@guillotinaweb/react-gmi 0.29.1 → 0.29.2-alpha.3

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 (70) hide show
  1. package/README.md +2 -1
  2. package/dist/actions/copy_item.d.ts +2 -2
  3. package/dist/actions/move_item.d.ts +2 -2
  4. package/dist/actions/remove_item.d.ts +2 -2
  5. package/dist/components/behaviors/iattachment.d.ts +4 -2
  6. package/dist/components/behaviors/imultiimageorderedattachment.d.ts +3 -1
  7. package/dist/components/behaviors/iworkflow.d.ts +1 -1
  8. package/dist/components/context_toolbar.d.ts +1 -1
  9. package/dist/components/fields/editComponent.d.ts +5 -4
  10. package/dist/components/fields/editableField.d.ts +4 -2
  11. package/dist/components/fields/renderField.d.ts +8 -5
  12. package/dist/components/flash.d.ts +1 -1
  13. package/dist/components/input/email.d.ts +2 -2
  14. package/dist/components/input/form_builder.d.ts +2 -2
  15. package/dist/components/input/input.d.ts +1 -1
  16. package/dist/components/input/search_input.d.ts +1 -1
  17. package/dist/components/input/search_input_list.d.ts +2 -2
  18. package/dist/components/input/select_vocabulary.d.ts +2 -2
  19. package/dist/components/input/upload.d.ts +1 -2
  20. package/dist/components/pagination.d.ts +1 -1
  21. package/dist/components/panel/permissions.d.ts +1 -1
  22. package/dist/components/panel/permissions_prinperm.d.ts +2 -2
  23. package/dist/components/panel/permissions_prinrole.d.ts +1 -1
  24. package/dist/components/panel/permissions_roleperm.d.ts +1 -1
  25. package/dist/components/path.d.ts +1 -1
  26. package/dist/components/properties_view.d.ts +2 -2
  27. package/dist/components/search_labels.d.ts +1 -1
  28. package/dist/components/search_options_labels.d.ts +1 -1
  29. package/dist/components/search_vocabulary_labels.d.ts +2 -2
  30. package/dist/components/selected_items_actions.d.ts +14 -0
  31. package/dist/components/tabs.d.ts +4 -2
  32. package/dist/components/widgets/tags.d.ts +4 -1
  33. package/dist/contexts/index.d.ts +21 -19
  34. package/dist/forms/required_fields.d.ts +2 -3
  35. package/dist/forms/users.d.ts +1 -1
  36. package/dist/hooks/useClickAway.d.ts +2 -1
  37. package/dist/hooks/useConfig.d.ts +4 -2
  38. package/dist/hooks/useCrudContext.d.ts +11 -10
  39. package/dist/hooks/useInput.d.ts +4 -3
  40. package/dist/hooks/useRegistry.d.ts +29 -29
  41. package/dist/hooks/useSetState.d.ts +6 -1
  42. package/dist/hooks/useVocabulary.d.ts +1 -1
  43. package/dist/lib/auth.d.ts +14 -19
  44. package/dist/lib/client.d.ts +49 -36
  45. package/dist/lib/helpers.d.ts +10 -18
  46. package/dist/lib/processResponse.d.ts +9 -0
  47. package/dist/lib/rest.d.ts +9 -16
  48. package/dist/lib/utils.d.ts +3 -2
  49. package/dist/lib/validators.d.ts +1 -1
  50. package/dist/locales/generic_messages.d.ts +248 -370
  51. package/dist/models/index.d.ts +5 -5
  52. package/dist/models/sharing.d.ts +5 -5
  53. package/dist/react-gmi.esm.js +1179 -900
  54. package/dist/react-gmi.esm.js.map +1 -1
  55. package/dist/react-gmi.js +1178 -900
  56. package/dist/react-gmi.js.map +1 -1
  57. package/dist/react-gmi.modern.js +1161 -856
  58. package/dist/react-gmi.modern.js.map +1 -1
  59. package/dist/react-gmi.umd.js +1178 -900
  60. package/dist/react-gmi.umd.js.map +1 -1
  61. package/dist/reducers/guillotina.d.ts +22 -8
  62. package/dist/types/global.d.ts +9 -0
  63. package/dist/types/guillotina.d.ts +153 -19
  64. package/dist/views/folder.d.ts +1 -1
  65. package/dist/views/groups.d.ts +1 -1
  66. package/dist/views/item.d.ts +1 -1
  67. package/dist/views/users.d.ts +1 -1
  68. package/package.json +3 -2
  69. package/dist/lib/search.test.d.ts +0 -1
  70. package/dist/setupTests.d.ts +0 -1
package/dist/react-gmi.js CHANGED
@@ -111,6 +111,97 @@ function _createForOfIteratorHelperLoose(o, allowArrayLike) {
111
111
  return it.next.bind(it);
112
112
  }
113
113
 
114
+ var initialState = {
115
+ path: '',
116
+ loading: false,
117
+ context: undefined,
118
+ flash: {
119
+ message: undefined,
120
+ type: undefined
121
+ },
122
+ action: {
123
+ action: undefined,
124
+ params: undefined
125
+ },
126
+ permissions: [],
127
+ errorStatus: undefined,
128
+ registry: {},
129
+ refresh: undefined
130
+ };
131
+ var GuillotinaReducerActionTypes;
132
+
133
+ (function (GuillotinaReducerActionTypes) {
134
+ GuillotinaReducerActionTypes["SET_PATH"] = "SET_PATH";
135
+ GuillotinaReducerActionTypes["SET_CONTEXT"] = "SET_CONTEXT";
136
+ GuillotinaReducerActionTypes["SET_ERROR"] = "SET_ERROR";
137
+ GuillotinaReducerActionTypes["SET_FLASH"] = "SET_FLASH";
138
+ GuillotinaReducerActionTypes["CLEAR_FLASH"] = "CLEAR_FLASH";
139
+ GuillotinaReducerActionTypes["SET_ACTION"] = "SET_ACTION";
140
+ GuillotinaReducerActionTypes["CLEAR_ACTION"] = "CLEAR_ACTION";
141
+ GuillotinaReducerActionTypes["REFRESH"] = "REFRESH";
142
+ GuillotinaReducerActionTypes["APPLY"] = "APPLY";
143
+ })(GuillotinaReducerActionTypes || (GuillotinaReducerActionTypes = {}));
144
+
145
+ function guillotinaReducer(state, action) {
146
+ switch (action.type) {
147
+ case GuillotinaReducerActionTypes.SET_PATH:
148
+ return _extends({}, state, {
149
+ path: action.payload.path,
150
+ loading: true
151
+ });
152
+
153
+ case GuillotinaReducerActionTypes.SET_CONTEXT:
154
+ return _extends({}, state, action.payload, {
155
+ errorStatus: undefined,
156
+ loading: false
157
+ });
158
+
159
+ case GuillotinaReducerActionTypes.SET_ERROR:
160
+ return _extends({}, state, {
161
+ errorStatus: action.payload.errorStatus,
162
+ loading: false
163
+ });
164
+
165
+ case GuillotinaReducerActionTypes.SET_FLASH:
166
+ return _extends({}, state, action.payload);
167
+
168
+ case GuillotinaReducerActionTypes.CLEAR_FLASH:
169
+ return _extends({}, state, {
170
+ flash: {
171
+ message: undefined,
172
+ type: undefined
173
+ }
174
+ });
175
+
176
+ case GuillotinaReducerActionTypes.SET_ACTION:
177
+ return _extends({}, state, {
178
+ action: action.payload
179
+ });
180
+
181
+ case GuillotinaReducerActionTypes.CLEAR_ACTION:
182
+ return _extends({}, state, {
183
+ action: {
184
+ action: undefined,
185
+ params: undefined
186
+ }
187
+ });
188
+
189
+ case GuillotinaReducerActionTypes.REFRESH:
190
+ return _extends({}, state, {
191
+ refresh: Date.now(),
192
+ loading: !action.payload.transparent
193
+ });
194
+
195
+ case GuillotinaReducerActionTypes.APPLY:
196
+ return _extends({}, state, {
197
+ context: _extends({}, state.context, action.payload.context)
198
+ });
199
+
200
+ default:
201
+ return state;
202
+ }
203
+ }
204
+
114
205
  var AuthContext = React.createContext({});
115
206
  var ClientContext = React.createContext(null);
116
207
  var Traversal = /*#__PURE__*/function () {
@@ -141,7 +232,7 @@ var Traversal = /*#__PURE__*/function () {
141
232
  transparent = _ref2$transparent === void 0 ? false : _ref2$transparent;
142
233
 
143
234
  this.dispatch({
144
- type: 'REFRESH',
235
+ type: GuillotinaReducerActionTypes.REFRESH,
145
236
  payload: {
146
237
  transparent: transparent
147
238
  }
@@ -149,15 +240,18 @@ var Traversal = /*#__PURE__*/function () {
149
240
  };
150
241
 
151
242
  _proto.apply = function apply(data) {
243
+ // apply a optimistic update to context
152
244
  this.dispatch({
153
- type: 'APPLY',
154
- payload: data
245
+ type: GuillotinaReducerActionTypes.APPLY,
246
+ payload: {
247
+ context: data
248
+ }
155
249
  });
156
250
  };
157
251
 
158
252
  _proto.flash = function flash(message, type) {
159
253
  this.dispatch({
160
- type: 'SET_FLASH',
254
+ type: GuillotinaReducerActionTypes.SET_FLASH,
161
255
  payload: {
162
256
  flash: {
163
257
  message: message,
@@ -174,7 +268,8 @@ var Traversal = /*#__PURE__*/function () {
174
268
 
175
269
  _proto.clearFlash = function clearFlash() {
176
270
  this.dispatch({
177
- type: 'CLEAR_FLASH'
271
+ type: GuillotinaReducerActionTypes.CLEAR_FLASH,
272
+ payload: {}
178
273
  });
179
274
  };
180
275
 
@@ -184,7 +279,7 @@ var Traversal = /*#__PURE__*/function () {
184
279
  }
185
280
 
186
281
  this.dispatch({
187
- type: 'SET_ACTION',
282
+ type: GuillotinaReducerActionTypes.SET_ACTION,
188
283
  payload: {
189
284
  action: action,
190
285
  params: params
@@ -194,7 +289,8 @@ var Traversal = /*#__PURE__*/function () {
194
289
 
195
290
  _proto.cancelAction = function cancelAction() {
196
291
  this.dispatch({
197
- type: 'CLEAR_ACTION'
292
+ type: GuillotinaReducerActionTypes.CLEAR_ACTION,
293
+ payload: {}
198
294
  });
199
295
  };
200
296
 
@@ -231,6 +327,10 @@ var Traversal = /*#__PURE__*/function () {
231
327
  }, {
232
328
  key: "context",
233
329
  get: function get() {
330
+ if (this.state.context === undefined) {
331
+ throw new Error('Context is not loaded');
332
+ }
333
+
234
334
  return this.state.context;
235
335
  }
236
336
  }, {
@@ -253,7 +353,13 @@ function TraversalProvider(_ref3) {
253
353
  });
254
354
  }
255
355
  function useTraversal() {
256
- return React.useContext(TraversalContext);
356
+ var traversal = React.useContext(TraversalContext);
357
+
358
+ if (!traversal) {
359
+ throw new Error('useTraversal must be used within a TraversalProvider');
360
+ }
361
+
362
+ return traversal;
257
363
  }
258
364
  function ClientProvider(_ref4) {
259
365
  var children = _ref4.children,
@@ -264,7 +370,13 @@ function ClientProvider(_ref4) {
264
370
  });
265
371
  }
266
372
  function useGuillotinaClient() {
267
- return React.useContext(ClientContext);
373
+ var client = React.useContext(ClientContext);
374
+
375
+ if (!client) {
376
+ throw new Error('useGuillotinaClient must be used within a ClientProvider');
377
+ }
378
+
379
+ return client;
268
380
  }
269
381
 
270
382
  var genericMessages = reactIntl.defineMessages({
@@ -771,8 +883,10 @@ function base64ToArrayBuffer(base64) {
771
883
  return bytes;
772
884
  }
773
885
  function stringToSlug(str) {
774
- str = str.replace(/^\s+|\s+$/g, '');
775
- str = str.toLowerCase();
886
+ str = str.replace(/^\s+|\s+$/g, ''); // trim
887
+
888
+ str = str.toLowerCase(); // remove accents, swap ñ for n, etc
889
+
776
890
  var from = 'àáäâèéëêìíïîòóöôùúüûñç·/_,:;';
777
891
  var to = 'aaaaeeeeiiiioooouuuunc------';
778
892
 
@@ -780,13 +894,16 @@ function stringToSlug(str) {
780
894
  str = str.replace(new RegExp(from.charAt(i), 'g'), to.charAt(i));
781
895
  }
782
896
 
783
- str = str.replace(/[^a-z0-9 -]/g, '').replace(/\s+/g, '-').replace(/-+/g, '-');
897
+ str = str.replace(/[^a-z0-9 -]/g, '') // remove invalid chars
898
+ .replace(/\s+/g, '-') // collapse whitespace and replace by -
899
+ .replace(/-+/g, '-'); // collapse dashes
900
+
784
901
  return str;
785
902
  }
786
903
  function sleep(ms) {
787
904
  return new Promise(function (resolve) {
788
905
  setTimeout(function () {
789
- resolve(null);
906
+ resolve();
790
907
  }, ms);
791
908
  });
792
909
  }
@@ -815,8 +932,6 @@ var getActionsObject = function getActionsObject(intl, multiple) {
815
932
  };
816
933
 
817
934
  var Button = function Button(_ref) {
818
- var _ref2;
819
-
820
935
  var children = _ref.children,
821
936
  _ref$className = _ref.className,
822
937
  className = _ref$className === void 0 ? 'is-primary' : _ref$className,
@@ -828,9 +943,7 @@ var Button = function Button(_ref) {
828
943
  _ref$disabled = _ref.disabled,
829
944
  disabled = _ref$disabled === void 0 ? false : _ref$disabled,
830
945
  dataTest = _ref.dataTest;
831
-
832
- var css = (_ref2 = []).concat.apply(_ref2, ['button'].concat(className.split(' ')));
833
-
946
+ var css = [].concat(className.split(' '), ['button']);
834
947
  if (loading) css = css.concat('is-loading');
835
948
  return jsxRuntime.jsx("p", {
836
949
  className: "control",
@@ -845,6 +958,50 @@ var Button = function Button(_ref) {
845
958
  });
846
959
  };
847
960
 
961
+ var formatDate = function formatDate(str) {
962
+ var d = new Date(str);
963
+ var minutes = d.getMinutes() < 10 ? "0" + d.getMinutes() : d.getMinutes();
964
+ return d.getDate() + "/" + (d.getMonth() + 1) + "/" + d.getFullYear() + " " + d.getHours() + ":" + minutes;
965
+ };
966
+ var get = function get(obj, path, defValue) {
967
+ var _pathArray$reduce;
968
+
969
+ // If path is not defined or it has false value
970
+ if (!path) return defValue; // Check if path is string or array. Regex : ensure that we do not have '.' and brackets.
971
+ // Regex explained: https://regexr.com/58j0k
972
+
973
+ var pathArray = Array.isArray(path) ? path : path.match(/([^[.\]])+/g); // Find value if exist return otherwise return undefined value;
974
+
975
+ if (pathArray === null) return defValue;
976
+ return (_pathArray$reduce = pathArray.reduce(function (prevObj, key) {
977
+ return prevObj && prevObj[key];
978
+ }, obj)) != null ? _pathArray$reduce : defValue;
979
+ };
980
+ function getNewId(id) {
981
+ if (id === void 0) {
982
+ id = '';
983
+ }
984
+
985
+ var suffix = '-copy-';
986
+ var rgx = new RegExp("($|" + suffix + "\\d*)");
987
+ return stringToSlug(id).replace(rgx, function (r) {
988
+ var num = parseInt(r.replace(suffix, '') || '0');
989
+ return "" + suffix + (num + 1);
990
+ });
991
+ }
992
+ function debounce(callback, wait) {
993
+ var timer;
994
+ return function () {
995
+ var _arguments = arguments;
996
+ clearTimeout(timer);
997
+ return new Promise(function (resolve) {
998
+ timer = setTimeout(function () {
999
+ return resolve(callback.apply(void 0, [].slice.call(_arguments)));
1000
+ }, wait);
1001
+ });
1002
+ };
1003
+ }
1004
+
848
1005
  function Modal(props) {
849
1006
  var isActive = props.isActive,
850
1007
  setActive = props.setActive,
@@ -924,7 +1081,8 @@ function Confirm(_ref) {
924
1081
  })]
925
1082
  })]
926
1083
  });
927
- }
1084
+ } // @todo Improve it... Replacing the inputText to a tree
1085
+
928
1086
  function PathTree(_ref2) {
929
1087
  var title = _ref2.title,
930
1088
  defaultPath = _ref2.defaultPath,
@@ -940,7 +1098,7 @@ function PathTree(_ref2) {
940
1098
  }), jsxRuntime.jsxs("form", {
941
1099
  onSubmit: function onSubmit(e) {
942
1100
  e.preventDefault();
943
- onConfirm(e.target[0].value, e.target);
1101
+ onConfirm(get(e, 'target.0.value', ''), e.target);
944
1102
  },
945
1103
  children: [jsxRuntime.jsx("small", {
946
1104
  style: {
@@ -972,51 +1130,6 @@ function PathTree(_ref2) {
972
1130
  });
973
1131
  }
974
1132
 
975
- function useSetState(initialState) {
976
- var _useState = React.useState(initialState),
977
- state = _useState[0],
978
- set = _useState[1];
979
-
980
- var setState = React.useCallback(function (patch) {
981
- set(function (prevState) {
982
- return Object.assign({}, prevState, patch instanceof Function ? patch(prevState) : patch);
983
- });
984
- }, [set]);
985
- return [state, setState];
986
- }
987
-
988
- function _catch(body, recover) {
989
- try {
990
- var result = body();
991
- } catch (e) {
992
- return recover(e);
993
- }
994
-
995
- if (result && result.then) {
996
- return result.then(void 0, recover);
997
- }
998
-
999
- return result;
1000
- }
1001
-
1002
- var initial = {
1003
- loading: undefined,
1004
- isError: false,
1005
- errorMessage: undefined,
1006
- result: undefined,
1007
- response: undefined
1008
- };
1009
-
1010
- var getErrorMessage = function getErrorMessage(dataError, defaultValue) {
1011
- if (dataError && dataError.details) {
1012
- return dataError.details;
1013
- } else if (dataError && dataError.reason) {
1014
- return dataError.reason;
1015
- }
1016
-
1017
- return defaultValue;
1018
- };
1019
-
1020
1133
  var processResponse = function processResponse(res, ready_body) {
1021
1134
  if (ready_body === void 0) {
1022
1135
  ready_body = true;
@@ -1036,7 +1149,7 @@ var processResponse = function processResponse(res, ready_body) {
1036
1149
  return {
1037
1150
  isError: true,
1038
1151
  loading: false,
1039
- errorMessage: getErrorMessage(_res$json2, res.status),
1152
+ errorMessage: getErrorMessage(_res$json2, res.status).toString(),
1040
1153
  response: res
1041
1154
  };
1042
1155
  });
@@ -1045,10 +1158,66 @@ var processResponse = function processResponse(res, ready_body) {
1045
1158
  }
1046
1159
  };
1047
1160
 
1048
- var patch = function patch(setState, Ctx) {
1161
+ var getErrorMessage = function getErrorMessage(dataError, defaultValue) {
1162
+ if (dataError && dataError.details) {
1163
+ return dataError.details;
1164
+ } else if (dataError && dataError.reason) {
1165
+ return dataError.reason;
1166
+ }
1167
+
1168
+ return defaultValue;
1169
+ };
1170
+
1171
+ /**
1172
+ * Do setState like react class component.
1173
+ */
1174
+
1175
+ function useSetState(initialState) {
1176
+ var _useState = React.useState(initialState),
1177
+ state = _useState[0],
1178
+ setState = _useState[1]; // Function which accepts a partial state to merge
1179
+
1180
+
1181
+ var setCustomState = React.useCallback(function (newPartialState) {
1182
+ try {
1183
+ setState(function (prevState) {
1184
+ return _extends({}, prevState, newPartialState);
1185
+ });
1186
+ } catch (error) {
1187
+ // eslint-disable-next-line no-console
1188
+ console.error(error);
1189
+ }
1190
+ }, []); // Return
1191
+
1192
+ return [state, setCustomState];
1193
+ } // **** Export Default **** //
1194
+
1195
+ function _catch(body, recover) {
1196
+ try {
1197
+ var result = body();
1198
+ } catch (e) {
1199
+ return recover(e);
1200
+ }
1201
+
1202
+ if (result && result.then) {
1203
+ return result.then(void 0, recover);
1204
+ }
1205
+
1206
+ return result;
1207
+ }
1208
+
1209
+ var initial = {
1210
+ loading: undefined,
1211
+ isError: false,
1212
+ errorMessage: undefined,
1213
+ result: undefined,
1214
+ response: undefined
1215
+ };
1216
+
1217
+ function patch(setState, Ctx) {
1049
1218
  return function (data, endpoint, body) {
1050
- if (endpoint === void 0) {
1051
- endpoint = undefined;
1219
+ if (data === void 0) {
1220
+ data = {};
1052
1221
  }
1053
1222
 
1054
1223
  if (body === void 0) {
@@ -1056,7 +1225,7 @@ var patch = function patch(setState, Ctx) {
1056
1225
  }
1057
1226
 
1058
1227
  try {
1059
- function _temp5() {
1228
+ function _temp3() {
1060
1229
  setState(newState);
1061
1230
  return newState;
1062
1231
  }
@@ -1066,7 +1235,7 @@ var patch = function patch(setState, Ctx) {
1066
1235
  });
1067
1236
  var newState = {};
1068
1237
 
1069
- var _temp6 = _catch(function () {
1238
+ var _temp4 = _catch(function () {
1070
1239
  var path = endpoint ? "" + Ctx.path + endpoint : Ctx.path;
1071
1240
  return Promise.resolve(Ctx.client.patch(path, data)).then(function (res) {
1072
1241
  return Promise.resolve(processResponse(res, body)).then(function (_processResponse) {
@@ -1081,29 +1250,25 @@ var patch = function patch(setState, Ctx) {
1081
1250
  };
1082
1251
  });
1083
1252
 
1084
- return Promise.resolve(_temp6 && _temp6.then ? _temp6.then(_temp5) : _temp5(_temp6));
1253
+ return Promise.resolve(_temp4 && _temp4.then ? _temp4.then(_temp3) : _temp3(_temp4));
1085
1254
  } catch (e) {
1086
1255
  return Promise.reject(e);
1087
1256
  }
1088
1257
  };
1089
- };
1258
+ }
1090
1259
 
1091
- var del = function del(setState, Ctx) {
1260
+ function del(setState, Ctx) {
1092
1261
  return function (data, endpoint, body) {
1093
1262
  if (data === void 0) {
1094
1263
  data = {};
1095
1264
  }
1096
1265
 
1097
- if (endpoint === void 0) {
1098
- endpoint = undefined;
1099
- }
1100
-
1101
1266
  if (body === void 0) {
1102
1267
  body = false;
1103
1268
  }
1104
1269
 
1105
1270
  try {
1106
- function _temp9() {
1271
+ function _temp7() {
1107
1272
  setState(newState);
1108
1273
  return newState;
1109
1274
  }
@@ -1113,7 +1278,7 @@ var del = function del(setState, Ctx) {
1113
1278
  });
1114
1279
  var newState = {};
1115
1280
 
1116
- var _temp10 = _catch(function () {
1281
+ var _temp8 = _catch(function () {
1117
1282
  var path = endpoint ? "" + Ctx.path + endpoint : Ctx.path;
1118
1283
  return Promise.resolve(Ctx.client.delete(path, data)).then(function (res) {
1119
1284
  return Promise.resolve(processResponse(res, body)).then(function (_processResponse2) {
@@ -1128,17 +1293,17 @@ var del = function del(setState, Ctx) {
1128
1293
  };
1129
1294
  });
1130
1295
 
1131
- return Promise.resolve(_temp10 && _temp10.then ? _temp10.then(_temp9) : _temp9(_temp10));
1296
+ return Promise.resolve(_temp8 && _temp8.then ? _temp8.then(_temp7) : _temp7(_temp8));
1132
1297
  } catch (e) {
1133
1298
  return Promise.reject(e);
1134
1299
  }
1135
1300
  };
1136
- };
1301
+ }
1137
1302
 
1138
- var post = function post(setState, Ctx) {
1303
+ function post(setState, Ctx) {
1139
1304
  return function (data, endpoint, body) {
1140
- if (endpoint === void 0) {
1141
- endpoint = undefined;
1305
+ if (data === void 0) {
1306
+ data = {};
1142
1307
  }
1143
1308
 
1144
1309
  if (body === void 0) {
@@ -1146,7 +1311,7 @@ var post = function post(setState, Ctx) {
1146
1311
  }
1147
1312
 
1148
1313
  try {
1149
- function _temp13() {
1314
+ function _temp11() {
1150
1315
  setState(newState);
1151
1316
  return newState;
1152
1317
  }
@@ -1156,7 +1321,7 @@ var post = function post(setState, Ctx) {
1156
1321
  });
1157
1322
  var newState = {};
1158
1323
 
1159
- var _temp14 = _catch(function () {
1324
+ var _temp12 = _catch(function () {
1160
1325
  var path = endpoint ? "" + Ctx.path + endpoint : Ctx.path;
1161
1326
  return Promise.resolve(Ctx.client.post(path, data)).then(function (res) {
1162
1327
  return Promise.resolve(processResponse(res, body)).then(function (_processResponse3) {
@@ -1171,21 +1336,17 @@ var post = function post(setState, Ctx) {
1171
1336
  };
1172
1337
  });
1173
1338
 
1174
- return Promise.resolve(_temp14 && _temp14.then ? _temp14.then(_temp13) : _temp13(_temp14));
1339
+ return Promise.resolve(_temp12 && _temp12.then ? _temp12.then(_temp11) : _temp11(_temp12));
1175
1340
  } catch (e) {
1176
1341
  return Promise.reject(e);
1177
1342
  }
1178
1343
  };
1179
- };
1344
+ }
1180
1345
 
1181
- var get = function get(setState, Ctx) {
1346
+ function get$1(setState, Ctx) {
1182
1347
  return function (endpoint) {
1183
- if (endpoint === void 0) {
1184
- endpoint = undefined;
1185
- }
1186
-
1187
1348
  try {
1188
- function _temp17() {
1349
+ function _temp15() {
1189
1350
  setState(newState);
1190
1351
  return newState;
1191
1352
  }
@@ -1195,7 +1356,7 @@ var get = function get(setState, Ctx) {
1195
1356
  });
1196
1357
  var newState = {};
1197
1358
 
1198
- var _temp18 = _catch(function () {
1359
+ var _temp16 = _catch(function () {
1199
1360
  var path = endpoint ? "" + Ctx.path + endpoint : Ctx.path;
1200
1361
  return Promise.resolve(Ctx.client.get(path)).then(function (res) {
1201
1362
  return Promise.resolve(processResponse(res, true)).then(function (_processResponse4) {
@@ -1210,12 +1371,16 @@ var get = function get(setState, Ctx) {
1210
1371
  };
1211
1372
  });
1212
1373
 
1213
- return Promise.resolve(_temp18 && _temp18.then ? _temp18.then(_temp17) : _temp17(_temp18));
1374
+ return Promise.resolve(_temp16 && _temp16.then ? _temp16.then(_temp15) : _temp15(_temp16));
1214
1375
  } catch (e) {
1215
1376
  return Promise.reject(e);
1216
1377
  }
1217
1378
  };
1218
- };
1379
+ } // const get = (
1380
+ // setState: (value: Partial<State>) => void,
1381
+ // Ctx: Traversal
1382
+ // ) =>
1383
+
1219
1384
 
1220
1385
  function useCrudContext() {
1221
1386
  var Ctx = useTraversal();
@@ -1229,7 +1394,7 @@ function useCrudContext() {
1229
1394
  patch: patch(setState, Ctx),
1230
1395
  del: del(setState, Ctx),
1231
1396
  post: post(setState, Ctx),
1232
- get: get(setState, Ctx)
1397
+ get: get$1(setState, Ctx)
1233
1398
  });
1234
1399
  }
1235
1400
 
@@ -1277,9 +1442,6 @@ function AddItem(props) {
1277
1442
  children: jsxRuntime.jsx(Form, {
1278
1443
  loading: loading,
1279
1444
  onSubmit: doSubmit,
1280
- onError: function onError(err) {
1281
- return console.log(err);
1282
- },
1283
1445
  actionName: 'Add ' + type,
1284
1446
  title: 'Add ' + type,
1285
1447
  type: type,
@@ -1289,31 +1451,52 @@ function AddItem(props) {
1289
1451
  }
1290
1452
 
1291
1453
  var Permissions = ['guillotina.AddContent', 'guillotina.ModifyContent', 'guillotina.ViewContent', 'guillotina.DeleteContent', 'guillotina.AccessContent', 'guillotina.SeePermissions', 'guillotina.ChangePermissions', 'guillotina.MoveContent', 'guillotina.DuplicateContent', 'guillotina.ReadConfiguration', 'guillotina.RegisterConfigurations', 'guillotina.WriteConfiguration', 'guillotina.ManageAddons', 'guillotina.swagger.View'];
1292
- var Config = {
1454
+ var defaultConfig = {
1293
1455
  DisabledTypes: ['UserManager', 'GroupManager'],
1294
1456
  PageSize: 10,
1295
1457
  DelayActions: 200,
1296
1458
  Permissions: Permissions,
1297
1459
  SearchEngine: 'PostreSQL',
1460
+ // Elasticsearch
1298
1461
  fieldHaveDeleteButton: function fieldHaveDeleteButton(schema) {
1299
1462
  return (schema == null ? void 0 : schema.widget) === 'file' || (schema == null ? void 0 : schema.widget) === 'select' || (schema == null ? void 0 : schema.type) === 'array';
1300
1463
  }
1301
1464
  };
1302
- var calculated = Object.assign({}, Config);
1303
-
1304
- var addConfig = function addConfig(additional, original) {
1305
- var rest = Object.assign({}, original);
1306
- Object.keys(additional).forEach(function (item) {
1307
- if (typeof Config[item] === 'object' && Array.isArray(Config[item])) {
1308
- rest[item] = [].concat(Config[item], additional[item]);
1309
- } else if (typeof Config[item] === 'object') {
1310
- rest[item] = Object.assign({}, Config[item], additional[item]);
1465
+ var calculated = Object.assign({}, defaultConfig);
1466
+
1467
+ function addConfig(updates, currentConfig) {
1468
+ var updatedConfig = _extends({}, currentConfig);
1469
+
1470
+ Object.entries(updates).forEach(function (_ref) {
1471
+ var key = _ref[0],
1472
+ value = _ref[1];
1473
+ var currentKey = key;
1474
+ var currentValue = currentConfig[currentKey];
1475
+
1476
+ if (Array.isArray(value) && Array.isArray(currentValue)) {
1477
+ var _extends2;
1478
+
1479
+ // Correctly type the array concatenation
1480
+ updatedConfig = _extends({}, updatedConfig, (_extends2 = {}, _extends2[currentKey] = [].concat(currentValue, value), _extends2));
1481
+ } else if (isPlainObject(value) && isPlainObject(currentValue)) {
1482
+ var _extends3;
1483
+
1484
+ // Correctly type the object merging
1485
+ updatedConfig = _extends({}, updatedConfig, (_extends3 = {}, _extends3[currentKey] = _extends({}, currentValue, value), _extends3));
1311
1486
  } else {
1312
- rest[item] = additional[item];
1487
+ var _extends4;
1488
+
1489
+ // Directly assign all other types
1490
+ updatedConfig = _extends({}, updatedConfig, (_extends4 = {}, _extends4[currentKey] = value, _extends4));
1313
1491
  }
1314
1492
  });
1315
- return rest;
1316
- };
1493
+ return updatedConfig;
1494
+ } // Helper function to check if a value is a plain object (and not a React node, etc.)
1495
+
1496
+
1497
+ function isPlainObject(value) {
1498
+ return Object.prototype.toString.call(value) === '[object Object]';
1499
+ }
1317
1500
 
1318
1501
  function useConfig(cfg) {
1319
1502
  if (cfg === void 0) {
@@ -1337,7 +1520,7 @@ function RemoveItems(props) {
1337
1520
  setLoading(true);
1338
1521
  var actions = items.map(function (item) {
1339
1522
  try {
1340
- return Promise.resolve(Ctx.client.delete("" + Ctx.path + item['@name'])).then(function (res) {
1523
+ return Promise.resolve(Ctx.client.delete("" + Ctx.path + item.id, {})).then(function (res) {
1341
1524
  var _temp = function () {
1342
1525
  if (!res.ok) {
1343
1526
  return Promise.resolve(res.json()).then(function (err) {
@@ -1351,7 +1534,9 @@ function RemoveItems(props) {
1351
1534
  } catch (e) {
1352
1535
  return Promise.reject(e);
1353
1536
  }
1354
- });
1537
+ }); // this sleep is here, to let elasticsearch, wait for
1538
+ // index our operations... (will work 99% of use cases)
1539
+
1355
1540
  actions.push(sleep(cfg.DelayActions));
1356
1541
  return Promise.resolve(Promise.all(actions)).then(function () {
1357
1542
  if (errors.length === 0) {
@@ -1381,9 +1566,9 @@ function RemoveItems(props) {
1381
1566
 
1382
1567
  var _props$items = props.items,
1383
1568
  items = _props$items === void 0 ? [] : _props$items;
1384
- var last = items[items.length - 1]['@name'];
1569
+ var last = items[items.length - 1].id;
1385
1570
  var itemsNames = items.map(function (item) {
1386
- return item['@name'];
1571
+ return item.id;
1387
1572
  }).join(', ').replace(", " + last, " and " + last);
1388
1573
  return jsxRuntime.jsx(Confirm, {
1389
1574
  loading: loading,
@@ -1410,7 +1595,7 @@ var Checkbox = function Checkbox(_ref) {
1410
1595
  dataTest = _ref.dataTest;
1411
1596
  var inputRef = React.useRef(null);
1412
1597
 
1413
- var _useState = React.useState(checked),
1598
+ var _useState = React.useState(!!checked),
1414
1599
  state = _useState[0],
1415
1600
  setState = _useState[1];
1416
1601
 
@@ -1429,13 +1614,13 @@ var Checkbox = function Checkbox(_ref) {
1429
1614
  className: "field",
1430
1615
  children: jsxRuntime.jsxs("label", {
1431
1616
  htmlFor: id,
1432
- className: classnames(['checkbox', className]),
1617
+ className: classnames(['checkbox', className != null ? className : '']),
1433
1618
  children: [jsxRuntime.jsx("input", {
1434
1619
  ref: inputRef,
1435
1620
  disabled: disabled || loading,
1436
1621
  id: id,
1437
1622
  type: "checkbox",
1438
- className: classnames(['checkbox', classNameInput]),
1623
+ className: classnames(['checkbox', classNameInput != null ? classNameInput : '']),
1439
1624
  checked: state,
1440
1625
  onChange: updateState,
1441
1626
  "data-test": dataTest
@@ -1473,7 +1658,7 @@ var applyValidators = function applyValidators(value, validators) {
1473
1658
  return result;
1474
1659
  };
1475
1660
 
1476
- var useInput = function useInput(onChange, value, validator) {
1661
+ var useInput = function useInput(onChange, value, validators) {
1477
1662
  var _useState = React.useState({
1478
1663
  hasError: false,
1479
1664
  value: value
@@ -1482,7 +1667,7 @@ var useInput = function useInput(onChange, value, validator) {
1482
1667
  setState = _useState[1];
1483
1668
 
1484
1669
  var onUpdate = function onUpdate(ev) {
1485
- var value = ev && ev.target ? ev.target.value : ev ? ev : '';
1670
+ var value = ev && ev.target ? ev.target.value : '';
1486
1671
  setState({
1487
1672
  value: value,
1488
1673
  hasError: false
@@ -1491,7 +1676,7 @@ var useInput = function useInput(onChange, value, validator) {
1491
1676
  };
1492
1677
 
1493
1678
  var onBlur = function onBlur() {
1494
- var hasError = applyValidators(state.value, validator) === false;
1679
+ var hasError = applyValidators(state.value, validators) === false;
1495
1680
  if (hasError) setState({
1496
1681
  value: state.value,
1497
1682
  hasError: hasError
@@ -1521,6 +1706,9 @@ var useInput = function useInput(onChange, value, validator) {
1521
1706
  };
1522
1707
  };
1523
1708
 
1709
+ // From github.com/protonmail/proton-shared
1710
+
1711
+ /* eslint-disable no-useless-escape */
1524
1712
  var REGEX_EMAIL = /(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))/i;
1525
1713
  var REGEX_URL = /((([A-Za-z]{3,9}:(?:\/\/)?)(?:[\-;:&=\+\$,\w]+@)?[A-Za-z0-9\.\-]+|(?:www\.|[\-;:&=\+\$,\w]+@)[A-Za-z0-9\.\-]+)((?:\/[\+~%\/\.\w\-_]*)?\??(?:[\-\+=&;%@\.\w_]*)#?(?:[\.\!\/\\\w]*))?)/;
1526
1714
  var REGEX_HEX_COLOR = /^#([a-f0-9]{3,4}|[a-f0-9]{4}(?:[a-f0-9]{2}){1,2})\b$/i;
@@ -1621,10 +1809,10 @@ var Input = React.forwardRef(function (_ref, ref) {
1621
1809
  dataTest = _ref$dataTest === void 0 ? 'testInput' : _ref$dataTest,
1622
1810
  disabled = _ref.disabled,
1623
1811
  onKeyUp = _ref.onKeyUp;
1624
- var validatorFn = null;
1812
+ var validatorFn = [];
1625
1813
 
1626
1814
  if (required) {
1627
- validatorFn = Array.isArray(validator) ? validator.push(notEmpty) : [validator, notEmpty];
1815
+ validatorFn = Array.isArray(validator) ? [].concat(validator, [notEmpty]) : [validator, notEmpty];
1628
1816
  }
1629
1817
 
1630
1818
  var _useInput = useInput(onChange, value != null ? value : '', validatorFn),
@@ -1636,17 +1824,18 @@ var Input = React.forwardRef(function (_ref, ref) {
1636
1824
 
1637
1825
  var _useState2 = React.useState(false),
1638
1826
  mounted = _useState2[0],
1639
- setMounted = _useState2[1];
1827
+ setMounted = _useState2[1]; // eslint-disable-next-line
1828
+
1640
1829
 
1641
- ref = ref || React.useRef();
1830
+ var newRef = ref || React.useRef();
1642
1831
  React.useEffect(function () {
1643
1832
  setMounted(true);
1644
1833
  }, []);
1645
1834
  React.useEffect(function () {
1646
- if (autofocus && !error && ref != null && typeof ref !== 'function') {
1647
- ref.current.focus();
1835
+ if (autofocus && !error && newRef != null && typeof newRef !== 'function' && newRef.current) {
1836
+ newRef.current.focus();
1648
1837
  }
1649
- }, [mounted, autofocus, ref, error]);
1838
+ }, [mounted, autofocus, newRef, error]);
1650
1839
  var theError = state.hasError ? errorMessage || 'invalid field' : '';
1651
1840
  var statusClasses = state.hasError ? 'is-danger' : '';
1652
1841
 
@@ -1687,7 +1876,8 @@ Input.displayName = 'Input';
1687
1876
 
1688
1877
  var Icon = function Icon(_ref) {
1689
1878
  var icon = _ref.icon,
1690
- className = _ref.className,
1879
+ _ref$className = _ref.className,
1880
+ className = _ref$className === void 0 ? '' : _ref$className,
1691
1881
  align = _ref.align;
1692
1882
  var addClass = className ? className.split(' ') : [className];
1693
1883
  align = align || 'is-right';
@@ -1704,7 +1894,8 @@ var EmailInput = function EmailInput(_ref) {
1704
1894
  value = _ref$value === void 0 ? '' : _ref$value,
1705
1895
  dataTest = _ref.dataTest,
1706
1896
  placeholder = _ref.placeholder,
1707
- id = _ref.id;
1897
+ id = _ref.id,
1898
+ onChange = _ref.onChange;
1708
1899
  var intl = reactIntl.useIntl();
1709
1900
  return jsxRuntime.jsx(Input, {
1710
1901
  type: "email",
@@ -1722,7 +1913,8 @@ var EmailInput = function EmailInput(_ref) {
1722
1913
  icon: "fas fa-envelope"
1723
1914
  }),
1724
1915
  id: id,
1725
- placeholder: placeholder
1916
+ placeholder: placeholder,
1917
+ onChange: onChange
1726
1918
  });
1727
1919
  };
1728
1920
 
@@ -1796,24 +1988,26 @@ function FormBuilder(_ref) {
1796
1988
  remotes = _ref$remotes === void 0 ? {} : _ref$remotes,
1797
1989
  _ref$submitButton = _ref.submitButton,
1798
1990
  submitButton = _ref$submitButton === void 0 ? true : _ref$submitButton;
1799
- var ref = React.useRef();
1991
+ var ref = React.useRef(null);
1800
1992
  var properties = schema.properties,
1801
1993
  required = schema.required;
1802
- var values = Object.assign({}, formData || {});
1994
+ var values = Object.assign({}, formData || {}); // build initial state
1995
+
1803
1996
  var initialState = {};
1804
1997
  var fields = Object.keys(properties).filter(function (x) {
1805
1998
  return !exclude.includes(x);
1806
1999
  });
1807
2000
  fields.forEach(function (element) {
1808
2001
  initialState[element] = values[element] || undefined;
1809
- });
2002
+ }); // Register remotes
1810
2003
 
1811
- if (!ref.current) {
2004
+ if (ref.current === null) {
1812
2005
  ref.current = {};
1813
2006
  Object.keys(remotes).forEach(function (item) {
1814
2007
  return ref.current[item] = remotes[item];
1815
2008
  });
1816
2009
  } else {
2010
+ // apply remote changes
1817
2011
  Object.keys(remotes).forEach(function (key) {
1818
2012
  if (JSON.stringify(ref.current[key]) !== JSON.stringify(remotes[key])) {
1819
2013
  ref.current[key] = remotes[key];
@@ -1824,15 +2018,16 @@ function FormBuilder(_ref) {
1824
2018
  ref.current = ref.current || {};
1825
2019
 
1826
2020
  var onUpdate = function onUpdate(field) {
1827
- return function (ev) {
1828
- ref.current[field] = ev.target ? ev.target.value : ev.value || ev;
2021
+ return function (value) {
2022
+ ref.current[field] = value;
1829
2023
  };
1830
2024
  };
1831
2025
 
1832
2026
  var GetTag = function GetTag(_ref2) {
1833
2027
  var field = _ref2.field;
1834
2028
  var property = properties[field];
1835
- var Tag = formComponents[property.widget || property.type];
2029
+ var key = property.widget || property.type;
2030
+ var Tag = formComponents[key];
1836
2031
  var props = {
1837
2032
  value: initialState[field],
1838
2033
  onChange: onUpdate(field),
@@ -1847,7 +2042,6 @@ function FormBuilder(_ref) {
1847
2042
  props.placeholder += ' *';
1848
2043
  }
1849
2044
 
1850
- Tag.displayName = field + "Field";
1851
2045
  return jsxRuntime.jsx(Tag, _extends({}, props));
1852
2046
  };
1853
2047
 
@@ -1916,9 +2110,13 @@ var Select = React.forwardRef(function (_ref, ref) {
1916
2110
  selectValue = selectValue.concat([ev.target.selectedOptions[i].value]);
1917
2111
  }
1918
2112
 
1919
- onChange(selectValue);
2113
+ if (onChange) {
2114
+ onChange(selectValue);
2115
+ }
1920
2116
  } else {
1921
- onChange(ev.target.value);
2117
+ if (onChange) {
2118
+ onChange(ev.target.value);
2119
+ }
1922
2120
  }
1923
2121
  };
1924
2122
 
@@ -1967,33 +2165,6 @@ var Select = React.forwardRef(function (_ref, ref) {
1967
2165
  });
1968
2166
  Select.displayName = 'Select';
1969
2167
 
1970
- var formatDate = function formatDate(str) {
1971
- var d = new Date(str);
1972
- var minutes = d.getMinutes() < 10 ? "0" + d.getMinutes() : d.getMinutes();
1973
- return d.getDate() + "/" + (d.getMonth() + 1) + "/" + d.getFullYear() + " " + d.getHours() + ":" + minutes;
1974
- };
1975
- var get$1 = function get(obj, path, defValue) {
1976
- var _pathArray$reduce;
1977
-
1978
- if (!path) return undefined;
1979
- var pathArray = Array.isArray(path) ? path : path.match(/([^[.\]])+/g);
1980
- return (_pathArray$reduce = pathArray.reduce(function (prevObj, key) {
1981
- return prevObj && prevObj[key];
1982
- }, obj)) != null ? _pathArray$reduce : defValue;
1983
- };
1984
- function getNewId(id) {
1985
- if (id === void 0) {
1986
- id = '';
1987
- }
1988
-
1989
- var suffix = '-copy-';
1990
- var rgx = new RegExp("($|" + suffix + "\\d*)");
1991
- return stringToSlug(id).replace(rgx, function (r) {
1992
- var num = parseInt(r.replace(suffix, '') || '0');
1993
- return "" + suffix + (num + 1);
1994
- });
1995
- }
1996
-
1997
2168
  function _catch$1(body, recover) {
1998
2169
  try {
1999
2170
  var result = body();
@@ -2009,10 +2180,6 @@ function _catch$1(body, recover) {
2009
2180
  }
2010
2181
 
2011
2182
  function useVocabulary(vocabularyName, path) {
2012
- if (path === void 0) {
2013
- path = null;
2014
- }
2015
-
2016
2183
  var traversal = useTraversal();
2017
2184
 
2018
2185
  var _useSetState = useSetState({
@@ -2081,8 +2248,10 @@ var SelectVocabulary = React.forwardRef(function (_ref, ref) {
2081
2248
  var vocabulary = useVocabulary(vocabularyName);
2082
2249
 
2083
2250
  var getOptions = function getOptions() {
2084
- if (get$1(vocabulary, 'data.items', null)) {
2085
- var vocData = vocabulary.data.items.map(function (item) {
2251
+ if (get(vocabulary, 'data.items', null)) {
2252
+ var _vocabulary$data$item, _vocabulary$data;
2253
+
2254
+ var vocData = ((_vocabulary$data$item = vocabulary == null ? void 0 : (_vocabulary$data = vocabulary.data) == null ? void 0 : _vocabulary$data.items) != null ? _vocabulary$data$item : []).map(function (item) {
2086
2255
  return {
2087
2256
  text: item.title,
2088
2257
  value: item.token
@@ -2128,6 +2297,8 @@ var SelectVocabulary = React.forwardRef(function (_ref, ref) {
2128
2297
  });
2129
2298
  SelectVocabulary.displayName = 'SelectVocabulary';
2130
2299
 
2300
+ // https://github.com/molefrog/wouter
2301
+
2131
2302
  var setURLParams = function setURLParams(p) {
2132
2303
  return window.history.pushState(0, '0', '' + '?' + p.toString().replace(/%2F/g, '/'));
2133
2304
  };
@@ -2147,7 +2318,10 @@ var useLocation = function useLocation() {
2147
2318
 
2148
2319
  var prevPath = React.useRef(path);
2149
2320
  React.useEffect(function () {
2150
- patchHistoryEvents();
2321
+ patchHistoryEvents(); // this function checks if the location has been changed since the
2322
+ // last render and updates the state only when needed.
2323
+ // unfortunately, we can't rely on `path` value here, since it can be stale,
2324
+ // that's why we store the last pathname in a ref.
2151
2325
 
2152
2326
  var checkForUpdates = function checkForUpdates() {
2153
2327
  var pathname = currentSearchParams();
@@ -2157,14 +2331,22 @@ var useLocation = function useLocation() {
2157
2331
  var events = ['popstate', 'pushState', 'replaceState'];
2158
2332
  events.map(function (e) {
2159
2333
  return window.addEventListener(e, checkForUpdates);
2160
- });
2334
+ }); // it's possible that an update has occurred between render and the effect handler,
2335
+ // so we run additional check on mount to catch these updates. Based on:
2336
+ // https://gist.github.com/bvaughn/e25397f70e8c65b0ae0d7c90b731b189
2337
+
2161
2338
  checkForUpdates();
2162
2339
  return function () {
2163
2340
  events.map(function (e) {
2164
2341
  return window.removeEventListener(e, checkForUpdates);
2165
2342
  });
2166
2343
  };
2167
- }, []);
2344
+ }, []); // the 2nd argument of the `useLocation` return value is a function
2345
+ // that allows to perform a navigation.
2346
+ //
2347
+ // the function reference should stay the same between re-renders, so that
2348
+ // it can be passed down as an element prop without any performance concerns.
2349
+
2168
2350
  var navigate = React.useCallback(function (to, replace) {
2169
2351
  if (replace) {
2170
2352
  clean(to);
@@ -2183,23 +2365,40 @@ var useLocation = function useLocation() {
2183
2365
  setURLParams(current);
2184
2366
  }, [path]);
2185
2367
  return [path, navigate, remove];
2186
- };
2368
+ }; // While History API does have `popstate` event, the only
2369
+ // proper way to listen to changes via `push/replaceState`
2370
+ // is to monkey-patch these methods.
2371
+ //
2372
+ // See https://stackoverflow.com/a/4585031
2373
+
2187
2374
  var patched = 0;
2188
2375
 
2189
2376
  var patchHistoryEvents = function patchHistoryEvents() {
2190
2377
  if (patched) return;
2191
- ['pushState', 'replaceState'].map(function (type) {
2192
- var original = window.history[type];
2193
-
2194
- window.history[type] = function () {
2195
- var args = [].slice.call(arguments);
2196
- var result = original.apply(this, args);
2197
- var event = new Event(type);
2198
- event.arguments = args;
2199
- dispatchEvent(event);
2200
- return result;
2201
- };
2202
- });
2378
+ var originalPushState = window.history.pushState;
2379
+
2380
+ window.history.pushState = function () {
2381
+ var args = [].slice.call(arguments);
2382
+ var result = originalPushState.apply(this, args); // eslint-disable-next-line @typescript-eslint/no-explicit-any
2383
+
2384
+ var event = new Event('pushState');
2385
+ event.arguments = args;
2386
+ dispatchEvent(event);
2387
+ return result;
2388
+ };
2389
+
2390
+ var originalReplaceState = window.history.replaceState;
2391
+
2392
+ window.history.replaceState = function () {
2393
+ var args = [].slice.call(arguments);
2394
+ var result = originalReplaceState.apply(this, args); // eslint-disable-next-line @typescript-eslint/no-explicit-any
2395
+
2396
+ var event = new Event('replaceState');
2397
+ event.arguments = args;
2398
+ dispatchEvent(event);
2399
+ return result;
2400
+ };
2401
+
2203
2402
  return patched = 1;
2204
2403
  };
2205
2404
 
@@ -2254,7 +2453,7 @@ function TdLink(_ref) {
2254
2453
  children = _ref.children,
2255
2454
  _ref$style = _ref.style,
2256
2455
  style = _ref$style === void 0 ? {} : _ref$style;
2257
- var link = React.useRef();
2456
+ var link = React.useRef(null);
2258
2457
 
2259
2458
  function onClick() {
2260
2459
  if (link && link.current) {
@@ -2361,15 +2560,7 @@ var RestClient = /*#__PURE__*/function () {
2361
2560
 
2362
2561
  var _proto = RestClient.prototype;
2363
2562
 
2364
- _proto.request = function request(path, data, headers) {
2365
- if (data === void 0) {
2366
- data = undefined;
2367
- }
2368
-
2369
- if (headers === void 0) {
2370
- headers = undefined;
2371
- }
2372
-
2563
+ _proto.request = function request(path, data, headers, signal) {
2373
2564
  try {
2374
2565
  var _this2 = this;
2375
2566
 
@@ -2385,9 +2576,18 @@ var RestClient = /*#__PURE__*/function () {
2385
2576
  path = "/" + path;
2386
2577
  }
2387
2578
 
2388
- data = data || {};
2389
- data.headers = headers || _this2.getHeaders();
2390
- return Promise.resolve(fetch("" + _this2.url + path, data));
2579
+ var dataRequest = data || {};
2580
+ dataRequest.headers = _this2.getHeaders();
2581
+
2582
+ if (headers) {
2583
+ dataRequest.headers = _extends({}, dataRequest.headers, headers);
2584
+ }
2585
+
2586
+ if (signal) {
2587
+ dataRequest.signal = signal;
2588
+ }
2589
+
2590
+ return Promise.resolve(fetch("" + _this2.url + path, dataRequest));
2391
2591
  } catch (e) {
2392
2592
  return Promise.reject(e);
2393
2593
  }
@@ -2395,12 +2595,12 @@ var RestClient = /*#__PURE__*/function () {
2395
2595
 
2396
2596
  _proto.getHeaders = function getHeaders() {
2397
2597
  var authToken = this.auth.getToken();
2398
- if (!authToken) return {};
2399
- return {
2400
- Accept: 'application/json',
2401
- 'Content-Type': 'application/json',
2402
- Authorization: 'Bearer ' + authToken
2403
- };
2598
+ var headersInit = {};
2599
+ if (!authToken) return headersInit;
2600
+ headersInit.Accept = 'application/json';
2601
+ headersInit['Content-Type'] = 'application/json';
2602
+ headersInit.Authorization = 'Bearer ' + authToken;
2603
+ return headersInit;
2404
2604
  };
2405
2605
 
2406
2606
  _proto.post = function post(path, data) {
@@ -2416,11 +2616,11 @@ var RestClient = /*#__PURE__*/function () {
2416
2616
  }
2417
2617
  };
2418
2618
 
2419
- _proto.get = function get(path) {
2619
+ _proto.get = function get(path, signal) {
2420
2620
  try {
2421
2621
  var _this6 = this;
2422
2622
 
2423
- return Promise.resolve(_this6.request(path));
2623
+ return Promise.resolve(_this6.request(path, undefined, undefined, signal));
2424
2624
  } catch (e) {
2425
2625
  return Promise.reject(e);
2426
2626
  }
@@ -2458,24 +2658,20 @@ var RestClient = /*#__PURE__*/function () {
2458
2658
 
2459
2659
  var headers = _this12.getHeaders();
2460
2660
 
2461
- delete headers['Content-Type'];
2462
- headers['Content-Type'] = data['content-type'];
2463
- headers['X-UPLOAD-FILENAME'] = data.filename;
2464
- headers['Content-Encoding'] = 'base64';
2661
+ var newHeaders = {};
2662
+ newHeaders['Content-Type'] = data['content-type'];
2663
+ newHeaders['X-UPLOAD-FILENAME'] = data.filename;
2664
+ newHeaders['Content-Encoding'] = 'base64';
2465
2665
  return Promise.resolve(_this12.request(path, {
2466
2666
  method: 'PATCH',
2467
2667
  body: data.data
2468
- }, headers));
2668
+ }, _extends({}, headers, newHeaders)));
2469
2669
  } catch (e) {
2470
2670
  return Promise.reject(e);
2471
2671
  }
2472
2672
  };
2473
2673
 
2474
2674
  _proto.delete = function _delete(path, data) {
2475
- if (data === void 0) {
2476
- data = undefined;
2477
- }
2478
-
2479
2675
  try {
2480
2676
  var _this14 = this;
2481
2677
 
@@ -2616,6 +2812,14 @@ var GuillotinaClient = /*#__PURE__*/function () {
2616
2812
  }
2617
2813
  };
2618
2814
 
2815
+ _proto.getQueryParamsSearchFunction = function getQueryParamsSearchFunction(name) {
2816
+ if (name === 'getQueryParamsElasticsearch') {
2817
+ return this.getQueryParamsElasticsearch;
2818
+ }
2819
+
2820
+ return this.getQueryParamsPostresql;
2821
+ };
2822
+
2619
2823
  _proto.getQueryParamsPostresql = function getQueryParamsPostresql(_ref) {
2620
2824
  var _ref$start = _ref.start,
2621
2825
  start = _ref$start === void 0 ? 0 : _ref$start,
@@ -2707,7 +2911,7 @@ var GuillotinaClient = /*#__PURE__*/function () {
2707
2911
  label: 'id/name',
2708
2912
  key: 'title',
2709
2913
  isSortable: true,
2710
- child: function child(m, navigate, search) {
2914
+ child: function child(m, _navigate, search) {
2711
2915
  return jsxRuntime.jsxs(TdLink, {
2712
2916
  model: m,
2713
2917
  children: [m.name, search && jsxRuntime.jsxs(React__default['default'].Fragment, {
@@ -2741,15 +2945,19 @@ var GuillotinaClient = /*#__PURE__*/function () {
2741
2945
  });
2742
2946
  }
2743
2947
  }];
2744
- };
2948
+ } // BBB API changes. Compat G5 and G6
2949
+ ;
2745
2950
 
2746
2951
  _proto.applyCompat = function applyCompat(data) {
2747
- data.member = data.items;
2748
- data.items_count = data.items_total;
2749
- return data;
2952
+ var result = _extends({}, data, {
2953
+ member: data.items,
2954
+ items_count: data.items_total
2955
+ });
2956
+
2957
+ return result;
2750
2958
  };
2751
2959
 
2752
- _proto.search = function search(path, params, container, prepare) {
2960
+ _proto.search = function search(path, params, container, prepare, signal) {
2753
2961
  if (container === void 0) {
2754
2962
  container = false;
2755
2963
  }
@@ -2771,7 +2979,7 @@ var GuillotinaClient = /*#__PURE__*/function () {
2771
2979
 
2772
2980
  var query = prepare ? toQueryString(params) : params;
2773
2981
  var url = path + "@search?" + query;
2774
- return Promise.resolve(_this7.rest.get(url)).then(function (res) {
2982
+ return Promise.resolve(_this7.rest.get(url, signal)).then(function (res) {
2775
2983
  return Promise.resolve(res.json()).then(function (data) {
2776
2984
  return _this7.applyCompat(data);
2777
2985
  });
@@ -2901,7 +3109,8 @@ var GuillotinaClient = /*#__PURE__*/function () {
2901
3109
 
2902
3110
  var _temp4 = function () {
2903
3111
  if (!cacheSchemas[name]) {
2904
- var url = _this25.getContainerFromPath(path);
3112
+ var url = _this25.getContainerFromPath(path); // todo: handle db case (only addable containers)
3113
+
2905
3114
 
2906
3115
  return Promise.resolve(_this25.rest.get(url + "@types/" + name)).then(function (res) {
2907
3116
  return Promise.resolve(res.json()).then(function (_res$json) {
@@ -2982,23 +3191,53 @@ var GuillotinaClient = /*#__PURE__*/function () {
2982
3191
  var users = _this37.getUsers(path);
2983
3192
 
2984
3193
  return Promise.resolve(Promise.all([groups, users])).then(function (_ref3) {
2985
- var gr = _ref3[0],
2986
- usr = _ref3[1];
3194
+ var responseGroups = _ref3[0],
3195
+ responseUsers = _ref3[1];
2987
3196
 
2988
- function _temp6(_gr$json) {
2989
- function _temp5(_usr$json) {
3197
+ function _temp8() {
3198
+ function _temp6() {
2990
3199
  return {
2991
- groups: _gr$json,
2992
- users: _usr$json
3200
+ groups: groupsData,
3201
+ users: usersData
2993
3202
  };
2994
3203
  }
2995
3204
 
2996
- var _usr$ok = usr.ok;
2997
- return _usr$ok ? Promise.resolve(usr.json()).then(_temp5) : _temp5([]);
3205
+ var _temp5 = function () {
3206
+ if (responseUsers) {
3207
+ return Promise.resolve(responseUsers.json()).then(function (usersDataResponse) {
3208
+ usersData = usersDataResponse.map(function (user) {
3209
+ return {
3210
+ '@name': user.id,
3211
+ user_roles: user.roles,
3212
+ fullname: user.fullname,
3213
+ email: user.email
3214
+ };
3215
+ });
3216
+ });
3217
+ }
3218
+ }();
3219
+
3220
+ return _temp5 && _temp5.then ? _temp5.then(_temp6) : _temp6(_temp5);
2998
3221
  }
2999
3222
 
3000
- var _gr$ok = gr.ok;
3001
- return _gr$ok ? Promise.resolve(gr.json()).then(_temp6) : _temp6([]);
3223
+ var groupsData = [];
3224
+ var usersData = [];
3225
+
3226
+ var _temp7 = function () {
3227
+ if (responseGroups.ok) {
3228
+ return Promise.resolve(responseGroups.json()).then(function (groupsDataResponse) {
3229
+ groupsData = groupsDataResponse.map(function (group) {
3230
+ return {
3231
+ '@name': group.id,
3232
+ user_roles: group.roles,
3233
+ users: group.users
3234
+ };
3235
+ });
3236
+ });
3237
+ }
3238
+ }();
3239
+
3240
+ return _temp7 && _temp7.then ? _temp7.then(_temp8) : _temp8(_temp7);
3002
3241
  });
3003
3242
  } catch (e) {
3004
3243
  return Promise.reject(e);
@@ -3020,6 +3259,7 @@ var GuillotinaClient = /*#__PURE__*/function () {
3020
3259
  try {
3021
3260
  var _this41 = this;
3022
3261
 
3262
+ // paths used to query the API always has to start without a "/"
3023
3263
  if (path.startsWith('/')) {
3024
3264
  path = path.slice(1);
3025
3265
  }
@@ -3039,7 +3279,7 @@ var GuillotinaClient = /*#__PURE__*/function () {
3039
3279
  try {
3040
3280
  var _this43 = this;
3041
3281
 
3042
- function _temp10() {
3282
+ function _temp12() {
3043
3283
  return cacheTypes[path];
3044
3284
  }
3045
3285
 
@@ -3047,10 +3287,10 @@ var GuillotinaClient = /*#__PURE__*/function () {
3047
3287
  path = path.slice(1);
3048
3288
  }
3049
3289
 
3050
- var _temp11 = function () {
3290
+ var _temp13 = function () {
3051
3291
  if (!cacheTypes[path]) {
3052
3292
  return Promise.resolve(_this43.rest.get(path + '@addable-types')).then(function (types) {
3053
- var _temp7 = function () {
3293
+ var _temp9 = function () {
3054
3294
  if (types.status === 401 || types.status === 404) {
3055
3295
  cacheTypes[path] = [];
3056
3296
  } else {
@@ -3060,12 +3300,12 @@ var GuillotinaClient = /*#__PURE__*/function () {
3060
3300
  }
3061
3301
  }();
3062
3302
 
3063
- if (_temp7 && _temp7.then) return _temp7.then(function () {});
3303
+ if (_temp9 && _temp9.then) return _temp9.then(function () {});
3064
3304
  });
3065
3305
  }
3066
3306
  }();
3067
3307
 
3068
- return Promise.resolve(_temp11 && _temp11.then ? _temp11.then(_temp10) : _temp10(_temp11));
3308
+ return Promise.resolve(_temp13 && _temp13.then ? _temp13.then(_temp12) : _temp12(_temp13));
3069
3309
  } catch (e) {
3070
3310
  return Promise.reject(e);
3071
3311
  }
@@ -3077,17 +3317,24 @@ function getClient(url, container, auth) {
3077
3317
  return new GuillotinaClient(new RestClient(url, container, auth), container === '/');
3078
3318
  }
3079
3319
  var lightFileReader = function lightFileReader(file) {
3080
- return new Promise(function (resolve) {
3320
+ return new Promise(function (resolve, reject) {
3081
3321
  var reader = new FileReader();
3082
3322
  reader.readAsArrayBuffer(file);
3083
3323
 
3084
3324
  reader.onloadend = function (e) {
3085
- var fileData = e.target.result;
3086
- resolve({
3087
- filename: file.name.normalize('NFD').replace(/[\u0300-\u036f]/g, ''),
3088
- data: fileData,
3089
- 'content-type': file.type
3090
- });
3325
+ var _e$target;
3326
+
3327
+ var fileData = e == null ? void 0 : (_e$target = e.target) == null ? void 0 : _e$target.result;
3328
+
3329
+ if (fileData) {
3330
+ resolve({
3331
+ filename: file.name.normalize('NFD').replace(/[\u0300-\u036f]/g, ''),
3332
+ data: fileData,
3333
+ 'content-type': file.type
3334
+ });
3335
+ } else {
3336
+ reject('Error reading file');
3337
+ }
3091
3338
  };
3092
3339
  });
3093
3340
  };
@@ -3118,9 +3365,15 @@ function FileUpload(_ref) {
3118
3365
 
3119
3366
  var changed = function changed(event) {
3120
3367
  try {
3121
- return Promise.resolve(lightFileReader(event.target.files[0])).then(function (fileToUpload) {
3122
- onChange(fileToUpload);
3123
- });
3368
+ var _temp2 = function () {
3369
+ if (event.target.files) {
3370
+ return Promise.resolve(lightFileReader(event.target.files[0])).then(function (fileToUpload) {
3371
+ onChange(fileToUpload);
3372
+ });
3373
+ }
3374
+ }();
3375
+
3376
+ return Promise.resolve(_temp2 && _temp2.then ? _temp2.then(function () {}) : void 0);
3124
3377
  } catch (e) {
3125
3378
  return Promise.reject(e);
3126
3379
  }
@@ -3211,12 +3464,12 @@ Textarea.displayName = 'Textarea';
3211
3464
 
3212
3465
  var defaultEvents = ['mousedown', 'touchstart'];
3213
3466
 
3214
- var on = function on(obj) {
3215
- return obj.addEventListener.apply(obj, [].slice.call(arguments, 1));
3467
+ var on = function on(obj, type, handler) {
3468
+ return obj.addEventListener(type, handler);
3216
3469
  };
3217
3470
 
3218
- var off = function off(obj) {
3219
- return obj.removeEventListener.apply(obj, [].slice.call(arguments, 1));
3471
+ var off = function off(obj, type, handler) {
3472
+ return obj.removeEventListener(type, handler);
3220
3473
  };
3221
3474
 
3222
3475
  function useClickAway(ref, onClickAway, events) {
@@ -3248,23 +3501,7 @@ function useClickAway(ref, onClickAway, events) {
3248
3501
  }, [events, ref]);
3249
3502
  }
3250
3503
 
3251
- function debounce(func, wait) {
3252
- var timeout;
3253
- return function () {
3254
- var context = this;
3255
- var args = arguments;
3256
-
3257
- var later = function later() {
3258
- timeout = null;
3259
- func.apply(context, args);
3260
- };
3261
-
3262
- clearTimeout(timeout);
3263
- timeout = setTimeout(later, wait);
3264
- };
3265
- }
3266
-
3267
- var initialState = {
3504
+ var initialState$1 = {
3268
3505
  page: 0,
3269
3506
  items: undefined,
3270
3507
  loading: false,
@@ -3274,10 +3511,9 @@ var SearchInput = function SearchInput(_ref) {
3274
3511
  var onChange = _ref.onChange,
3275
3512
  error = _ref.error,
3276
3513
  errorZoneClassName = _ref.errorZoneClassName,
3277
- _ref$traversal = _ref.traversal,
3278
- traversal = _ref$traversal === void 0 ? null : _ref$traversal,
3514
+ traversal = _ref.traversal,
3279
3515
  _ref$path = _ref.path,
3280
- path = _ref$path === void 0 ? null : _ref$path,
3516
+ path = _ref$path === void 0 ? undefined : _ref$path,
3281
3517
  _ref$qs = _ref.qs,
3282
3518
  qs = _ref$qs === void 0 ? [] : _ref$qs,
3283
3519
  _ref$queryCondition = _ref.queryCondition,
@@ -3292,14 +3528,14 @@ var SearchInput = function SearchInput(_ref) {
3292
3528
  _ref$dataTestItem = _ref.dataTestItem,
3293
3529
  dataTestItem = _ref$dataTestItem === void 0 ? 'searchInputItemTest' : _ref$dataTestItem,
3294
3530
  _ref$renderTextItemOp = _ref.renderTextItemOption,
3295
- renderTextItemOption = _ref$renderTextItemOp === void 0 ? null : _ref$renderTextItemOp,
3531
+ renderTextItemOption = _ref$renderTextItemOp === void 0 ? undefined : _ref$renderTextItemOp,
3296
3532
  _ref$typeNameQuery = _ref.typeNameQuery,
3297
- typeNameQuery = _ref$typeNameQuery === void 0 ? null : _ref$typeNameQuery,
3533
+ typeNameQuery = _ref$typeNameQuery === void 0 ? undefined : _ref$typeNameQuery,
3298
3534
  _ref$labelProperty = _ref.labelProperty,
3299
3535
  labelProperty = _ref$labelProperty === void 0 ? 'id' : _ref$labelProperty;
3300
3536
  var intl = reactIntl.useIntl();
3301
3537
 
3302
- var _useSetState = useSetState(initialState),
3538
+ var _useSetState = useSetState(initialState$1),
3303
3539
  options = _useSetState[0],
3304
3540
  setOptions = _useSetState[1];
3305
3541
 
@@ -3353,7 +3589,7 @@ var SearchInput = function SearchInput(_ref) {
3353
3589
  var searchTermParsed = ["id", value];
3354
3590
  var getSearch = traversal.registry.get;
3355
3591
  var fnName = getSearch('searchEngineQueryParamsFunction', SearchEngine);
3356
- var qsParsed = traversal.client[fnName]({
3592
+ var qsParsed = traversal.client.getQueryParamsSearchFunction(fnName)({
3357
3593
  path: traversal.path,
3358
3594
  start: 0,
3359
3595
  pageSize: PageSize,
@@ -3371,7 +3607,7 @@ var SearchInput = function SearchInput(_ref) {
3371
3607
 
3372
3608
  return Promise.resolve(traversal.client.search(path ? path : traversal.client.getContainerFromPath(traversal.path), searchTermQs, false, false)).then(function (data) {
3373
3609
  var newValuesLabel = data.items.reduce(function (result, item) {
3374
- result[item.id] = get$1(item, labelProperty, item.id);
3610
+ result[item.id] = get(item, labelProperty, item.id);
3375
3611
  return result;
3376
3612
  }, {});
3377
3613
  setValueLabel(newValuesLabel);
@@ -3399,6 +3635,7 @@ var SearchInput = function SearchInput(_ref) {
3399
3635
  }
3400
3636
 
3401
3637
  try {
3638
+ console.log('handle search input');
3402
3639
  setOptions({
3403
3640
  loading: true
3404
3641
  });
@@ -3413,7 +3650,7 @@ var SearchInput = function SearchInput(_ref) {
3413
3650
 
3414
3651
  var fnName = _get('searchEngineQueryParamsFunction', SearchEngine);
3415
3652
 
3416
- var qsParsed = traversal.client[fnName]({
3653
+ var qsParsed = traversal.client.getQueryParamsSearchFunction(fnName)({
3417
3654
  path: traversal.path,
3418
3655
  start: page * PageSize,
3419
3656
  pageSize: PageSize,
@@ -3426,7 +3663,7 @@ var SearchInput = function SearchInput(_ref) {
3426
3663
  typeNameParsed = parser("type_name__in=" + typeNameQuery);
3427
3664
  }
3428
3665
 
3429
- if (qs.length > 0 || searchTermParsed.length > 0 || qsParsed.length > 0 || typeNameParsed.length > 0) {
3666
+ if (qs.length > 0 || searchTermParsed.length > 0 || qsParsed.length > 0 || typeNameParsed.length > 0 || sortParsed.length > 0) {
3430
3667
  searchTermQs = buildQs([].concat(qs, searchTermParsed, qsParsed, typeNameParsed, sortParsed));
3431
3668
  }
3432
3669
 
@@ -3451,7 +3688,7 @@ var SearchInput = function SearchInput(_ref) {
3451
3688
  return renderTextItemOption(item);
3452
3689
  }
3453
3690
 
3454
- return get$1(item, labelProperty, item.title) || item['@name'];
3691
+ return get(item, labelProperty, item.title) || item['@name'];
3455
3692
  };
3456
3693
 
3457
3694
  React.useEffect(function () {
@@ -3477,7 +3714,7 @@ var SearchInput = function SearchInput(_ref) {
3477
3714
  if (!ev.currentTarget.contains(ev.relatedTarget)) {
3478
3715
  if (searchTerm !== '') {
3479
3716
  setSearchTerm('');
3480
- setOptions(initialState);
3717
+ setOptions(initialState$1);
3481
3718
  }
3482
3719
 
3483
3720
  setIsOpen(false);
@@ -3495,6 +3732,7 @@ var SearchInput = function SearchInput(_ref) {
3495
3732
  }
3496
3733
 
3497
3734
  setIsOpen(!isOpen);
3735
+ console.log('on clic btn', options);
3498
3736
 
3499
3737
  if (!options.loading && !options.items) {
3500
3738
  handleSearch(options.page);
@@ -3503,7 +3741,7 @@ var SearchInput = function SearchInput(_ref) {
3503
3741
  "aria-haspopup": "true",
3504
3742
  "aria-controls": "dropdown-menu",
3505
3743
  children: [jsxRuntime.jsx("span", {
3506
- children: value ? get$1(valueLabel, value, value) : intl.formatMessage(genericMessages.choose)
3744
+ children: value ? get(valueLabel, value, value) : intl.formatMessage(genericMessages.choose)
3507
3745
  }), jsxRuntime.jsx("span", {
3508
3746
  className: "icon",
3509
3747
  children: jsxRuntime.jsx("i", {
@@ -3577,23 +3815,7 @@ var SearchInput = function SearchInput(_ref) {
3577
3815
  });
3578
3816
  };
3579
3817
 
3580
- function debounce$1(func, wait) {
3581
- var timeout;
3582
- return function () {
3583
- var context = this;
3584
- var args = arguments;
3585
-
3586
- var later = function later() {
3587
- timeout = null;
3588
- func.apply(context, args);
3589
- };
3590
-
3591
- clearTimeout(timeout);
3592
- timeout = setTimeout(later, wait);
3593
- };
3594
- }
3595
-
3596
- var initialState$1 = {
3818
+ var initialState$2 = {
3597
3819
  page: 0,
3598
3820
  items: undefined,
3599
3821
  loading: false,
@@ -3603,10 +3825,9 @@ var SearchInputList = function SearchInputList(_ref) {
3603
3825
  var onChange = _ref.onChange,
3604
3826
  error = _ref.error,
3605
3827
  errorZoneClassName = _ref.errorZoneClassName,
3606
- _ref$traversal = _ref.traversal,
3607
- traversal = _ref$traversal === void 0 ? null : _ref$traversal,
3828
+ traversal = _ref.traversal,
3608
3829
  _ref$path = _ref.path,
3609
- path = _ref$path === void 0 ? null : _ref$path,
3830
+ path = _ref$path === void 0 ? undefined : _ref$path,
3610
3831
  _ref$qs = _ref.qs,
3611
3832
  qs = _ref$qs === void 0 ? [] : _ref$qs,
3612
3833
  _ref$queryCondition = _ref.queryCondition,
@@ -3621,14 +3842,14 @@ var SearchInputList = function SearchInputList(_ref) {
3621
3842
  _ref$dataTestItem = _ref.dataTestItem,
3622
3843
  dataTestItem = _ref$dataTestItem === void 0 ? 'searchInputItemTest' : _ref$dataTestItem,
3623
3844
  _ref$renderTextItemOp = _ref.renderTextItemOption,
3624
- renderTextItemOption = _ref$renderTextItemOp === void 0 ? null : _ref$renderTextItemOp,
3845
+ renderTextItemOption = _ref$renderTextItemOp === void 0 ? undefined : _ref$renderTextItemOp,
3625
3846
  _ref$typeNameQuery = _ref.typeNameQuery,
3626
- typeNameQuery = _ref$typeNameQuery === void 0 ? null : _ref$typeNameQuery,
3847
+ typeNameQuery = _ref$typeNameQuery === void 0 ? undefined : _ref$typeNameQuery,
3627
3848
  _ref$labelProperty = _ref.labelProperty,
3628
3849
  labelProperty = _ref$labelProperty === void 0 ? 'id' : _ref$labelProperty;
3629
3850
  var intl = reactIntl.useIntl();
3630
3851
 
3631
- var _useSetState = useSetState(initialState$1),
3852
+ var _useSetState = useSetState(initialState$2),
3632
3853
  options = _useSetState[0],
3633
3854
  setOptions = _useSetState[1];
3634
3855
 
@@ -3674,7 +3895,7 @@ var SearchInputList = function SearchInputList(_ref) {
3674
3895
  };
3675
3896
  };
3676
3897
 
3677
- var delayedQuery = React.useCallback(debounce$1(function (value) {
3898
+ var delayedQuery = React.useCallback(debounce(function (value) {
3678
3899
  return handleSearch(0, false, value);
3679
3900
  }, 500), []);
3680
3901
 
@@ -3706,7 +3927,7 @@ var SearchInputList = function SearchInputList(_ref) {
3706
3927
 
3707
3928
  var fnName = _get('searchEngineQueryParamsFunction', SearchEngine);
3708
3929
 
3709
- var qsParsed = traversal.client[fnName]({
3930
+ var qsParsed = traversal.client.getQueryParamsSearchFunction(fnName)({
3710
3931
  path: traversal.path,
3711
3932
  start: page * PageSize,
3712
3933
  pageSize: PageSize,
@@ -3748,7 +3969,7 @@ var SearchInputList = function SearchInputList(_ref) {
3748
3969
  var searchTermParsed = ['__or', "id=" + value.join('%26id=')];
3749
3970
  var getSearch = traversal.registry.get;
3750
3971
  var fnName = getSearch('searchEngineQueryParamsFunction', SearchEngine);
3751
- var qsParsed = traversal.client[fnName]({
3972
+ var qsParsed = traversal.client.getQueryParamsSearchFunction(fnName)({
3752
3973
  path: traversal.path,
3753
3974
  start: 0,
3754
3975
  pageSize: 100,
@@ -3764,9 +3985,9 @@ var SearchInputList = function SearchInputList(_ref) {
3764
3985
  searchTermQs = buildQs([].concat(qs, [searchTermParsed], qsParsed, typeNameParsed));
3765
3986
  }
3766
3987
 
3767
- return Promise.resolve(traversal.client.search(path ? path : traversal.client.getContainerFromPath(traversal.path), searchTermQs, false, false, 0, 100)).then(function (data) {
3988
+ return Promise.resolve(traversal.client.search(path ? path : traversal.client.getContainerFromPath(traversal.path), searchTermQs, false, false)).then(function (data) {
3768
3989
  var newValuesLabel = data.items.reduce(function (result, item) {
3769
- result[item.id] = get$1(item, labelProperty, item.id);
3990
+ result[item.id] = get(item, labelProperty, item.id);
3770
3991
  return result;
3771
3992
  }, {});
3772
3993
  setValuesLabels(newValuesLabel);
@@ -3786,7 +4007,7 @@ var SearchInputList = function SearchInputList(_ref) {
3786
4007
  return renderTextItemOption(item);
3787
4008
  }
3788
4009
 
3789
- return get$1(item, labelProperty, item.title) || item['@name'];
4010
+ return get(item, labelProperty, item.title) || item['@name'];
3790
4011
  };
3791
4012
 
3792
4013
  React.useEffect(function () {
@@ -3809,7 +4030,7 @@ var SearchInputList = function SearchInputList(_ref) {
3809
4030
  children: value.map(function (tag, index) {
3810
4031
  return jsxRuntime.jsxs("div", {
3811
4032
  className: "tag is-info is-medium",
3812
- children: [get$1(valuesLabel, tag, tag), jsxRuntime.jsx("button", {
4033
+ children: [get(valuesLabel, tag, tag), jsxRuntime.jsx("button", {
3813
4034
  className: "delete is-small",
3814
4035
  onClick: function onClick(ev) {
3815
4036
  ev.stopPropagation();
@@ -3829,7 +4050,7 @@ var SearchInputList = function SearchInputList(_ref) {
3829
4050
  if (!ev.currentTarget.contains(ev.relatedTarget)) {
3830
4051
  if (searchTerm !== '') {
3831
4052
  setSearchTerm('');
3832
- setOptions(initialState$1);
4053
+ setOptions(initialState$2);
3833
4054
  }
3834
4055
 
3835
4056
  setIsOpen(false);
@@ -3893,7 +4114,7 @@ var SearchInputList = function SearchInputList(_ref) {
3893
4114
  if (onChange && !value.includes(item.id)) {
3894
4115
  var _extends2;
3895
4116
 
3896
- setValuesLabels(_extends({}, valuesLabel, (_extends2 = {}, _extends2[item.id] = get$1(item, labelProperty, item.id), _extends2)));
4117
+ setValuesLabels(_extends({}, valuesLabel, (_extends2 = {}, _extends2[item.id] = get(item, labelProperty, item.id), _extends2)));
3897
4118
  onChange([].concat(value, [item.id]));
3898
4119
  }
3899
4120
  },
@@ -4081,7 +4302,7 @@ function EditableField(_ref) {
4081
4302
  ref.current.focus();
4082
4303
  }
4083
4304
  });
4084
- var canModified = modifyContent && !get$1(schema, 'readonly', false);
4305
+ var canModified = schema !== undefined && modifyContent && !get(schema, 'readonly', false);
4085
4306
 
4086
4307
  var saveField = function saveField(ev) {
4087
4308
  try {
@@ -4147,7 +4368,7 @@ function EditableField(_ref) {
4147
4368
  var deleteField = function deleteField(ev) {
4148
4369
  try {
4149
4370
  if (ev) ev.preventDefault();
4150
- return Promise.resolve(function () {
4371
+ return Promise.resolve(function (_schema$items) {
4151
4372
  if ((schema == null ? void 0 : schema.widget) === 'file') {
4152
4373
  var _ns2, _ref4, _ref5;
4153
4374
 
@@ -4175,7 +4396,7 @@ function EditableField(_ref) {
4175
4396
  });
4176
4397
  } else if ((schema == null ? void 0 : schema.type) === 'string' && schema != null && schema.enum) {
4177
4398
  setValue(null);
4178
- } else if ((schema == null ? void 0 : schema.type) === 'array' && (schema == null ? void 0 : schema.items.type) === 'string') {
4399
+ } else if ((schema == null ? void 0 : schema.type) === 'array' && (schema == null ? void 0 : (_schema$items = schema.items) == null ? void 0 : _schema$items.type) === 'string') {
4179
4400
  setValue([]);
4180
4401
  }
4181
4402
  }());
@@ -4232,7 +4453,7 @@ function EditableField(_ref) {
4232
4453
  dataTest: "editableFieldBtnCancelTest",
4233
4454
  children: intl.formatMessage(genericMessages.cancel)
4234
4455
  })
4235
- }), !required && fieldHaveDeleteButton(schema) && jsxRuntime.jsx("div", {
4456
+ }), !required && schema && fieldHaveDeleteButton(schema) && jsxRuntime.jsx("div", {
4236
4457
  className: "control",
4237
4458
  children: jsxRuntime.jsx(Button, {
4238
4459
  className: "is-small is-danger",
@@ -4261,7 +4482,8 @@ var DownloadField = function DownloadField(_ref) {
4261
4482
  var blob = new Blob([text], {
4262
4483
  type: data.content_type
4263
4484
  });
4264
- var url = window.URL.createObjectURL(blob);
4485
+ var url = window.URL.createObjectURL(blob); // Create blob link to download
4486
+
4265
4487
  var link = document.createElement('a');
4266
4488
  link.href = url;
4267
4489
 
@@ -4276,6 +4498,7 @@ var DownloadField = function DownloadField(_ref) {
4276
4498
  setTimeout(function () {
4277
4499
  var _link$parentNode;
4278
4500
 
4501
+ // For Firefox it is necessary to delay revoking the ObjectURL
4279
4502
  window.URL.revokeObjectURL(url);
4280
4503
  (_link$parentNode = link.parentNode) == null ? void 0 : _link$parentNode.removeChild(link);
4281
4504
  }, 100);
@@ -4351,23 +4574,27 @@ function RenderField(_ref) {
4351
4574
  }
4352
4575
 
4353
4576
  if (type === 'object') {
4577
+ var _schema$properties;
4578
+
4354
4579
  if (Array.isArray(value)) {
4355
- return value.map(function (item) {
4580
+ return value.map(function (item, index) {
4356
4581
  return jsxRuntime.jsx("div", {
4357
4582
  children: jsxRuntime.jsx(RenderField, {
4358
4583
  value: item
4359
4584
  })
4360
- }, item);
4585
+ }, "renderField_" + index + "_" + (schema == null ? void 0 : schema.title));
4361
4586
  });
4362
4587
  }
4363
4588
 
4364
- return Object.keys(value).map(function (key) {
4365
- return jsxRuntime.jsx(FieldValue, {
4366
- field: get$1(schema, "properties." + key + ".title", key),
4367
- schema: get$1(schema, "properties." + key, {}),
4368
- value: value[key]
4369
- }, key);
4370
- });
4589
+ if ((schema == null ? void 0 : (_schema$properties = schema.properties) == null ? void 0 : _schema$properties.key) !== undefined) {
4590
+ return Object.keys(value).map(function (key) {
4591
+ return jsxRuntime.jsx(FieldValue, {
4592
+ field: get(schema, "properties." + key + ".title", key),
4593
+ schema: schema.properties.key,
4594
+ value: get(value, key, {})
4595
+ }, key);
4596
+ });
4597
+ }
4371
4598
  }
4372
4599
 
4373
4600
  return jsxRuntime.jsxs("p", {
@@ -4411,6 +4638,7 @@ var SearchRenderField = function SearchRenderField(_ref3) {
4411
4638
  var schema = _ref3.schema,
4412
4639
  value = _ref3.value,
4413
4640
  modifyContent = _ref3.modifyContent;
4641
+ console.log('search render fields');
4414
4642
  var intl = reactIntl.useIntl();
4415
4643
 
4416
4644
  var _useState = React.useState([]),
@@ -4435,7 +4663,7 @@ var SearchRenderField = function SearchRenderField(_ref3) {
4435
4663
  var searchTermParsed = ['__or', "id=" + valuesToSearch.join('%26id=')];
4436
4664
  var getSearch = traversal.registry.get;
4437
4665
  var fnName = getSearch('searchEngineQueryParamsFunction', SearchEngine);
4438
- var qsParsed = traversal.client[fnName]({
4666
+ var qsParsed = traversal.client.getQueryParamsSearchFunction(fnName)({
4439
4667
  path: traversal.path,
4440
4668
  start: 0,
4441
4669
  pageSize: 100,
@@ -4446,11 +4674,11 @@ var SearchRenderField = function SearchRenderField(_ref3) {
4446
4674
  searchTermQs = buildQs([searchTermParsed].concat(qsParsed));
4447
4675
  }
4448
4676
 
4449
- return Promise.resolve(traversal.client.search(traversal.client.getContainerFromPath(traversal.path), searchTermQs, false, false, 0, 100)).then(function (data) {
4677
+ return Promise.resolve(traversal.client.search(traversal.client.getContainerFromPath(traversal.path), searchTermQs, false, false)).then(function (data) {
4450
4678
  var newValuesLabel = data.items.map(function (item) {
4451
4679
  var _schema$labelProperty;
4452
4680
 
4453
- return get$1(item, (_schema$labelProperty = schema == null ? void 0 : schema.labelProperty) != null ? _schema$labelProperty : 'title', item.id);
4681
+ return get(item, (_schema$labelProperty = schema == null ? void 0 : schema.labelProperty) != null ? _schema$labelProperty : 'title', item.id);
4454
4682
  });
4455
4683
  setValuesLabels(newValuesLabel);
4456
4684
  setIsLoadingData(false);
@@ -4460,13 +4688,15 @@ var SearchRenderField = function SearchRenderField(_ref3) {
4460
4688
  }
4461
4689
  };
4462
4690
 
4463
- var valuesToSearch = value;
4691
+ var valuesToSearch = [];
4464
4692
 
4465
- if (typeof valuesToSearch === 'string') {
4466
- valuesToSearch = [valuesToSearch];
4693
+ if (typeof value === 'string' && value) {
4694
+ valuesToSearch = [value];
4695
+ } else if (Array.isArray(value)) {
4696
+ valuesToSearch = value;
4467
4697
  }
4468
4698
 
4469
- if (valuesToSearch !== undefined && valuesToSearch.length > 0) {
4699
+ if (valuesToSearch.length > 0) {
4470
4700
  fetchData(valuesToSearch);
4471
4701
  } else {
4472
4702
  setValuesLabels([]);
@@ -4501,7 +4731,7 @@ var VocabularyRenderField = function VocabularyRenderField(_ref4) {
4501
4731
  modifyContent = _ref4.modifyContent;
4502
4732
  var intl = reactIntl.useIntl();
4503
4733
  var DEFAULT_VALUE_EDITABLE_FIELD = getDefaultValueEditableField(intl);
4504
- var vocabularyName = (schema == null ? void 0 : (_schema$items = schema.items) == null ? void 0 : _schema$items.vocabularyName) || (schema == null ? void 0 : schema.vocabularyName);
4734
+ var vocabularyName = (schema == null ? void 0 : (_schema$items = schema.items) == null ? void 0 : _schema$items.vocabularyName) || (schema == null ? void 0 : schema.vocabularyName) || '';
4505
4735
  var vocabulary = useVocabulary(vocabularyName);
4506
4736
 
4507
4737
  var getRenderProps = function getRenderProps() {
@@ -4512,7 +4742,7 @@ var VocabularyRenderField = function VocabularyRenderField(_ref4) {
4512
4742
  if (schema != null && schema.vocabularyName) {
4513
4743
  var _vocabularyValue$titl;
4514
4744
 
4515
- var vocabularyValue = get$1(vocabulary, 'data.items', []).find(function (item) {
4745
+ var vocabularyValue = get(vocabulary, 'data.items', []).find(function (item) {
4516
4746
  return item.token === value;
4517
4747
  });
4518
4748
  renderProps['value'] = (_vocabularyValue$titl = vocabularyValue == null ? void 0 : vocabularyValue.title) != null ? _vocabularyValue$titl : '';
@@ -4522,7 +4752,7 @@ var VocabularyRenderField = function VocabularyRenderField(_ref4) {
4522
4752
  renderProps['value'] = ((_renderProps$value = renderProps['value']) != null ? _renderProps$value : []).map(function (value) {
4523
4753
  var _get$find$title, _get$find;
4524
4754
 
4525
- return (_get$find$title = (_get$find = get$1(vocabulary, 'data.items', []).find(function (item) {
4755
+ return (_get$find$title = (_get$find = get(vocabulary, 'data.items', []).find(function (item) {
4526
4756
  return item.token === value;
4527
4757
  })) == null ? void 0 : _get$find.title) != null ? _get$find$title : '';
4528
4758
  });
@@ -4599,7 +4829,7 @@ var EditComponent = React.forwardRef(function (_ref, ref) {
4599
4829
  queryCondition: schema != null && schema.queryCondition ? schema.queryCondition : 'title__in',
4600
4830
  path: schema.queryPath,
4601
4831
  labelProperty: schema != null && schema.labelProperty ? schema.labelProperty : 'title',
4602
- typeNameQuery: schema != null && schema.typeNameQuery ? schema.typeNameQuery : null
4832
+ typeNameQuery: schema == null ? void 0 : schema.typeNameQuery
4603
4833
  })]
4604
4834
  });
4605
4835
  } else if ((schema == null ? void 0 : schema.widget) === 'search') {
@@ -4616,7 +4846,7 @@ var EditComponent = React.forwardRef(function (_ref, ref) {
4616
4846
  queryCondition: schema != null && schema.queryCondition ? schema.queryCondition : 'title__in',
4617
4847
  path: schema.queryPath,
4618
4848
  labelProperty: schema != null && schema.labelProperty ? schema.labelProperty : 'title',
4619
- typeNameQuery: schema != null && schema.typeNameQuery ? schema.typeNameQuery : null
4849
+ typeNameQuery: schema == null ? void 0 : schema.typeNameQuery
4620
4850
  })]
4621
4851
  });
4622
4852
  } else if ((schema == null ? void 0 : schema.widget) === 'textarea' || (schema == null ? void 0 : schema.widget) === 'richtext') {
@@ -4646,7 +4876,7 @@ var EditComponent = React.forwardRef(function (_ref, ref) {
4646
4876
 
4647
4877
  if (schema.items.vocabularyName) {
4648
4878
  return jsxRuntime.jsx(SelectVocabulary, {
4649
- vocabularyName: get$1(schema, 'items.vocabularyName', null),
4879
+ vocabularyName: get(schema, 'items.vocabularyName', ''),
4650
4880
  val: val || [],
4651
4881
  className: className,
4652
4882
  classWrap: "is-fullwidth",
@@ -4683,22 +4913,25 @@ var EditComponent = React.forwardRef(function (_ref, ref) {
4683
4913
  }), jsxRuntime.jsx(InputList, {
4684
4914
  value: val || [],
4685
4915
  className: className,
4686
- onChange: function onChange(ev) {
4687
- return _setValue(ev);
4916
+ onChange: function onChange(val) {
4917
+ return _setValue(val);
4688
4918
  },
4689
4919
  ref: ref,
4690
4920
  dataTest: dataTest
4691
4921
  })]
4692
4922
  });
4693
4923
  } else if ((schema == null ? void 0 : schema.widget) === 'file') {
4924
+ var value = val;
4694
4925
  return jsxRuntime.jsx(FileUpload, {
4695
4926
  onChange: function onChange(ev) {
4696
4927
  return _setValue(ev);
4697
4928
  },
4698
- label: get$1(val, 'filename', null),
4929
+ label: get(value, 'filename', undefined),
4699
4930
  dataTest: dataTest
4700
4931
  });
4701
4932
  } else if ((schema == null ? void 0 : schema.widget) === 'select' && schema.type === 'string') {
4933
+ var _schema$vocabulary;
4934
+
4702
4935
  if (schema != null && schema.vocabularyName) {
4703
4936
  return jsxRuntime.jsx(SelectVocabulary, {
4704
4937
  val: val || '',
@@ -4707,7 +4940,7 @@ var EditComponent = React.forwardRef(function (_ref, ref) {
4707
4940
  classWrap: "is-fullwidth",
4708
4941
  dataTest: dataTest,
4709
4942
  onChange: _setValue,
4710
- vocabularyName: get$1(schema, 'vocabularyName', null),
4943
+ vocabularyName: get(schema, 'vocabularyName', ''),
4711
4944
  placeholder: placeholder,
4712
4945
  id: id
4713
4946
  });
@@ -4719,7 +4952,7 @@ var EditComponent = React.forwardRef(function (_ref, ref) {
4719
4952
  appendDefault: true,
4720
4953
  classWrap: "is-fullwidth",
4721
4954
  dataTest: dataTest,
4722
- options: schema == null ? void 0 : schema.vocabulary.map(function (item) {
4955
+ options: ((_schema$vocabulary = schema == null ? void 0 : schema.vocabulary) != null ? _schema$vocabulary : []).map(function (item) {
4723
4956
  return {
4724
4957
  text: item,
4725
4958
  value: item
@@ -4730,26 +4963,27 @@ var EditComponent = React.forwardRef(function (_ref, ref) {
4730
4963
  id: id
4731
4964
  });
4732
4965
  } else if ((schema == null ? void 0 : schema.type) === 'object' && schema.widget !== 'file') {
4733
- var value = val;
4966
+ var _value = val;
4734
4967
  return jsxRuntime.jsxs(jsxRuntime.Fragment, {
4735
4968
  children: [schema.title && jsxRuntime.jsx("h4", {
4736
4969
  className: "subtitle mt-2",
4737
4970
  children: schema.title
4738
- }), Object.keys(get$1(schema, 'properties', {})).map(function (key) {
4971
+ }), Object.keys(get(schema, 'properties', {})).map(function (key) {
4739
4972
  var _subSchema$title;
4740
4973
 
4741
- var subSchema = get$1(schema, 'properties', {})[key];
4742
- var requiredFields = get$1(schema, 'required', []);
4974
+ var subSchema = get(schema, "properties." + key, null);
4975
+ var requiredFields = get(schema, 'required', []);
4976
+ if (!subSchema) return null;
4743
4977
  return jsxRuntime.jsx(EditComponent, {
4744
4978
  id: id + "[" + key + "]",
4745
4979
  schema: subSchema,
4746
- val: value && key in value ? value[key] : '',
4980
+ val: _value && key in _value ? _value[key] : '',
4747
4981
  placeholder: (_subSchema$title = subSchema == null ? void 0 : subSchema.title) != null ? _subSchema$title : '',
4748
4982
  required: requiredFields.includes(key),
4749
4983
  setValue: function setValue(ev) {
4750
4984
  var _extends2;
4751
4985
 
4752
- _setValue(_extends({}, value, (_extends2 = {}, _extends2[key] = ev, _extends2)));
4986
+ _setValue(_extends({}, _value, (_extends2 = {}, _extends2[key] = ev, _extends2)));
4753
4987
  },
4754
4988
  dataTest: key + "TestInput"
4755
4989
  }, id + "[" + key + "]");
@@ -4811,9 +5045,9 @@ function IAttachment(_ref) {
4811
5045
  }, 1), jsxRuntime.jsx("td", {
4812
5046
  children: jsxRuntime.jsx(EditableField, {
4813
5047
  field: key,
4814
- value: values[key],
5048
+ value: values.file,
4815
5049
  ns: "guillotina.behaviors.attachment.IAttachment",
4816
- schema: properties[key],
5050
+ schema: properties.file,
4817
5051
  modifyContent: modifyContent && ['file'].includes(key)
4818
5052
  })
4819
5053
  }, 2)]
@@ -4863,6 +5097,11 @@ function IMultiAttachment(_ref) {
4863
5097
 
4864
5098
  setLoading(true);
4865
5099
  setError(undefined);
5100
+
5101
+ if (!file) {
5102
+ return Promise.resolve();
5103
+ }
5104
+
4866
5105
  var endpoint = Ctx.path + "@upload/files/" + fileKey;
4867
5106
  return Promise.resolve(Ctx.client.upload(endpoint, file)).then(function (req) {
4868
5107
  if (req.status !== 200) {
@@ -4931,7 +5170,7 @@ function IMultiAttachment(_ref) {
4931
5170
  field: "files/" + key,
4932
5171
  value: values['files'][key],
4933
5172
  ns: "guillotina.behaviors.attachment.IMultiAttachment.files",
4934
- schema: properties['files']['additionalProperties'],
5173
+ schema: get(properties, 'files.additionalProperties', {}),
4935
5174
  modifyContent: false
4936
5175
  }), jsxRuntime.jsx("div", {
4937
5176
  className: "ml-5",
@@ -5155,13 +5394,18 @@ function IImageAttachment(_ref) {
5155
5394
  ev.preventDefault();
5156
5395
  setLoading(true);
5157
5396
  setError(undefined);
5397
+
5398
+ if (!file) {
5399
+ return Promise.resolve();
5400
+ }
5401
+
5158
5402
  var endpoint = Ctx.path + "@upload/image";
5159
5403
  return Promise.resolve(Ctx.client.upload(endpoint, file)).then(function (req) {
5160
5404
  var _exit;
5161
5405
 
5162
5406
  function _temp4(_result) {
5163
5407
  if (_exit) return _result;
5164
- setFile(undefined);
5408
+ setFile(null);
5165
5409
  setLoading(false);
5166
5410
  Ctx.flash(intl.formatMessage(genericFileMessages.image_uploaded), 'success');
5167
5411
  Ctx.refresh();
@@ -5442,7 +5686,7 @@ function IMultiImageAttachment(_ref) {
5442
5686
  fileKey = _useState[0],
5443
5687
  setFileKey = _useState[1];
5444
5688
 
5445
- var _useState2 = React.useState(null),
5689
+ var _useState2 = React.useState(undefined),
5446
5690
  file = _useState2[0],
5447
5691
  setFile = _useState2[1];
5448
5692
 
@@ -5475,6 +5719,11 @@ function IMultiImageAttachment(_ref) {
5475
5719
 
5476
5720
  setLoading(true);
5477
5721
  setError(undefined);
5722
+
5723
+ if (!file) {
5724
+ return Promise.resolve();
5725
+ }
5726
+
5478
5727
  var endpoint = Ctx.path + "@upload/images/" + fileKey;
5479
5728
  return Promise.resolve(Ctx.client.upload(endpoint, file)).then(function (req) {
5480
5729
  var _exit;
@@ -5577,7 +5826,7 @@ function IMultiImageAttachment(_ref) {
5577
5826
  field: "images/" + key,
5578
5827
  value: values['images'][key],
5579
5828
  ns: "guillotina.contrib.image.behaviors.IMultiImageAttachment.images",
5580
- schema: properties['images']['additionalProperties'],
5829
+ schema: get(properties, 'images.additionalProperties', {}),
5581
5830
  modifyContent: false,
5582
5831
  required: false
5583
5832
  }), jsxRuntime.jsx("div", {
@@ -5867,7 +6116,7 @@ function IMultiImageOrderedAttachment(_ref2) {
5867
6116
  sortedList = _useState2[0],
5868
6117
  setSortedList = _useState2[1];
5869
6118
 
5870
- var _useState3 = React.useState(null),
6119
+ var _useState3 = React.useState(undefined),
5871
6120
  file = _useState3[0],
5872
6121
  setFile = _useState3[1];
5873
6122
 
@@ -6011,7 +6260,7 @@ function IMultiImageOrderedAttachment(_ref2) {
6011
6260
  field: "images/" + key,
6012
6261
  value: values['images'][key],
6013
6262
  ns: "guillotina.contrib.image.behaviors.IMultiImageAttachment.images",
6014
- schema: properties['images']['additionalProperties'],
6263
+ schema: get(properties, 'images.additionalProperties', {}),
6015
6264
  modifyContent: false,
6016
6265
  required: false
6017
6266
  }), jsxRuntime.jsx("div", {
@@ -6066,163 +6315,6 @@ function IMultiImageOrderedAttachment(_ref2) {
6066
6315
  });
6067
6316
  }
6068
6317
 
6069
- var base = {
6070
- local: {
6071
- roleperm: {},
6072
- prinperm: {},
6073
- prinrole: {}
6074
- },
6075
- inherit: []
6076
- };
6077
- var Sharing = /*#__PURE__*/function () {
6078
- function Sharing(element) {
6079
- this.local = void 0;
6080
- this.inherit = void 0;
6081
- Object.assign(this, element || base);
6082
- }
6083
-
6084
- var _proto = Sharing.prototype;
6085
-
6086
- _proto.getRole = function getRole(role) {
6087
- return this.local.roleperm[role];
6088
- };
6089
-
6090
- _proto.getPrincipals = function getPrincipals(principal) {
6091
- return this.local.prinperm[principal];
6092
- };
6093
-
6094
- _proto.getPrinroles = function getPrinroles(role) {
6095
- return this.local.prinrole[role];
6096
- };
6097
-
6098
- _createClass(Sharing, [{
6099
- key: "roles",
6100
- get: function get() {
6101
- return Object.keys(this.local.roleperm);
6102
- }
6103
- }, {
6104
- key: "principals",
6105
- get: function get() {
6106
- return Object.keys(this.local.prinperm);
6107
- }
6108
- }, {
6109
- key: "prinrole",
6110
- get: function get() {
6111
- return Object.keys(this.local.prinrole);
6112
- }
6113
- }]);
6114
-
6115
- return Sharing;
6116
- }();
6117
-
6118
- var ItemModel = /*#__PURE__*/function () {
6119
- function ItemModel(item, url) {
6120
- if (url === void 0) {
6121
- url = '';
6122
- }
6123
-
6124
- this.item = void 0;
6125
- this.url = void 0;
6126
- this.item = item;
6127
- this.url = url;
6128
- }
6129
-
6130
- _createClass(ItemModel, [{
6131
- key: "path",
6132
- get: function get() {
6133
- var item = this.item['@id'] ? this.item['@id'] : this.item['@absolute_url'];
6134
- var path = item.split('//')[1].split('/').splice(1).join('/');
6135
- path = "/" + path + "/";
6136
-
6137
- if (this.url.length > 0) {
6138
- if (this.url.startsWith('/')) {
6139
- path = path.replace(this.url.substring(1), '');
6140
- } else {
6141
- path = path.replace(this.url, '');
6142
- }
6143
- }
6144
-
6145
- return path;
6146
- }
6147
- }, {
6148
- key: "name",
6149
- get: function get() {
6150
- return this.item.title || this.item['@name'];
6151
- }
6152
- }, {
6153
- key: "icon",
6154
- get: function get() {
6155
- var cfg = useConfig();
6156
-
6157
- if (cfg.icons && cfg.icons[this.type]) {
6158
- return cfg.icons[this.type];
6159
- }
6160
-
6161
- switch (this.type) {
6162
- case 'GroupManager':
6163
- return 'fas fa-users-cog';
6164
-
6165
- case 'UserManager':
6166
- return 'fas fa-user-cog';
6167
-
6168
- case 'User':
6169
- return 'fas fa-user';
6170
-
6171
- case 'Group':
6172
- return 'fas fa-users';
6173
-
6174
- case 'Folder':
6175
- return 'fas fa-folder';
6176
-
6177
- default:
6178
- return 'fas fa-file';
6179
- }
6180
- }
6181
- }, {
6182
- key: "fullPath",
6183
- get: function get() {
6184
- return this.url + this.item.id;
6185
- }
6186
- }, {
6187
- key: "id",
6188
- get: function get() {
6189
- if (this.item.id) {
6190
- return this.item.id;
6191
- }
6192
-
6193
- var id = this.item['@id'].split('&')[0].split('/');
6194
- return id[id.length - 1];
6195
- }
6196
- }, {
6197
- key: "uid",
6198
- get: function get() {
6199
- return this.item['@uid'];
6200
- }
6201
- }, {
6202
- key: "type",
6203
- get: function get() {
6204
- return this.item['@type'] || this.item.type_name;
6205
- }
6206
- }, {
6207
- key: "title",
6208
- get: function get() {
6209
- return this.item.title;
6210
- }
6211
- }, {
6212
- key: "created",
6213
- get: function get() {
6214
- return this.item.creation_date ? formatDate(this.item.creation_date) : '';
6215
- }
6216
- }, {
6217
- key: "updated",
6218
- get: function get() {
6219
- return this.item.modification_date ? formatDate(this.item.modification_date) : '';
6220
- }
6221
- }]);
6222
-
6223
- return ItemModel;
6224
- }();
6225
-
6226
6318
  var messages$1 = reactIntl.defineMessages({
6227
6319
  status_changed_ok: {
6228
6320
  id: "status_changed_ok",
@@ -6298,13 +6390,12 @@ function IWorkflow() {
6298
6390
  definition = _useState[0],
6299
6391
  setDefinition = _useState[1];
6300
6392
 
6301
- var _useState2 = React.useState(null),
6393
+ var _useState2 = React.useState(undefined),
6302
6394
  workflowAction = _useState2[0],
6303
6395
  setWorkflowAction = _useState2[1];
6304
6396
 
6305
- var model = new ItemModel(Ctx.context);
6306
6397
  var vocabulary = useVocabulary('workflow_states');
6307
- var currentState = model.item['guillotina.contrib.workflows.interfaces.IWorkflowBehavior']['review_state'];
6398
+ var currentState = Ctx.context['guillotina.contrib.workflows.interfaces.IWorkflowBehavior']['review_state'];
6308
6399
  React.useEffect(function () {
6309
6400
  loadDefinition();
6310
6401
  }, [Ctx.path]);
@@ -6324,7 +6415,7 @@ function IWorkflow() {
6324
6415
  }
6325
6416
 
6326
6417
  Ctx.refresh();
6327
- setWorkflowAction(null);
6418
+ setWorkflowAction(undefined);
6328
6419
  });
6329
6420
  });
6330
6421
  } catch (e) {
@@ -6333,21 +6424,23 @@ function IWorkflow() {
6333
6424
  };
6334
6425
 
6335
6426
  var getStateTitle = function getStateTitle() {
6336
- var _vocabulary$data, _vocabulary$data$item;
6427
+ var _vocabulary$data$item, _vocabulary$data;
6337
6428
 
6338
- if (((_vocabulary$data = vocabulary.data) == null ? void 0 : (_vocabulary$data$item = _vocabulary$data.items) == null ? void 0 : _vocabulary$data$item.length) > 0) {
6339
- var vocabularyValue = vocabulary.data.items.find(function (item) {
6429
+ if (((_vocabulary$data$item = (_vocabulary$data = vocabulary.data) == null ? void 0 : _vocabulary$data.items) != null ? _vocabulary$data$item : []).length > 0) {
6430
+ var _vocabulary$data2;
6431
+
6432
+ var vocabularyValue = vocabulary == null ? void 0 : (_vocabulary$data2 = vocabulary.data) == null ? void 0 : _vocabulary$data2.items.find(function (item) {
6340
6433
  return item.token === currentState;
6341
6434
  });
6342
6435
 
6343
6436
  if (vocabularyValue) {
6344
- var translatedValue = get$1(vocabularyValue, "title.translated_title." + intl.locale, null);
6437
+ var translatedValue = get(vocabularyValue, "title.translated_title." + intl.locale, null);
6345
6438
 
6346
6439
  if (translatedValue !== null) {
6347
6440
  return translatedValue;
6348
6441
  }
6349
6442
 
6350
- var titleValue = get$1(vocabularyValue, "title.title." + intl.locale, null);
6443
+ var titleValue = get(vocabularyValue, "title.title." + intl.locale, null);
6351
6444
 
6352
6445
  if (titleValue !== null) {
6353
6446
  return titleValue;
@@ -6363,7 +6456,7 @@ function IWorkflow() {
6363
6456
  children: [workflowAction && jsxRuntime.jsx(Confirm, {
6364
6457
  loading: loading,
6365
6458
  onCancel: function onCancel() {
6366
- return setWorkflowAction(null);
6459
+ return setWorkflowAction(undefined);
6367
6460
  },
6368
6461
  onConfirm: doWorkflowAction,
6369
6462
  message: intl.formatMessage(messages$1.confirm_message, {
@@ -6389,7 +6482,7 @@ function IWorkflow() {
6389
6482
  onClick: function onClick() {
6390
6483
  return setWorkflowAction(transition['@id'].split('@workflow')[1].slice(1));
6391
6484
  },
6392
- children: get$1(transition, "metadata.translated_title." + intl.locale, transition.title)
6485
+ children: get(transition, "metadata.translated_title." + intl.locale, transition.title)
6393
6486
  }, transition['@id']);
6394
6487
  })]
6395
6488
  })]
@@ -6415,14 +6508,17 @@ function PanelActions() {
6415
6508
 
6416
6509
  return jsxRuntime.jsx(React.Fragment, {
6417
6510
  children: Object.keys(ACTIONS_OBJECT).map(function (actionKey) {
6418
- if (hasPerm(ACTIONS_OBJECT[actionKey].perms)) {
6511
+ var actionKeyTyped = actionKey;
6512
+ var actionObject = ACTIONS_OBJECT[actionKeyTyped];
6513
+
6514
+ if (hasPerm(actionObject.perms)) {
6419
6515
  return jsxRuntime.jsx("button", {
6420
6516
  className: "button mr-4",
6421
6517
  onClick: function onClick() {
6422
- onAction(actionKey);
6518
+ onAction(actionKeyTyped);
6423
6519
  },
6424
- children: ACTIONS_OBJECT[actionKey].text
6425
- }, "panel_action_" + ACTIONS_OBJECT[actionKey].text);
6520
+ children: actionObject.text
6521
+ }, "panel_action_" + actionObject.text);
6426
6522
  }
6427
6523
  })
6428
6524
  });
@@ -6464,7 +6560,8 @@ var messages$2 = reactIntl.defineMessages({
6464
6560
  "value": "Installed Addons"
6465
6561
  }]
6466
6562
  }
6467
- });
6563
+ }); // TODO: Refactor without useAsync... just crudContext
6564
+
6468
6565
  function PanelAddons() {
6469
6566
  var _state$data$available, _state$data, _state$data$available2, _state$data2, _state$data$installed, _state$data3, _state$data$installed2, _state$data4;
6470
6567
 
@@ -6619,8 +6716,9 @@ var prepareData = function prepareData(result) {
6619
6716
 
6620
6717
  var arrayToObject = function arrayToObject(array) {
6621
6718
  return array.reduce(function (obj, item) {
6622
- obj[item.id] = item;
6623
- return obj;
6719
+ var _extends2;
6720
+
6721
+ return _extends({}, obj, (_extends2 = {}, _extends2[item.id] = item, _extends2));
6624
6722
  }, {});
6625
6723
  };
6626
6724
 
@@ -6782,8 +6880,9 @@ function ItemsActionsProvider(_ref) {
6782
6880
 
6783
6881
  function onSelectAllItems(checked) {
6784
6882
  setSelected(items.reduce(function (obj, item) {
6785
- obj[item.path + "/" + item.id] = checked;
6786
- return obj;
6883
+ var _extends2;
6884
+
6885
+ return _extends({}, obj, (_extends2 = {}, _extends2[item.path + "/" + item.id] = checked, _extends2));
6787
6886
  }, {
6788
6887
  all: checked
6789
6888
  }));
@@ -6791,11 +6890,11 @@ function ItemsActionsProvider(_ref) {
6791
6890
 
6792
6891
  function onSelectOneItem(item) {
6793
6892
  setSelected(function (state) {
6794
- var _extends2;
6893
+ var _extends3;
6795
6894
 
6796
- return _extends({}, state, (_extends2 = {
6895
+ return _extends({}, state, (_extends3 = {
6797
6896
  all: false
6798
- }, _extends2[item.path + "/" + item.id] = !state[item.path + "/" + item.id], _extends2));
6897
+ }, _extends3[item.path + "/" + item.id] = !state[item.path + "/" + item.id], _extends3));
6799
6898
  });
6800
6899
  }
6801
6900
 
@@ -6817,13 +6916,38 @@ function ItemsActionsProvider(_ref) {
6817
6916
  children: children
6818
6917
  });
6819
6918
  }
6820
- function AllItemsCheckbox(_ref2) {
6821
- var dataTest = _ref2.dataTest;
6822
6919
 
6920
+ var useItemsActions = function useItemsActions() {
6823
6921
  var _useContext = React.useContext(ItemsActionsCtx),
6922
+ onAction = _useContext.onAction,
6923
+ onSelectOneItem = _useContext.onSelectOneItem,
6824
6924
  onSelectAllItems = _useContext.onSelectAllItems,
6825
6925
  selected = _useContext.selected;
6826
6926
 
6927
+ if (!onAction || !onSelectOneItem || !onSelectAllItems || !selected) {
6928
+ throw new Error('useItemsActions must be used inside ItemsActionsProvider');
6929
+ }
6930
+
6931
+ return {
6932
+ onAction: onAction,
6933
+ onSelectOneItem: onSelectOneItem,
6934
+ onSelectAllItems: onSelectAllItems,
6935
+ selected: selected
6936
+ };
6937
+ };
6938
+ /**
6939
+ * Checkbox component without props that consume the ItemsActionsContext
6940
+ * and it select/unselect all items of the page.
6941
+ */
6942
+
6943
+
6944
+ function AllItemsCheckbox(_ref2) {
6945
+ var dataTest = _ref2.dataTest;
6946
+
6947
+ var _useItemsActions = useItemsActions(),
6948
+ onSelectAllItems = _useItemsActions.onSelectAllItems,
6949
+ selected = _useItemsActions.selected;
6950
+
6827
6951
  return jsxRuntime.jsx(Checkbox, {
6828
6952
  onChange: onSelectAllItems,
6829
6953
  checked: selected.all,
@@ -6834,9 +6958,9 @@ function ItemCheckbox(_ref3) {
6834
6958
  var item = _ref3.item,
6835
6959
  dataTest = _ref3.dataTest;
6836
6960
 
6837
- var _useContext2 = React.useContext(ItemsActionsCtx),
6838
- selected = _useContext2.selected,
6839
- onSelectOneItem = _useContext2.onSelectOneItem;
6961
+ var _useItemsActions2 = useItemsActions(),
6962
+ selected = _useItemsActions2.selected,
6963
+ onSelectOneItem = _useItemsActions2.onSelectOneItem;
6840
6964
 
6841
6965
  var absId = item.path + "/" + item.id;
6842
6966
  var value = selected[absId];
@@ -6848,14 +6972,18 @@ function ItemCheckbox(_ref3) {
6848
6972
  dataTest: dataTest
6849
6973
  });
6850
6974
  }
6975
+ /**
6976
+ * Dropdown to choose some action to apply to the selected items.
6977
+ */
6978
+
6851
6979
  function ItemsActionsDropdown() {
6852
6980
  var intl = reactIntl.useIntl();
6853
6981
  var ACTIONS_OBJECT = getActionsObject(intl, true);
6854
6982
  var traversal = useTraversal();
6855
6983
 
6856
- var _useContext3 = React.useContext(ItemsActionsCtx),
6857
- selected = _useContext3.selected,
6858
- onAction = _useContext3.onAction;
6984
+ var _useItemsActions3 = useItemsActions(),
6985
+ selected = _useItemsActions3.selected,
6986
+ onAction = _useItemsActions3.onAction;
6859
6987
 
6860
6988
  var disabled = Object.values(selected).every(function (v) {
6861
6989
  return !v;
@@ -6939,6 +7067,7 @@ function Pagination(_ref) {
6939
7067
  "aria-label": "pagination",
6940
7068
  children: [jsxRuntime.jsx("a", {
6941
7069
  className: "pagination-previous is-small",
7070
+ // disabled={current === 0}
6942
7071
  onClick: function onClick() {
6943
7072
  return current > 0 ? doPaginate(current - 1) : null;
6944
7073
  },
@@ -6950,6 +7079,7 @@ function Pagination(_ref) {
6950
7079
  })
6951
7080
  }), jsxRuntime.jsx("a", {
6952
7081
  className: "pagination-next is-small",
7082
+ // disabled={current >= maxPages - 1}
6953
7083
  onClick: function onClick() {
6954
7084
  return doPaginate(current + 1);
6955
7085
  },
@@ -6964,6 +7094,170 @@ function Pagination(_ref) {
6964
7094
  });
6965
7095
  }
6966
7096
 
7097
+ var base = {
7098
+ local: {
7099
+ roleperm: {},
7100
+ prinperm: {},
7101
+ prinrole: {}
7102
+ },
7103
+ inherit: []
7104
+ };
7105
+ var Sharing = /*#__PURE__*/function () {
7106
+ function Sharing(element) {
7107
+ this.local = void 0;
7108
+ this.inherit = void 0;
7109
+
7110
+ if (element === undefined) {
7111
+ throw new Error('Sharing element is undefined');
7112
+ }
7113
+
7114
+ this.local = element.local || base.local;
7115
+ this.inherit = element.inherit || base.inherit;
7116
+ }
7117
+
7118
+ var _proto = Sharing.prototype;
7119
+
7120
+ _proto.getRole = function getRole(role) {
7121
+ return this.local.roleperm[role];
7122
+ };
7123
+
7124
+ _proto.getPrincipals = function getPrincipals(principal) {
7125
+ return this.local.prinperm[principal];
7126
+ };
7127
+
7128
+ _proto.getPrinroles = function getPrinroles(role) {
7129
+ return this.local.prinrole[role];
7130
+ };
7131
+
7132
+ _createClass(Sharing, [{
7133
+ key: "roles",
7134
+ get: function get() {
7135
+ return Object.keys(this.local.roleperm);
7136
+ }
7137
+ }, {
7138
+ key: "principals",
7139
+ get: function get() {
7140
+ return Object.keys(this.local.prinperm);
7141
+ }
7142
+ }, {
7143
+ key: "prinrole",
7144
+ get: function get() {
7145
+ return Object.keys(this.local.prinrole);
7146
+ }
7147
+ }]);
7148
+
7149
+ return Sharing;
7150
+ }();
7151
+
7152
+ var ItemModel = /*#__PURE__*/function () {
7153
+ function ItemModel(item, url) {
7154
+ if (url === void 0) {
7155
+ url = '';
7156
+ }
7157
+
7158
+ this.item = void 0;
7159
+ this.url = void 0;
7160
+ this.item = item;
7161
+ this.url = url;
7162
+ }
7163
+
7164
+ _createClass(ItemModel, [{
7165
+ key: "path",
7166
+ get: function get() {
7167
+ // Compat
7168
+ var item = this.item['@id'] ? this.item['@id'] : this.item['@absolute_url'];
7169
+ var path = item.split('//')[1].split('/').splice(1).join('/');
7170
+ path = "/" + path + "/";
7171
+
7172
+ if (this.url.length > 0) {
7173
+ if (this.url.startsWith('/')) {
7174
+ path = path.replace(this.url.substring(1), '');
7175
+ } else {
7176
+ path = path.replace(this.url, '');
7177
+ }
7178
+ }
7179
+
7180
+ return path;
7181
+ }
7182
+ }, {
7183
+ key: "name",
7184
+ get: function get() {
7185
+ return this.item.title || this.item['@name'];
7186
+ }
7187
+ }, {
7188
+ key: "icon",
7189
+ get: function get() {
7190
+ var cfg = useConfig();
7191
+
7192
+ if (cfg.icons && cfg.icons[this.type]) {
7193
+ return cfg.icons[this.type];
7194
+ }
7195
+
7196
+ switch (this.type) {
7197
+ case 'GroupManager':
7198
+ return 'fas fa-users-cog';
7199
+
7200
+ case 'UserManager':
7201
+ return 'fas fa-user-cog';
7202
+
7203
+ case 'User':
7204
+ return 'fas fa-user';
7205
+
7206
+ case 'Group':
7207
+ return 'fas fa-users';
7208
+
7209
+ case 'Folder':
7210
+ return 'fas fa-folder';
7211
+
7212
+ default:
7213
+ return 'fas fa-file';
7214
+ }
7215
+ }
7216
+ }, {
7217
+ key: "fullPath",
7218
+ get: function get() {
7219
+ return this.url + this.id;
7220
+ }
7221
+ }, {
7222
+ key: "id",
7223
+ get: function get() {
7224
+ if ('id' in this.item) {
7225
+ return this.item.id;
7226
+ }
7227
+
7228
+ var id = this.item['@id'].split('&')[0].split('/');
7229
+ return id[id.length - 1];
7230
+ }
7231
+ }, {
7232
+ key: "uid",
7233
+ get: function get() {
7234
+ return this.item['@uid'];
7235
+ }
7236
+ }, {
7237
+ key: "type",
7238
+ get: function get() {
7239
+ return this.item['@type'] || this.item.type_name;
7240
+ }
7241
+ }, {
7242
+ key: "title",
7243
+ get: function get() {
7244
+ return this.item.title;
7245
+ }
7246
+ }, {
7247
+ key: "created",
7248
+ get: function get() {
7249
+ return this.item.creation_date ? formatDate(this.item.creation_date) : '';
7250
+ }
7251
+ }, {
7252
+ key: "updated",
7253
+ get: function get() {
7254
+ return this.item.modification_date ? formatDate(this.item.modification_date) : '';
7255
+ }
7256
+ }]);
7257
+
7258
+ return ItemModel;
7259
+ }();
7260
+
6967
7261
  function Item(_ref) {
6968
7262
  var item = _ref.item,
6969
7263
  icon = _ref.icon;
@@ -7104,11 +7398,11 @@ function SearchOptionsLabels(_ref) {
7104
7398
  renderValue = _useState[0],
7105
7399
  setRenderValue = _useState[1];
7106
7400
 
7107
- var defaultRenderValue = location.get(query);
7401
+ var defaultRenderValue = location.get(query) || '';
7108
7402
  React.useEffect(function () {
7109
7403
  var value = defaultRenderValue;
7110
7404
 
7111
- if ((options != null ? options : []).length > 0) {
7405
+ if (options && (options != null ? options : []).length > 0) {
7112
7406
  var option = options.find(function (item) {
7113
7407
  return item.value === value;
7114
7408
  });
@@ -7157,14 +7451,16 @@ function SearchVocabularyLabels(_ref) {
7157
7451
  setRenderValue = _useState[1];
7158
7452
 
7159
7453
  var vocabulary = useVocabulary(vocabularyName);
7160
- var defaultRenderValue = location.get(query);
7454
+ var defaultRenderValue = location.get(query) || '';
7161
7455
  React.useEffect(function () {
7162
7456
  var _vocabulary$data$item, _vocabulary$data;
7163
7457
 
7164
7458
  var value = defaultRenderValue;
7165
7459
 
7166
7460
  if (((_vocabulary$data$item = vocabulary == null ? void 0 : (_vocabulary$data = vocabulary.data) == null ? void 0 : _vocabulary$data.items) != null ? _vocabulary$data$item : []).length > 0) {
7167
- var vocabularyValue = vocabulary.data.items.find(function (item) {
7461
+ var _vocabulary$data2;
7462
+
7463
+ var vocabularyValue = vocabulary == null ? void 0 : (_vocabulary$data2 = vocabulary.data) == null ? void 0 : _vocabulary$data2.items.find(function (item) {
7168
7464
  return item.token === value;
7169
7465
  });
7170
7466
 
@@ -7198,7 +7494,7 @@ function SearchVocabularyLabels(_ref) {
7198
7494
  return null;
7199
7495
  }
7200
7496
 
7201
- var initialState$2 = {
7497
+ var initialState$3 = {
7202
7498
  page: 0,
7203
7499
  items: [],
7204
7500
  loading: true,
@@ -7217,7 +7513,7 @@ function PanelItems() {
7217
7513
  var intl = reactIntl.useIntl();
7218
7514
  var Ctx = useTraversal();
7219
7515
 
7220
- var _useSetState = useSetState(initialState$2),
7516
+ var _useSetState = useSetState(initialState$3),
7221
7517
  state = _useSetState[0],
7222
7518
  setState = _useSetState[1];
7223
7519
 
@@ -7233,7 +7529,7 @@ function PanelItems() {
7233
7529
  var page;
7234
7530
 
7235
7531
  try {
7236
- page = parseInt(location.get('page')) || 0;
7532
+ page = parseInt(location.get('page') || '0');
7237
7533
  } catch (_unused) {
7238
7534
  page = 0;
7239
7535
  }
@@ -7280,7 +7576,7 @@ function PanelItems() {
7280
7576
  var resultQueryParams = [];
7281
7577
  var resultDynamicLocation = [];
7282
7578
  filterSchema.forEach(function (filter) {
7283
- var itemParam = location.get(filter.attribute_key);
7579
+ var itemParam = location.get(filter.attribute_key) || '';
7284
7580
  resultDynamicLocation.push(itemParam);
7285
7581
 
7286
7582
  if (itemParam) {
@@ -7292,53 +7588,51 @@ function PanelItems() {
7292
7588
  var controller = new AbortController();
7293
7589
  if (Ctx.state.loading) return;
7294
7590
 
7295
- try {
7296
- setState({
7297
- loading: true,
7298
- total: Ctx.context.length
7299
- });
7300
- var get = Ctx.registry.get;
7301
- var fnName = get('searchEngineQueryParamsFunction', SearchEngine);
7302
-
7303
- if (sortParsed === undefined) {
7304
- var defaultSortValue = Ctx.registry.getDefaultSortValue(Ctx.context['@type'], {
7305
- key: 'id',
7306
- direction: 'des'
7591
+ var getData = function getData() {
7592
+ try {
7593
+ setState({
7594
+ loading: true,
7595
+ total: Ctx.context.length
7307
7596
  });
7308
- sortParsed = parser("_sort_" + defaultSortValue.direction + "=" + defaultSortValue.key);
7309
- }
7597
+ var get = Ctx.registry.get;
7598
+ var fnName = get('searchEngineQueryParamsFunction', SearchEngine);
7310
7599
 
7311
- var qsParsed = Ctx.client[fnName]({
7312
- path: Ctx.path,
7313
- start: page * PageSize,
7314
- pageSize: PageSize
7315
- });
7316
- var qs = '';
7600
+ if (sortParsed === undefined) {
7601
+ var defaultSortValue = Ctx.registry.getDefaultSortValue(Ctx.context['@type']);
7602
+ sortParsed = parser("_sort_" + defaultSortValue.direction + "=" + defaultSortValue.key);
7603
+ }
7317
7604
 
7318
- if (search || type || resultQueryParams.length > 0) {
7319
- var _searchParsed, _typeParsed, _sortParsed;
7605
+ var qsParsed = Ctx.client.getQueryParamsSearchFunction(fnName)({
7606
+ path: Ctx.path,
7607
+ start: page * PageSize,
7608
+ pageSize: PageSize
7609
+ });
7610
+ var qs = '';
7320
7611
 
7321
- qs = buildQs([].concat(qsParsed, (_searchParsed = searchParsed) != null ? _searchParsed : [], (_typeParsed = typeParsed) != null ? _typeParsed : [], (_sortParsed = sortParsed) != null ? _sortParsed : [], resultQueryParams));
7322
- } else {
7323
- var _sortParsed2;
7612
+ if (search || type || resultQueryParams.length > 0) {
7613
+ var _searchParsed, _typeParsed, _sortParsed;
7324
7614
 
7325
- qs = buildQs([].concat(qsParsed, (_sortParsed2 = sortParsed) != null ? _sortParsed2 : []));
7326
- }
7615
+ qs = buildQs([].concat(qsParsed, (_searchParsed = searchParsed) != null ? _searchParsed : [], (_typeParsed = typeParsed) != null ? _typeParsed : [], (_sortParsed = sortParsed) != null ? _sortParsed : [], resultQueryParams));
7616
+ } else {
7617
+ var _sortParsed2;
7327
7618
 
7328
- var signal = controller.signal;
7329
- return Promise.resolve(Ctx.client.search(Ctx.path, qs, false, false, {
7330
- signal: signal
7331
- })).then(function (data) {
7332
- setState({
7333
- items: data.member,
7334
- loading: false,
7335
- total: data.items_count
7619
+ qs = buildQs([].concat(qsParsed, (_sortParsed2 = sortParsed) != null ? _sortParsed2 : []));
7620
+ }
7621
+
7622
+ var signal = controller.signal;
7623
+ return Promise.resolve(Ctx.client.search(Ctx.path, qs, false, false, signal)).then(function (data) {
7624
+ setState({
7625
+ items: data.items,
7626
+ loading: false,
7627
+ total: data.items_count
7628
+ });
7336
7629
  });
7337
- });
7338
- } catch (e) {
7339
- Promise.reject(e);
7340
- }
7630
+ } catch (e) {
7631
+ return Promise.reject(e);
7632
+ }
7633
+ };
7341
7634
 
7635
+ getData();
7342
7636
  return function () {
7343
7637
  controller.abort();
7344
7638
  };
@@ -7383,12 +7677,14 @@ function PanelItems() {
7383
7677
  var _filter$values;
7384
7678
 
7385
7679
  if (filter.type === 'select' && ((_filter$values = filter.values) != null ? _filter$values : []).length > 0) {
7680
+ var _filter$values2;
7681
+
7386
7682
  return jsxRuntime.jsx(Select, {
7387
7683
  id: filter.attribute_key,
7388
7684
  placeholder: filter.label,
7389
7685
  appendDefault: true,
7390
7686
  classWrap: "is-size-7 is-fullwidth",
7391
- options: filter.values,
7687
+ options: (_filter$values2 = filter.values) != null ? _filter$values2 : [],
7392
7688
  value: location.get(filter.attribute_key) || '',
7393
7689
  dataTest: "filterInput" + filter.attribute_key,
7394
7690
  onChange: function onChange(value) {
@@ -7455,7 +7751,7 @@ function PanelItems() {
7455
7751
  var filterData = location.get(filter.attribute_key);
7456
7752
 
7457
7753
  if (filterData) {
7458
- var _filter$values2;
7754
+ var _filter$values3;
7459
7755
 
7460
7756
  if (filter.type === 'select' && filter.vocabulary) {
7461
7757
  return jsxRuntime.jsx("div", {
@@ -7464,7 +7760,7 @@ function PanelItems() {
7464
7760
  vocabularyName: filter == null ? void 0 : filter.vocabulary
7465
7761
  })
7466
7762
  }, filter.attribute_key);
7467
- } else if (filter.type === 'select' && ((_filter$values2 = filter.values) != null ? _filter$values2 : []).length > 0) {
7763
+ } else if (filter.type === 'select' && ((_filter$values3 = filter.values) != null ? _filter$values3 : []).length > 0) {
7468
7764
  return jsxRuntime.jsx("div", {
7469
7765
  children: jsxRuntime.jsx(SearchOptionsLabels, {
7470
7766
  query: filter.attribute_key,
@@ -7510,7 +7806,7 @@ function PanelItems() {
7510
7806
  className: "has-text-info is-flex is-align-items-center",
7511
7807
  children: [jsxRuntime.jsx("span", {
7512
7808
  children: column.label
7513
- }), getIcon(column.key, column.isSortable)]
7809
+ }), getIcon(column.key, !!column.isSortable)]
7514
7810
  })
7515
7811
  }, "table-col-" + column.label);
7516
7812
  }), jsxRuntime.jsx("th", {
@@ -7521,7 +7817,7 @@ function PanelItems() {
7521
7817
  children: [items && items.map(function (item) {
7522
7818
  return jsxRuntime.jsx(RItem, {
7523
7819
  item: item,
7524
- search: search,
7820
+ search: search != null ? search : '',
7525
7821
  columns: columns
7526
7822
  }, item['@uid']);
7527
7823
  }), items && items.length === 0 && jsxRuntime.jsx("tr", {
@@ -7545,17 +7841,19 @@ function PanelItems() {
7545
7841
  }
7546
7842
 
7547
7843
  function BehaviorsView(_ref) {
7844
+ var _context$__behaviors_;
7845
+
7548
7846
  var context = _ref.context,
7549
7847
  schema = _ref.schema;
7550
7848
  var Ctx = useTraversal();
7551
7849
  var getBehavior = Ctx.registry.getBehavior;
7552
- var behaviors = [].concat(context.__behaviors__, context['@static_behaviors']);
7850
+ var behaviors = [].concat((_context$__behaviors_ = context.__behaviors__) != null ? _context$__behaviors_ : [], Object(context['@static_behaviors']));
7553
7851
 
7554
- var GetBehavior = function GetBehavior(b) {
7555
- var Cls = getBehavior(b, BehaviorNotImplemented);
7852
+ var GetBehavior = function GetBehavior(behaviorName) {
7853
+ var Cls = getBehavior(behaviorName, BehaviorNotImplemented);
7556
7854
  return jsxRuntime.jsx(Cls, {
7557
- values: context[b],
7558
- properties: get$1(schema, ['definitions', b, 'properties'], {})
7855
+ values: context[behaviorName],
7856
+ properties: get(schema, ['definitions', behaviorName, 'properties'], {})
7559
7857
  });
7560
7858
  };
7561
7859
 
@@ -7651,9 +7949,11 @@ function PanelProperties() {
7651
7949
  var properties = Object.keys((schema == null ? void 0 : (_schema$data = schema.data) == null ? void 0 : _schema$data.properties) || []).filter(function (key) {
7652
7950
  return !ignoreFields.includes(key);
7653
7951
  }).map(function (key) {
7952
+ var _schema$data2;
7953
+
7654
7954
  return {
7655
7955
  key: key,
7656
- value: schema.data.properties[key]
7956
+ value: schema == null ? void 0 : (_schema$data2 = schema.data) == null ? void 0 : _schema$data2.properties[key]
7657
7957
  };
7658
7958
  });
7659
7959
  React.useEffect(function () {
@@ -7665,7 +7965,7 @@ function PanelProperties() {
7665
7965
  setSchema({
7666
7966
  loading: true
7667
7967
  });
7668
- return Promise.resolve(Ctx.client.getTypeSchema(Ctx.path, model.type)).then(function (dataJson) {
7968
+ return Promise.resolve(Ctx.client.getTypeSchema(Ctx.path, Ctx.context.type_name)).then(function (dataJson) {
7669
7969
  setSchema({
7670
7970
  loading: false,
7671
7971
  data: dataJson
@@ -7740,7 +8040,7 @@ function PanelProperties() {
7740
8040
  }), jsxRuntime.jsx("td", {
7741
8041
  children: jsxRuntime.jsx(EditableField, {
7742
8042
  field: prop,
7743
- value: Ctx.context[prop],
8043
+ value: get(Ctx.context, prop, ''),
7744
8044
  modifyContent: false
7745
8045
  })
7746
8046
  })]
@@ -7764,7 +8064,7 @@ function PanelProperties() {
7764
8064
  })
7765
8065
  }), jsxRuntime.jsx("tbody", {
7766
8066
  children: properties.map(function (_ref) {
7767
- var _schema$data$required, _schema$data2;
8067
+ var _schema$data$required, _schema$data3;
7768
8068
 
7769
8069
  var key = _ref.key,
7770
8070
  value = _ref.value;
@@ -7777,10 +8077,10 @@ function PanelProperties() {
7777
8077
  }), jsxRuntime.jsx("td", {
7778
8078
  children: jsxRuntime.jsx(EditableField, {
7779
8079
  field: key,
7780
- value: Ctx.context[key],
8080
+ value: get(Ctx.context, key, ''),
7781
8081
  schema: value,
7782
8082
  modifyContent: modifyContent,
7783
- required: ((_schema$data$required = (_schema$data2 = schema.data) == null ? void 0 : _schema$data2.required) != null ? _schema$data$required : []).includes(key)
8083
+ required: ((_schema$data$required = (_schema$data3 = schema.data) == null ? void 0 : _schema$data3.required) != null ? _schema$data$required : []).includes(key)
7784
8084
  })
7785
8085
  })]
7786
8086
  }, 'prop' + key);
@@ -7816,14 +8116,6 @@ function PermissionPrinperm(_ref) {
7816
8116
  state = _useSetState[0],
7817
8117
  setState = _useSetState[1];
7818
8118
 
7819
- var getMultiples = function getMultiples(field, setter) {
7820
- return function (values) {
7821
- var _setter;
7822
-
7823
- setter((_setter = {}, _setter[field] = values, _setter));
7824
- };
7825
- };
7826
-
7827
8119
  var savePermission = function savePermission() {
7828
8120
  try {
7829
8121
  if (!state.principal || !state.setting || state.permission.length === 0) {
@@ -7873,7 +8165,7 @@ function PermissionPrinperm(_ref) {
7873
8165
  children: intl.formatMessage(genericMessages.select_principal)
7874
8166
  }), jsxRuntime.jsx(Select, {
7875
8167
  appendDefault: true,
7876
- options: principals,
8168
+ options: principals != null ? principals : [],
7877
8169
  onChange: function onChange(value) {
7878
8170
  return setState({
7879
8171
  principal: value
@@ -7887,8 +8179,12 @@ function PermissionPrinperm(_ref) {
7887
8179
  className: "label",
7888
8180
  children: intl.formatMessage(genericMessages.select_permissions)
7889
8181
  }), jsxRuntime.jsx(Select, {
7890
- options: permissions,
7891
- onChange: getMultiples('permission', setState),
8182
+ options: permissions != null ? permissions : [],
8183
+ onChange: function onChange(values) {
8184
+ setState({
8185
+ permission: values
8186
+ });
8187
+ },
7892
8188
  size: 5,
7893
8189
  multiple: true,
7894
8190
  dataTest: "selectPermissionsTest"
@@ -7939,14 +8235,6 @@ function PermissionPrinrole(_ref) {
7939
8235
  state = _useSetState[0],
7940
8236
  setState = _useSetState[1];
7941
8237
 
7942
- var getMultiples = function getMultiples(field, setter) {
7943
- return function (values) {
7944
- var _setter;
7945
-
7946
- setter((_setter = {}, _setter[field] = values, _setter));
7947
- };
7948
- };
7949
-
7950
8238
  var savePermission = function savePermission() {
7951
8239
  try {
7952
8240
  if (!state.principal || !state.setting || state.roles.length === 0) {
@@ -7996,7 +8284,7 @@ function PermissionPrinrole(_ref) {
7996
8284
  children: intl.formatMessage(genericMessages.select_principal)
7997
8285
  }), jsxRuntime.jsx(Select, {
7998
8286
  appendDefault: true,
7999
- options: principals,
8287
+ options: principals != null ? principals : [],
8000
8288
  onChange: function onChange(value) {
8001
8289
  return setState({
8002
8290
  principal: value
@@ -8011,7 +8299,11 @@ function PermissionPrinrole(_ref) {
8011
8299
  children: intl.formatMessage(genericMessages.select_role)
8012
8300
  }), jsxRuntime.jsx(Select, {
8013
8301
  options: roles,
8014
- onChange: getMultiples('roles', setState),
8302
+ onChange: function onChange(values) {
8303
+ setState({
8304
+ roles: values
8305
+ });
8306
+ },
8015
8307
  size: 5,
8016
8308
  multiple: true,
8017
8309
  dataTest: "selectRoleTest"
@@ -8062,14 +8354,6 @@ function PermissionRoleperm(_ref) {
8062
8354
  state = _useSetState[0],
8063
8355
  setState = _useSetState[1];
8064
8356
 
8065
- var getMultiples = function getMultiples(field, setter) {
8066
- return function (values) {
8067
- var _setter;
8068
-
8069
- setter((_setter = {}, _setter[field] = values, _setter));
8070
- };
8071
- };
8072
-
8073
8357
  var savePermission = function savePermission() {
8074
8358
  try {
8075
8359
  if (!state.role || !state.setting || state.permission.length === 0) {
@@ -8133,8 +8417,12 @@ function PermissionRoleperm(_ref) {
8133
8417
  className: "label",
8134
8418
  children: intl.formatMessage(genericMessages.select_permissions)
8135
8419
  }), jsxRuntime.jsx(Select, {
8136
- options: permissions,
8137
- onChange: getMultiples('permission', setState),
8420
+ options: permissions != null ? permissions : [],
8421
+ onChange: function onChange(values) {
8422
+ setState({
8423
+ permission: values
8424
+ });
8425
+ },
8138
8426
  dataTest: "selectPermissionsTest",
8139
8427
  size: 5,
8140
8428
  multiple: true
@@ -8267,7 +8555,18 @@ function PanelPermissions() {
8267
8555
  React.useEffect(function () {
8268
8556
  get('@sharing');
8269
8557
  }, [reset]);
8270
- var perms = new Sharing(result);
8558
+ var perms = React.useMemo(function () {
8559
+ if (result) {
8560
+ return new Sharing(result);
8561
+ }
8562
+
8563
+ return null;
8564
+ }, [result]);
8565
+
8566
+ if (perms === null) {
8567
+ return null;
8568
+ }
8569
+
8271
8570
  return jsxRuntime.jsxs("div", {
8272
8571
  className: "columns",
8273
8572
  children: [!loading && jsxRuntime.jsxs("div", {
@@ -8425,14 +8724,14 @@ function AddPermission(_ref) {
8425
8724
  return Promise.resolve(Ctx.client.getPrincipals(Ctx.path)).then(function (principalsData) {
8426
8725
  var groups = principalsData.groups.map(function (group) {
8427
8726
  return {
8428
- text: group.id,
8429
- value: group.id
8727
+ text: group['@name'],
8728
+ value: group['@name']
8430
8729
  };
8431
8730
  });
8432
8731
  var users = principalsData.users.map(function (user) {
8433
8732
  return {
8434
- text: user.fullname || user.id,
8435
- value: user.id
8733
+ text: user.fullname || user['@name'],
8734
+ value: user['@name']
8436
8735
  };
8437
8736
  });
8438
8737
  principals = [].concat(groups, users);
@@ -8503,18 +8802,6 @@ var prepareAvailable = function prepareAvailable(items, already, title) {
8503
8802
  text: "Add " + title
8504
8803
  };
8505
8804
  if (items.length === 0) return [];
8506
-
8507
- if (items[0] && typeof items[0] === 'string') {
8508
- return [def].concat(items.map(function (x) {
8509
- return {
8510
- value: x,
8511
- text: x
8512
- };
8513
- })).filter(function (item) {
8514
- return !already.includes(item.value);
8515
- });
8516
- }
8517
-
8518
8805
  return [def].concat(items).filter(function (item) {
8519
8806
  return !already.includes(item.value);
8520
8807
  });
@@ -8527,7 +8814,7 @@ function TagsWidget(_ref) {
8527
8814
  noData = _ref.noData,
8528
8815
  onChange = _ref.onChange,
8529
8816
  loading = _ref.loading;
8530
- var selectRef = React.useRef();
8817
+ var selectRef = React.useRef(null);
8531
8818
 
8532
8819
  var _useState = React.useState(items),
8533
8820
  result = _useState[0],
@@ -8575,7 +8862,7 @@ function TagsWidget(_ref) {
8575
8862
  marginBottom: '20px'
8576
8863
  },
8577
8864
  children: noData
8578
- }), available.length > 1 && jsxRuntime.jsx("li", {
8865
+ }), (available != null ? available : []).length > 1 && jsxRuntime.jsx("li", {
8579
8866
  className: "widget-list-add select is-small",
8580
8867
  children: jsxRuntime.jsx(Select, {
8581
8868
  options: availableData,
@@ -8593,13 +8880,13 @@ function TagsWidget(_ref) {
8593
8880
  });
8594
8881
  }
8595
8882
 
8596
- var initialState$3 = {
8597
- types: undefined
8883
+ var initialState$4 = {
8884
+ types: []
8598
8885
  };
8599
8886
  function CreateButton() {
8600
8887
  var intl = reactIntl.useIntl();
8601
8888
 
8602
- var _useSetState = useSetState(initialState$3),
8889
+ var _useSetState = useSetState(initialState$4),
8603
8890
  state = _useSetState[0],
8604
8891
  setState = _useSetState[1];
8605
8892
 
@@ -8647,7 +8934,8 @@ function CreateButton() {
8647
8934
 
8648
8935
  if (state.types && state.types.length === 0) {
8649
8936
  return null;
8650
- }
8937
+ } // Implement some kind of filtering
8938
+
8651
8939
 
8652
8940
  return jsxRuntime.jsx(Dropdown, {
8653
8941
  id: "dropdown-menu",
@@ -8686,7 +8974,7 @@ function ContextToolbar(_ref) {
8686
8974
  var AddButton = _ref.AddButton;
8687
8975
  var intl = reactIntl.useIntl();
8688
8976
 
8689
- var _useSetState2 = useSetState(initialState$3),
8977
+ var _useSetState2 = useSetState(initialState$4),
8690
8978
  state = _useSetState2[0],
8691
8979
  setState = _useSetState2[1];
8692
8980
 
@@ -8697,7 +8985,7 @@ function ContextToolbar(_ref) {
8697
8985
 
8698
8986
  var traversal = useTraversal();
8699
8987
  var Config = useConfig();
8700
- var searchText = location.get('q');
8988
+ var searchText = location.get('q') || '';
8701
8989
 
8702
8990
  var _useState = React.useState(searchText || ''),
8703
8991
  searchValue = _useState[0],
@@ -8710,14 +8998,13 @@ function ContextToolbar(_ref) {
8710
8998
  setSearchValue(searchText);
8711
8999
  }, [searchText]);
8712
9000
 
8713
- var onSearchQuery = function onSearchQuery(ev) {
8714
- var search = ev.target[0].value;
9001
+ var onSearchQuery = function onSearchQuery(event) {
9002
+ event.preventDefault();
8715
9003
  setLocation({
8716
- q: search,
9004
+ q: event.currentTarget.elements.filterInput.value,
8717
9005
  tab: 'Items',
8718
9006
  page: 0
8719
9007
  });
8720
- ev.preventDefault();
8721
9008
  };
8722
9009
 
8723
9010
  var onSearchByType = function onSearchByType(typeText) {
@@ -8751,7 +9038,8 @@ function ContextToolbar(_ref) {
8751
9038
  type: "text",
8752
9039
  className: "input is-size-7",
8753
9040
  placeholder: intl.formatMessage(genericMessages.search),
8754
- "data-test": "inputFilterTest"
9041
+ "data-test": "inputFilterTest",
9042
+ id: "filterInput"
8755
9043
  })
8756
9044
  }), jsxRuntime.jsx("div", {
8757
9045
  className: "control",
@@ -8778,7 +9066,9 @@ function ContextToolbar(_ref) {
8778
9066
  value: item
8779
9067
  };
8780
9068
  }),
8781
- onChange: onSearchByType
9069
+ onChange: function onChange(value) {
9070
+ return onSearchByType(value);
9071
+ }
8782
9072
  })
8783
9073
  }), traversal.hasPerm('guillotina.AddContent') && jsxRuntime.jsx("div", {
8784
9074
  className: "level-item",
@@ -8819,11 +9109,11 @@ function TabsPanel(_ref2) {
8819
9109
  location = _useLocation[0],
8820
9110
  setLocation = _useLocation[1];
8821
9111
 
8822
- if (location.get('tab')) {
8823
- currentTab = location.get('tab');
8824
- } else {
8825
- currentTab = currentTab || Object.keys(tabs)[0];
8826
- }
9112
+ currentTab = location.get('tab') || Object.keys(tabs)[0];
9113
+ /*if (!Object.keys(tabs).includes(currentTab)) {
9114
+ setLocation(defaultTab)
9115
+ currentTab = defaultTab
9116
+ }*/
8827
9117
 
8828
9118
  var _useState = React.useState(currentTab),
8829
9119
  current = _useState[0],
@@ -8832,7 +9122,7 @@ function TabsPanel(_ref2) {
8832
9122
  var CurrentComp = tabs[current] || fallback;
8833
9123
  React__default['default'].useEffect(function () {
8834
9124
  if (Object.keys(tabs).includes(currentTab)) {
8835
- setTab(currentTab);
9125
+ setTab(currentTab); // setLocation({tab: currentTab})
8836
9126
  }
8837
9127
  }, [currentTab, tabs]);
8838
9128
 
@@ -8891,14 +9181,14 @@ var tabsPermissions = {
8891
9181
  Behaviors: 'guillotina.ModifyContent',
8892
9182
  Permissions: 'guillotina.SeePermissions'
8893
9183
  };
8894
- function FolderCtx(props) {
9184
+ function FolderCtx() {
8895
9185
  var ctx = useTraversal();
8896
9186
  var calculated = ctx.filterTabs(tabs, tabsPermissions);
8897
- return jsxRuntime.jsx(TabsPanel, _extends({
9187
+ return jsxRuntime.jsx(TabsPanel, {
8898
9188
  tabs: calculated,
8899
9189
  currentTab: "Items",
8900
- rightToolbar: jsxRuntime.jsx(ContextToolbar, _extends({}, props))
8901
- }, props));
9190
+ rightToolbar: jsxRuntime.jsx(ContextToolbar, {})
9191
+ });
8902
9192
  }
8903
9193
 
8904
9194
  var tabs$1 = {
@@ -8912,13 +9202,13 @@ var tabsPermissions$1 = {
8912
9202
  Behaviors: 'guillotina.ModifyContent',
8913
9203
  Permissions: 'guillotina.SeePermissions'
8914
9204
  };
8915
- function ItemCtx(props) {
9205
+ function ItemCtx() {
8916
9206
  var ctx = useTraversal();
8917
9207
  var calculated = ctx.filterTabs(tabs$1, tabsPermissions$1);
8918
- return jsxRuntime.jsx(TabsPanel, _extends({
9208
+ return jsxRuntime.jsx(TabsPanel, {
8919
9209
  tabs: calculated,
8920
9210
  currentTab: "Properties"
8921
- }, props));
9211
+ });
8922
9212
  }
8923
9213
 
8924
9214
  function _catch$7(body, recover) {
@@ -8937,8 +9227,9 @@ function _catch$7(body, recover) {
8937
9227
 
8938
9228
  function ApplicationCtx() {
8939
9229
  var intl = reactIntl.useIntl();
8940
- var context = useTraversal();
8941
- var databases = context.state.context.databases;
9230
+ var traversal = useTraversal();
9231
+ var appContext = traversal.state.context;
9232
+ var databases = appContext.databases;
8942
9233
  return jsxRuntime.jsxs(jsxRuntime.Fragment, {
8943
9234
  children: [jsxRuntime.jsx("h3", {
8944
9235
  children: intl.formatMessage({
@@ -8952,22 +9243,26 @@ function ApplicationCtx() {
8952
9243
  className: "container",
8953
9244
  children: [jsxRuntime.jsx(ItemTitle, {
8954
9245
  title: "Objects"
8955
- }), databases.map(function (db) {
8956
- return jsxRuntime.jsx(Item, {
8957
- item: {
8958
- id: db,
8959
- path: "/" + db + "/"
8960
- },
8961
- icon: 'fas fa-database'
8962
- }, db);
9246
+ }), jsxRuntime.jsx("table", {
9247
+ children: jsxRuntime.jsx("tbody", {
9248
+ children: databases.map(function (db) {
9249
+ return jsxRuntime.jsx(Item, {
9250
+ item: {
9251
+ id: db,
9252
+ path: "/" + db + "/"
9253
+ },
9254
+ icon: 'fas fa-database'
9255
+ }, db);
9256
+ })
9257
+ })
8963
9258
  })]
8964
9259
  })]
8965
9260
  });
8966
9261
  }
8967
9262
  function DatabaseCtx() {
8968
- var context = useTraversal();
8969
- var containers = context.state.context.containers;
8970
- var path = context.state.path;
9263
+ var traversal = useTraversal();
9264
+ var containers = traversal.state.context.containers;
9265
+ var path = traversal.state.path;
8971
9266
  return jsxRuntime.jsx(jsxRuntime.Fragment, {
8972
9267
  children: jsxRuntime.jsxs("div", {
8973
9268
  className: "container",
@@ -9255,17 +9550,17 @@ function UsersToolbar() {
9255
9550
 
9256
9551
  var searchText = location.get('q');
9257
9552
 
9258
- var onSearchQuery = function onSearchQuery(ev) {
9259
- var search = ev.target[0].value;
9553
+ var onSearchQuery = function onSearchQuery(event) {
9554
+ event.preventDefault();
9260
9555
  setLocation({
9261
- q: search,
9556
+ q: event.currentTarget.elements.filterInput.value,
9262
9557
  page: 0
9263
9558
  });
9264
- ev.preventDefault();
9265
- };
9559
+ }; // cleanup form on state.search change
9560
+
9266
9561
 
9267
9562
  React.useEffect(function () {
9268
- if (!searchText || searchText === '') {
9563
+ if (ref.current && (!searchText || searchText === '')) {
9269
9564
  ref.current.value = '';
9270
9565
  }
9271
9566
  }, [searchText]);
@@ -9285,7 +9580,8 @@ function UsersToolbar() {
9285
9580
  type: "text",
9286
9581
  className: "input is-size-7",
9287
9582
  placeholder: intl.formatMessage(genericMessages.search),
9288
- "data-test": "inputFilterTest"
9583
+ "data-test": "inputFilterTest",
9584
+ id: "filterInput"
9289
9585
  })
9290
9586
  }), jsxRuntime.jsx("div", {
9291
9587
  className: "control",
@@ -9317,12 +9613,12 @@ function UsersToolbar() {
9317
9613
  })]
9318
9614
  });
9319
9615
  }
9320
- function UsersCtx(props) {
9321
- return jsxRuntime.jsx(TabsPanel, _extends({
9616
+ function UsersCtx() {
9617
+ return jsxRuntime.jsx(TabsPanel, {
9322
9618
  tabs: tabs$3,
9323
9619
  currentTab: "Users",
9324
9620
  rightToolbar: jsxRuntime.jsx(UsersToolbar, {})
9325
- }, props));
9621
+ });
9326
9622
  }
9327
9623
  function UserCtx() {
9328
9624
  var intl = reactIntl.useIntl();
@@ -9339,9 +9635,10 @@ function UserCtx() {
9339
9635
  state = _useState[0],
9340
9636
  setState = _useState[1];
9341
9637
 
9638
+ var userDataContext = Ctx.context;
9342
9639
  var fields = {
9343
9640
  user_groups: [],
9344
- user_roles: Ctx.context.user_roles
9641
+ user_roles: userDataContext.user_roles
9345
9642
  };
9346
9643
 
9347
9644
  var _useRemoteField = useRemoteField(fields),
@@ -9445,7 +9742,7 @@ function UserCtx() {
9445
9742
  "value": "Username"
9446
9743
  }]
9447
9744
  }), ":", ' ']
9448
- }), ' ', Ctx.context.username, " (", Ctx.context.email, ")"]
9745
+ }), ' ', userDataContext.username, " (", userDataContext.email, ")"]
9449
9746
  }), jsxRuntime.jsxs("p", {
9450
9747
  children: [jsxRuntime.jsxs("label", {
9451
9748
  children: [' ', intl.formatMessage({
@@ -9455,7 +9752,7 @@ function UserCtx() {
9455
9752
  "value": "Creation Date"
9456
9753
  }]
9457
9754
  }), ":", ' ']
9458
- }), ' ', formatDate(Ctx.context.creation_date)]
9755
+ }), ' ', formatDate(userDataContext.creation_date)]
9459
9756
  }), jsxRuntime.jsxs("p", {
9460
9757
  children: [jsxRuntime.jsxs("label", {
9461
9758
  children: [' ', intl.formatMessage({
@@ -9465,7 +9762,7 @@ function UserCtx() {
9465
9762
  "value": "Modification Date"
9466
9763
  }]
9467
9764
  }), ":", ' ']
9468
- }), ' ', formatDate(Ctx.context.modification_date)]
9765
+ }), ' ', formatDate(userDataContext.modification_date)]
9469
9766
  }), jsxRuntime.jsx(Button, {
9470
9767
  className: "is-size-7 is-info",
9471
9768
  onClick: function onClick() {
@@ -9484,7 +9781,7 @@ function UserCtx() {
9484
9781
  onSubmit: function onSubmit(ev) {
9485
9782
  return updateObject(ev);
9486
9783
  },
9487
- formData: Ctx.context,
9784
+ formData: userDataContext,
9488
9785
  exclude: ['password'],
9489
9786
  remotes: remotes,
9490
9787
  submitButton: false,
@@ -9498,7 +9795,7 @@ function UserCtx() {
9498
9795
  className: "column",
9499
9796
  children: [jsxRuntime.jsx(TagsWidget, {
9500
9797
  onChange: updateRemote('user_groups'),
9501
- items: Ctx.context.user_groups,
9798
+ items: userDataContext.user_groups,
9502
9799
  title: "Groups",
9503
9800
  noData: intl.formatMessage({
9504
9801
  id: "there_is_no_groups_for_this_user",
@@ -9519,7 +9816,12 @@ function UserCtx() {
9519
9816
  "value": "The user doesn't have any role"
9520
9817
  }]
9521
9818
  }),
9522
- available: state.roles
9819
+ available: state.roles.map(function (x) {
9820
+ return {
9821
+ value: x,
9822
+ text: x
9823
+ };
9824
+ })
9523
9825
  })]
9524
9826
  })]
9525
9827
  })]
@@ -9535,7 +9837,7 @@ function CopyItems(props) {
9535
9837
  try {
9536
9838
  return Promise.resolve(Promise.all(items.map(function (item, i) {
9537
9839
  var input = form[i + 1] || {};
9538
- return Ctx.client.post("" + Ctx.path + item['@name'] + "/@duplicate", {
9840
+ return Ctx.client.post("" + Ctx.path + item.id + "/@duplicate", {
9539
9841
  destination: path,
9540
9842
  new_id: input.value || getNewId(item.id)
9541
9843
  });
@@ -9581,7 +9883,7 @@ function CopyItems(props) {
9581
9883
  }), jsxRuntime.jsx("input", {
9582
9884
  type: "text",
9583
9885
  className: "input",
9584
- "data-test": "inputCopyIdTest-" + item['@name'],
9886
+ "data-test": "inputCopyIdTest-" + item.id,
9585
9887
  defaultValue: getNewId(item.id)
9586
9888
  })]
9587
9889
  }, item.id);
@@ -9654,9 +9956,9 @@ function MoveItems(props) {
9654
9956
  var moveItems = function moveItems(path) {
9655
9957
  try {
9656
9958
  return Promise.resolve(Promise.all(items.map(function (item) {
9657
- return Ctx.client.post("" + Ctx.path + item['@name'] + "/@move", {
9959
+ return Ctx.client.post("" + Ctx.path + item.id + "/@move", {
9658
9960
  destination: path,
9659
- new_id: item['@name']
9961
+ new_id: item.id
9660
9962
  });
9661
9963
  }))).then(function (responses) {
9662
9964
  Ctx.refresh();
@@ -9993,17 +10295,17 @@ function GroupToolbar() {
9993
10295
 
9994
10296
  var searchText = location.get('q');
9995
10297
 
9996
- var onSearchQuery = function onSearchQuery(ev) {
9997
- var search = ev.target[0].value;
10298
+ var onSearchQuery = function onSearchQuery(event) {
10299
+ event.preventDefault();
9998
10300
  setLocation({
9999
- q: search,
10301
+ q: event.currentTarget.elements.filterInput.value,
10000
10302
  page: 0
10001
10303
  });
10002
- ev.preventDefault();
10003
- };
10304
+ }; // cleanup form on state.search change
10305
+
10004
10306
 
10005
10307
  React.useEffect(function () {
10006
- if (!searchText || searchText === '') {
10308
+ if (ref.current && (!searchText || searchText === '')) {
10007
10309
  ref.current.value = '';
10008
10310
  }
10009
10311
  }, [searchText]);
@@ -10023,7 +10325,8 @@ function GroupToolbar() {
10023
10325
  type: "text",
10024
10326
  className: "input is-size-7",
10025
10327
  placeholder: intl.formatMessage(genericMessages.search),
10026
- "data-test": "inputFilterTest"
10328
+ "data-test": "inputFilterTest",
10329
+ id: "filterInput"
10027
10330
  })
10028
10331
  }), jsxRuntime.jsx("div", {
10029
10332
  className: "control",
@@ -10061,12 +10364,12 @@ function GroupToolbar() {
10061
10364
  })]
10062
10365
  });
10063
10366
  }
10064
- function GroupsCtx(props) {
10065
- return jsxRuntime.jsx(TabsPanel, _extends({
10367
+ function GroupsCtx() {
10368
+ return jsxRuntime.jsx(TabsPanel, {
10066
10369
  tabs: tabs$4,
10067
10370
  currentTab: "Groups",
10068
10371
  rightToolbar: jsxRuntime.jsx(GroupToolbar, {})
10069
- }, props));
10372
+ });
10070
10373
  }
10071
10374
  var sortParsed = parser("_sort_asc=id");
10072
10375
  var searchParsed = parser('type_name=User');
@@ -10081,6 +10384,7 @@ function GroupCtx() {
10081
10384
  roles = _useState[0],
10082
10385
  setRoles = _useState[1];
10083
10386
 
10387
+ var groupDataContext = Ctx.context;
10084
10388
  React.useEffect(function () {
10085
10389
  var getRoles = function getRoles() {
10086
10390
  try {
@@ -10134,11 +10438,11 @@ function GroupCtx() {
10134
10438
  var addRole = function addRole(role) {
10135
10439
  try {
10136
10440
  return Promise.resolve(patch({
10137
- user_roles: Ctx.context.user_roles.concat(role)
10441
+ user_roles: groupDataContext.user_roles.concat(role)
10138
10442
  })).then(function (_ref) {
10139
10443
  var isError = _ref.isError,
10140
10444
  errorMessage = _ref.errorMessage;
10141
- handleResponse(isError, intl.formatMessage({
10445
+ handleResponse(!!isError, intl.formatMessage({
10142
10446
  id: "role_added_to_group",
10143
10447
  defaultMessage: [{
10144
10448
  "type": 0,
@@ -10152,7 +10456,7 @@ function GroupCtx() {
10152
10456
  }]
10153
10457
  }, {
10154
10458
  role: role
10155
- }), errorMessage);
10459
+ }), errorMessage != null ? errorMessage : '');
10156
10460
  });
10157
10461
  } catch (e) {
10158
10462
  return Promise.reject(e);
@@ -10162,13 +10466,13 @@ function GroupCtx() {
10162
10466
  var removeRole = function removeRole(role) {
10163
10467
  try {
10164
10468
  return Promise.resolve(patch({
10165
- user_roles: Ctx.context.user_roles.filter(function (r) {
10469
+ user_roles: groupDataContext.user_roles.filter(function (r) {
10166
10470
  return r !== role;
10167
10471
  })
10168
10472
  })).then(function (_ref2) {
10169
10473
  var isError = _ref2.isError,
10170
10474
  errorMessage = _ref2.errorMessage;
10171
- handleResponse(isError, intl.formatMessage({
10475
+ handleResponse(!!isError, intl.formatMessage({
10172
10476
  id: "role_removed_from_group",
10173
10477
  defaultMessage: [{
10174
10478
  "type": 0,
@@ -10182,7 +10486,7 @@ function GroupCtx() {
10182
10486
  }]
10183
10487
  }, {
10184
10488
  role: role
10185
- }), errorMessage);
10489
+ }), errorMessage != null ? errorMessage : '');
10186
10490
  });
10187
10491
  } catch (e) {
10188
10492
  return Promise.reject(e);
@@ -10192,30 +10496,32 @@ function GroupCtx() {
10192
10496
  var addUser = function addUser(newUserId) {
10193
10497
  try {
10194
10498
  var data = {};
10195
- Ctx.context.users.forEach(function (user) {
10499
+ groupDataContext.users.forEach(function (user) {
10196
10500
  data[user] = true;
10197
10501
  });
10198
10502
  data[newUserId] = true;
10199
10503
  return Promise.resolve(Ctx.client.rest.patch(Ctx.containerPath + "@groups/" + Ctx.context['@name'], {
10200
10504
  users: data
10201
- })).then(function (_ref3) {
10202
- var isError = _ref3.isError,
10203
- errorMessage = _ref3.errorMessage;
10204
- handleResponse(isError, intl.formatMessage({
10205
- id: "user_added_to_group",
10206
- defaultMessage: [{
10207
- "type": 0,
10208
- "value": "User "
10209
- }, {
10210
- "type": 1,
10211
- "value": "user"
10505
+ })).then(function (response) {
10506
+ return Promise.resolve(processResponse(response)).then(function (_ref3) {
10507
+ var isError = _ref3.isError,
10508
+ errorMessage = _ref3.errorMessage;
10509
+ handleResponse(isError, intl.formatMessage({
10510
+ id: "user_added_to_group",
10511
+ defaultMessage: [{
10512
+ "type": 0,
10513
+ "value": "User "
10514
+ }, {
10515
+ "type": 1,
10516
+ "value": "user"
10517
+ }, {
10518
+ "type": 0,
10519
+ "value": " added to group"
10520
+ }]
10212
10521
  }, {
10213
- "type": 0,
10214
- "value": " added to group"
10215
- }]
10216
- }, {
10217
- user: newUserId
10218
- }), errorMessage);
10522
+ user: newUserId
10523
+ }), errorMessage != null ? errorMessage : '');
10524
+ });
10219
10525
  });
10220
10526
  } catch (e) {
10221
10527
  return Promise.reject(e);
@@ -10225,29 +10531,31 @@ function GroupCtx() {
10225
10531
  var removeUser = function removeUser(userToRemove) {
10226
10532
  try {
10227
10533
  var data = {};
10228
- Ctx.context.users.forEach(function (user) {
10534
+ groupDataContext.users.forEach(function (user) {
10229
10535
  data[user] = userToRemove !== user;
10230
10536
  });
10231
10537
  return Promise.resolve(Ctx.client.rest.patch(Ctx.containerPath + "@groups/" + Ctx.context['@name'], {
10232
10538
  users: data
10233
- })).then(function (_ref4) {
10234
- var isError = _ref4.isError,
10235
- errorMessage = _ref4.errorMessage;
10236
- handleResponse(isError, intl.formatMessage({
10237
- id: "user_removed_from_group",
10238
- defaultMessage: [{
10239
- "type": 0,
10240
- "value": "User "
10241
- }, {
10242
- "type": 1,
10243
- "value": "user"
10539
+ })).then(function (response) {
10540
+ return Promise.resolve(processResponse(response)).then(function (_ref4) {
10541
+ var isError = _ref4.isError,
10542
+ errorMessage = _ref4.errorMessage;
10543
+ handleResponse(isError, intl.formatMessage({
10544
+ id: "user_removed_from_group",
10545
+ defaultMessage: [{
10546
+ "type": 0,
10547
+ "value": "User "
10548
+ }, {
10549
+ "type": 1,
10550
+ "value": "user"
10551
+ }, {
10552
+ "type": 0,
10553
+ "value": " removed from group"
10554
+ }]
10244
10555
  }, {
10245
- "type": 0,
10246
- "value": " removed from group"
10247
- }]
10248
- }, {
10249
- user: userToRemove
10250
- }), errorMessage);
10556
+ user: userToRemove
10557
+ }), errorMessage != null ? errorMessage : '');
10558
+ });
10251
10559
  });
10252
10560
  } catch (e) {
10253
10561
  return Promise.reject(e);
@@ -10302,11 +10610,13 @@ function GroupCtx() {
10302
10610
  })
10303
10611
  }), jsxRuntime.jsx(Select, {
10304
10612
  options: roles.filter(function (role) {
10305
- return !Ctx.context.user_roles.includes(role.value);
10613
+ return !groupDataContext.user_roles.includes(role.value);
10306
10614
  }),
10307
10615
  appendDefault: true,
10308
- onChange: addRole
10309
- }), jsxRuntime.jsx("hr", {}), Ctx.context.user_roles.map(function (urole) {
10616
+ onChange: function onChange(value) {
10617
+ return addRole(value);
10618
+ }
10619
+ }), jsxRuntime.jsx("hr", {}), groupDataContext.user_roles.map(function (urole) {
10310
10620
  return jsxRuntime.jsx("p", {
10311
10621
  className: "control",
10312
10622
  children: jsxRuntime.jsx(Tag, {
@@ -10338,7 +10648,7 @@ function GroupCtx() {
10338
10648
  traversal: Ctx,
10339
10649
  onChange: addUser,
10340
10650
  btnClass: "is-small"
10341
- }), jsxRuntime.jsx("hr", {}), Ctx.context.users.map(function (user) {
10651
+ }), jsxRuntime.jsx("hr", {}), groupDataContext.users.map(function (user) {
10342
10652
  return jsxRuntime.jsx("p", {
10343
10653
  className: "control",
10344
10654
  children: jsxRuntime.jsx(Tag, {
@@ -10487,7 +10797,7 @@ function Path() {
10487
10797
  var links = buildPaths(segments);
10488
10798
 
10489
10799
  if (segments.length === 1) {
10490
- return false;
10800
+ return null;
10491
10801
  }
10492
10802
 
10493
10803
  return jsxRuntime.jsx("nav", {
@@ -10621,11 +10931,13 @@ var getComponent = function getComponent(context, path, fallback) {
10621
10931
  fallback = undefined;
10622
10932
  }
10623
10933
 
10624
- if (!context) return;
10934
+ if (!context) return; // console.log("Component for path", path)
10935
+ // lookup by path
10625
10936
 
10626
10937
  if (registry.paths[path]) {
10627
10938
  return registry.paths[path];
10628
- }
10939
+ } // by type
10940
+
10629
10941
 
10630
10942
  if (registry.views[context['@type']]) {
10631
10943
  return registry.views[context['@type']];
@@ -10648,19 +10960,15 @@ var getItemsColumn = function getItemsColumn(type) {
10648
10960
  return undefined;
10649
10961
  };
10650
10962
 
10651
- var getForm = function getForm(type, fallback) {
10652
- if (fallback === void 0) {
10653
- fallback = BaseForm;
10654
- }
10963
+ var getView = function getView(name) {
10964
+ return registry.views[name];
10965
+ };
10655
10966
 
10656
- return registry.forms[type] || fallback;
10967
+ var getForm = function getForm(type, fallback) {
10968
+ return registry.forms[type] || fallback || BaseForm;
10657
10969
  };
10658
10970
 
10659
10971
  var getAction = function getAction(type, fallback) {
10660
- if (fallback === void 0) {
10661
- fallback = undefined;
10662
- }
10663
-
10664
10972
  return registry.actions[type] || fallback;
10665
10973
  };
10666
10974
 
@@ -10677,10 +10985,21 @@ var getSchemas = function getSchemas(type) {
10677
10985
  };
10678
10986
 
10679
10987
  var getFieldsToFilter = function getFieldsToFilter(type, fallback) {
10988
+ if (fallback === void 0) {
10989
+ fallback = ['title'];
10990
+ }
10991
+
10680
10992
  return registry.fieldsToFilter[type] || fallback;
10681
10993
  };
10682
10994
 
10683
10995
  var getDefaultSortValue = function getDefaultSortValue(type, fallback) {
10996
+ if (fallback === void 0) {
10997
+ fallback = {
10998
+ key: 'id',
10999
+ direction: 'des'
11000
+ };
11001
+ }
11002
+
10684
11003
  return registry.defaultSortValue[type] || fallback;
10685
11004
  };
10686
11005
 
@@ -10688,12 +11007,14 @@ var defaultComponent = function defaultComponent(context) {
10688
11007
  return context.is_folderish ? FolderCtx : ItemCtx;
10689
11008
  };
10690
11009
  function useRegistry(data) {
11010
+ // if data is provided we need to merge it into actual registry
10691
11011
  var ref = React__default['default'].useRef();
10692
11012
 
10693
11013
  if (data && !ref.current) {
10694
11014
  ref.current = true;
10695
11015
  Object.keys(data).map(function (key) {
10696
- return registry[key] = _extends({}, registry[key], data[key]);
11016
+ var registryKey = key;
11017
+ registry[registryKey] = _extends({}, registry[registryKey], data[registryKey]);
10697
11018
  });
10698
11019
  }
10699
11020
 
@@ -10708,86 +11029,26 @@ function useRegistry(data) {
10708
11029
  getItemsColumn: getItemsColumn,
10709
11030
  getFieldsToFilter: getFieldsToFilter,
10710
11031
  getDefaultSortValue: getDefaultSortValue,
10711
- getSchemas: getSchemas
11032
+ getSchemas: getSchemas,
11033
+ getView: getView
10712
11034
  };
10713
11035
  }
11036
+ /*
10714
11037
 
10715
- var initialState$4 = {
10716
- path: '',
10717
- loading: false,
10718
- context: undefined,
10719
- flash: {
10720
- message: undefined,
10721
- type: undefined
10722
- },
10723
- action: {
10724
- action: undefined,
10725
- params: undefined
11038
+ const registry = {
11039
+ paths: {
11040
+ "/db/guillotina/tags/": TagsContext
10726
11041
  },
10727
- permissions: undefined,
10728
- errorStatus: undefined,
10729
- registry: {},
10730
- refresh: undefined
10731
- };
10732
- function guillotinaReducer(state, action) {
10733
- switch (action.type) {
10734
- case 'SET_PATH':
10735
- return _extends({}, state, {
10736
- path: action.payload,
10737
- loading: true
10738
- });
10739
-
10740
- case 'SET_CONTEXT':
10741
- return _extends({}, state, action.payload, {
10742
- errorStatus: undefined,
10743
- loading: false
10744
- });
10745
-
10746
- case 'SET_ERROR':
10747
- return _extends({}, state, {
10748
- errorStatus: action.payload,
10749
- loading: false
10750
- });
10751
-
10752
- case 'SET_FLASH':
10753
- return _extends({}, state, action.payload);
10754
-
10755
- case 'CLEAR_FLASH':
10756
- return _extends({}, state, {
10757
- flash: {
10758
- message: undefined,
10759
- type: undefined
10760
- }
10761
- });
10762
-
10763
- case 'SET_ACTION':
10764
- return _extends({}, state, {
10765
- action: action.payload
10766
- });
11042
+ forms: {
11043
+ Tag: AddTagForm
11044
+ }
11045
+ }
10767
11046
 
10768
- case 'CLEAR_ACTION':
10769
- return _extends({}, state, {
10770
- action: {
10771
- action: undefined,
10772
- params: undefined
10773
- }
10774
- });
10775
11047
 
10776
- case 'REFRESH':
10777
- return _extends({}, state, {
10778
- refresh: Date.now(),
10779
- loading: !action.payload.transparent
10780
- });
11048
+ <guillotina registry={registry} />
10781
11049
 
10782
- case 'APPLY':
10783
- return _extends({}, state, {
10784
- context: _extends({}, state.context, action.payload)
10785
- });
10786
11050
 
10787
- default:
10788
- return state;
10789
- }
10790
- }
11051
+ */
10791
11052
 
10792
11053
  var actions = [
10793
11054
  {
@@ -13598,25 +13859,27 @@ function Guillotina(_ref) {
13598
13859
  props = _objectWithoutPropertiesLoose(_ref, ["auth", "locale"]);
13599
13860
 
13600
13861
  var messages = loadLocaleData(locale);
13601
- var url = props.url || 'http://localhost:8080';
13862
+ var url = props.url || 'http://localhost:8080'; // without trailing slash
13863
+
13602
13864
  var config = props.config || {};
13603
13865
  var client = useGuillotinaClient();
13604
13866
 
13605
13867
  var _useConfig = useConfig(config),
13606
13868
  Permissions = _useConfig.Permissions;
13607
13869
 
13608
- var registry = useRegistry(props.registry || {});
13870
+ var registry = useRegistry(props.registry); // Location is cooked routing solution (only uses search params)
13609
13871
 
13610
13872
  var _useLocation = useLocation(),
13611
- location = _useLocation[0];
13873
+ location = _useLocation[0]; // if there is no path provided just go to root
13874
+
13612
13875
 
13613
13876
  var searchPath = location.get('path') || '/';
13614
13877
 
13615
13878
  if (searchPath && searchPath !== '') {
13616
- initialState$4.path = searchPath;
13879
+ initialState.path = searchPath;
13617
13880
  }
13618
13881
 
13619
- var _useReducer = React.useReducer(guillotinaReducer, initialState$4),
13882
+ var _useReducer = React.useReducer(guillotinaReducer, initialState),
13620
13883
  state = _useReducer[0],
13621
13884
  dispatch = _useReducer[1];
13622
13885
 
@@ -13624,8 +13887,10 @@ function Guillotina(_ref) {
13624
13887
  refresh = state.refresh;
13625
13888
  React.useEffect(function () {
13626
13889
  dispatch({
13627
- type: 'SET_PATH',
13628
- payload: searchPath
13890
+ type: GuillotinaReducerActionTypes.SET_PATH,
13891
+ payload: {
13892
+ path: searchPath
13893
+ }
13629
13894
  });
13630
13895
  }, [searchPath]);
13631
13896
  React.useEffect(function () {
@@ -13634,14 +13899,18 @@ function Guillotina(_ref) {
13634
13899
  return Promise.resolve(client.getContext(path)).then(function (data) {
13635
13900
  if (data.status === 401) {
13636
13901
  dispatch({
13637
- type: 'SET_ERROR',
13638
- payload: 'notallowed'
13902
+ type: GuillotinaReducerActionTypes.SET_ERROR,
13903
+ payload: {
13904
+ errorStatus: 'notallowed'
13905
+ }
13639
13906
  });
13640
13907
  return;
13641
13908
  } else if (data.status === 404) {
13642
13909
  dispatch({
13643
- type: 'SET_ERROR',
13644
- payload: 'notfound'
13910
+ type: GuillotinaReducerActionTypes.SET_ERROR,
13911
+ payload: {
13912
+ errorStatus: 'notallowed'
13913
+ }
13645
13914
  });
13646
13915
  return;
13647
13916
  }
@@ -13650,7 +13919,7 @@ function Guillotina(_ref) {
13650
13919
  return Promise.resolve(client.canido(path, Permissions)).then(function (pr) {
13651
13920
  return Promise.resolve(pr.json()).then(function (permissions) {
13652
13921
  dispatch({
13653
- type: 'SET_CONTEXT',
13922
+ type: GuillotinaReducerActionTypes.SET_CONTEXT,
13654
13923
  payload: {
13655
13924
  context: context,
13656
13925
  permissions: permissions
@@ -13667,9 +13936,9 @@ function Guillotina(_ref) {
13667
13936
 
13668
13937
  initContext();
13669
13938
  }, [path, refresh, client]);
13670
- var ErrorBoundary = registry.get('views', 'ErrorBoundary');
13671
- var NotAllowed = registry.get('views', 'NotAllowed');
13672
- var NotFound = registry.get('views', 'NotFound');
13939
+ var ErrorBoundary = registry.getView('ErrorBoundary');
13940
+ var NotAllowed = registry.getView('NotAllowed');
13941
+ var NotFound = registry.getView('NotFound');
13673
13942
  var Path = registry.get('components', 'Path');
13674
13943
  var contextData = {
13675
13944
  url: url,
@@ -13692,7 +13961,7 @@ function Guillotina(_ref) {
13692
13961
  children: jsxRuntime.jsxs(ErrorBoundary, {
13693
13962
  children: [!errorStatus && jsxRuntime.jsx(TraversalProvider, _extends({}, contextData, {
13694
13963
  children: permissions && jsxRuntime.jsxs(React__default['default'].Fragment, {
13695
- children: [action.action && jsxRuntime.jsx(Action, _extends({}, action.params)), jsxRuntime.jsx("div", {
13964
+ children: [action.action && Action !== null && jsxRuntime.jsx(Action, _extends({}, action.params)), jsxRuntime.jsx("div", {
13696
13965
  className: "level",
13697
13966
  children: jsxRuntime.jsx("div", {
13698
13967
  className: "level-left",
@@ -13701,7 +13970,7 @@ function Guillotina(_ref) {
13701
13970
  children: jsxRuntime.jsx(Path, {})
13702
13971
  })
13703
13972
  })
13704
- }), jsxRuntime.jsx(Flash, {}), Main && jsxRuntime.jsx(ErrorBoundary, {
13973
+ }), jsxRuntime.jsx(Flash, {}), Main !== undefined && jsxRuntime.jsx(ErrorBoundary, {
13705
13974
  children: jsxRuntime.jsxs("div", {
13706
13975
  className: "box main-panel",
13707
13976
  children: [state.loading && jsxRuntime.jsx(Loading, {}), !state.loading && jsxRuntime.jsx(Main, {
@@ -13811,7 +14080,7 @@ var ERRORS = {
13811
14080
  var initialState$5 = {
13812
14081
  username: '',
13813
14082
  password: '',
13814
- loading: undefined,
14083
+ loading: false,
13815
14084
  errors: undefined
13816
14085
  };
13817
14086
  var Login = function Login(_ref) {
@@ -13827,7 +14096,7 @@ var Login = function Login(_ref) {
13827
14096
 
13828
14097
  var inputRef = React.useRef(null);
13829
14098
  React.useEffect(function () {
13830
- if (inputRef) {
14099
+ if (inputRef && inputRef.current) {
13831
14100
  inputRef.current.focus();
13832
14101
  }
13833
14102
  }, [inputRef]);
@@ -14048,30 +14317,30 @@ function RequiredFieldsForm(_ref) {
14048
14317
  dataTest: dataTest,
14049
14318
  children: [schema && schema.data && !schema.loading && schema.formFields.map(function (key) {
14050
14319
  if (!ignoreFiels.includes(key)) {
14051
- var _value$title;
14320
+ var _schema$data, _value$title, _schema$data2;
14052
14321
 
14053
- var value = schema.data.properties[key];
14322
+ var value = (_schema$data = schema.data) == null ? void 0 : _schema$data.properties[key];
14054
14323
  return jsxRuntime.jsx(EditComponent, {
14055
14324
  id: key,
14056
14325
  placeholder: (_value$title = value == null ? void 0 : value.title) != null ? _value$title : '',
14057
14326
  className: "",
14058
14327
  required: true,
14059
- schema: schema.data.properties[key],
14060
- setValue: function setValue(ev) {
14328
+ schema: (_schema$data2 = schema.data) == null ? void 0 : _schema$data2.properties[key],
14329
+ setValue: function setValue(value) {
14061
14330
  if (key === 'title') {
14062
14331
  var _extends2;
14063
14332
 
14064
14333
  setFormData(_extends({}, formData, (_extends2 = {
14065
- uuid: stringToSlug(ev)
14066
- }, _extends2[key] = ev, _extends2)));
14334
+ uuid: stringToSlug(value)
14335
+ }, _extends2[key] = value, _extends2)));
14067
14336
  } else if (key === 'uuid') {
14068
14337
  setFormData(_extends({}, formData, {
14069
- uuid: stringToSlug(ev)
14338
+ uuid: stringToSlug(value)
14070
14339
  }));
14071
14340
  } else {
14072
14341
  var _extends3;
14073
14342
 
14074
- setFormData(_extends({}, formData, (_extends3 = {}, _extends3[key] = ev, _extends3)));
14343
+ setFormData(_extends({}, formData, (_extends3 = {}, _extends3[key] = value, _extends3)));
14075
14344
  }
14076
14345
  },
14077
14346
  error: errors[key],
@@ -14202,6 +14471,7 @@ var Auth = /*#__PURE__*/function () {
14202
14471
  method: 'post'
14203
14472
  })).then(function (data) {
14204
14473
  if (data.status === 401) {
14474
+ // invalid token
14205
14475
  _this4.cleanAuth();
14206
14476
 
14207
14477
  _this4.logout();
@@ -14264,7 +14534,7 @@ var Auth = /*#__PURE__*/function () {
14264
14534
 
14265
14535
  if (!authToken) return {};
14266
14536
 
14267
- if (this.willExpire(expires) && this.retryRefresh < this.maxRetry) {
14537
+ if (this.willExpire(expires != null ? expires : '') && this.retryRefresh < this.maxRetry) {
14268
14538
 
14269
14539
  (function () {
14270
14540
  try {
@@ -14322,6 +14592,13 @@ var Auth = /*#__PURE__*/function () {
14322
14592
  return Auth;
14323
14593
  }();
14324
14594
 
14595
+ (function (Setting) {
14596
+ Setting["Allow"] = "Allow";
14597
+ Setting["AllowSingle"] = "AllowSingle";
14598
+ Setting["Deny"] = "Deny";
14599
+ Setting["Unset"] = "Unset";
14600
+ })(exports.Setting || (exports.Setting = {}));
14601
+
14325
14602
  exports.AddItem = AddItem;
14326
14603
  exports.AddPermission = AddPermission;
14327
14604
  exports.AllItemsCheckbox = AllItemsCheckbox;
@@ -14335,7 +14612,6 @@ exports.Button = Button;
14335
14612
  exports.Checkbox = Checkbox;
14336
14613
  exports.ClientContext = ClientContext;
14337
14614
  exports.ClientProvider = ClientProvider;
14338
- exports.Config = Config;
14339
14615
  exports.Confirm = Confirm;
14340
14616
  exports.ContainerCtx = ContainerCtx;
14341
14617
  exports.ContextToolbar = ContextToolbar;
@@ -14433,12 +14709,14 @@ exports.VocabularyRenderField = VocabularyRenderField;
14433
14709
  exports.base64ToArrayBuffer = base64ToArrayBuffer;
14434
14710
  exports.buildQs = buildQs;
14435
14711
  exports.classnames = classnames;
14712
+ exports.debounce = debounce;
14436
14713
  exports.defaultComponent = defaultComponent;
14714
+ exports.defaultConfig = defaultConfig;
14437
14715
  exports.formatDate = formatDate;
14438
14716
  exports.generateUID = generateUID;
14439
14717
  exports.genericFileMessages = genericFileMessages;
14440
14718
  exports.genericMessages = genericMessages;
14441
- exports.get = get$1;
14719
+ exports.get = get;
14442
14720
  exports.getActionsObject = getActionsObject;
14443
14721
  exports.getClient = getClient;
14444
14722
  exports.getNewId = getNewId;