arengibook 3.1.312-main → 3.1.313-main

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 (2) hide show
  1. package/dist/index.js +123 -68
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -37028,6 +37028,7 @@ var DropdownSelectMetaAsync = function DropdownSelectMetaAsync(_ref) {
37028
37028
  optionLabel = _ref$optionLabel === void 0 ? 'label' : _ref$optionLabel,
37029
37029
  _ref$optionValue = _ref.optionValue,
37030
37030
  optionValue = _ref$optionValue === void 0 ? 'value' : _ref$optionValue,
37031
+ optionsUrl = _ref.optionsUrl,
37031
37032
  _ref$invalid = _ref.invalid,
37032
37033
  invalid = _ref$invalid === void 0 ? false : _ref$invalid,
37033
37034
  _ref$errorMessage = _ref.errorMessage,
@@ -37115,6 +37116,94 @@ var DropdownSelectMetaAsync = function DropdownSelectMetaAsync(_ref) {
37115
37116
  style: styleLabel
37116
37117
  }, option === null || option === void 0 ? void 0 : option[optionLabel])));
37117
37118
  };
37119
+
37120
+ // 🔹 Chargement des options depuis une URL (même contrat que MultiSelectMetaAsync)
37121
+ var fetchOptionsFromUrl = /*#__PURE__*/function () {
37122
+ var _ref3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
37123
+ var search,
37124
+ _ref4,
37125
+ _ref4$page,
37126
+ page,
37127
+ length,
37128
+ start,
37129
+ queryParams,
37130
+ response,
37131
+ responseJSON,
37132
+ dataAjax,
37133
+ mappedOptions,
37134
+ hasMore,
37135
+ _args = arguments,
37136
+ _t;
37137
+ return _regenerator().w(function (_context) {
37138
+ while (1) switch (_context.n) {
37139
+ case 0:
37140
+ search = _args.length > 0 && _args[0] !== undefined ? _args[0] : '';
37141
+ _ref4 = _args.length > 2 && _args[2] !== undefined ? _args[2] : {}, _ref4$page = _ref4.page, page = _ref4$page === void 0 ? 1 : _ref4$page;
37142
+ _context.p = 1;
37143
+ length = 25;
37144
+ start = (page - 1) * length;
37145
+ queryParams = new URLSearchParams();
37146
+ if (search) queryParams.append('search[value]', search);
37147
+ queryParams.append('start', start);
37148
+ queryParams.append('length', length);
37149
+ _context.n = 2;
37150
+ return fetch("".concat(optionsUrl, "?").concat(queryParams.toString()));
37151
+ case 2:
37152
+ response = _context.v;
37153
+ if (response.ok) {
37154
+ _context.n = 4;
37155
+ break;
37156
+ }
37157
+ if (!(response.status === 404)) {
37158
+ _context.n = 3;
37159
+ break;
37160
+ }
37161
+ return _context.a(2, {
37162
+ options: [],
37163
+ hasMore: false
37164
+ });
37165
+ case 3:
37166
+ throw new Error("Erreur HTTP: ".concat(response.status));
37167
+ case 4:
37168
+ _context.n = 5;
37169
+ return response.json();
37170
+ case 5:
37171
+ responseJSON = _context.v;
37172
+ dataAjax = responseJSON.data || [];
37173
+ mappedOptions = dataAjax.map(function (opt) {
37174
+ if (opt.hasOwnProperty('color') && opt.color !== null && opt.color.length > 0) {
37175
+ opt.color = opt.color.toLowerCase();
37176
+ } else {
37177
+ delete opt.color;
37178
+ }
37179
+ opt.label = opt.nom !== undefined && opt.nom !== null ? opt.nom : opt.label;
37180
+ opt.value = opt.id;
37181
+ return opt;
37182
+ });
37183
+ hasMore = start + dataAjax.length < responseJSON.recordsTotal;
37184
+ return _context.a(2, {
37185
+ options: mappedOptions,
37186
+ hasMore: hasMore,
37187
+ additional: {
37188
+ page: page + 1
37189
+ }
37190
+ });
37191
+ case 6:
37192
+ _context.p = 6;
37193
+ _t = _context.v;
37194
+ console.error("Erreur lors de la récupération des options :", _t);
37195
+ return _context.a(2, {
37196
+ options: [],
37197
+ hasMore: false
37198
+ });
37199
+ }
37200
+ }, _callee, null, [[1, 6]]);
37201
+ }));
37202
+ return function fetchOptionsFromUrl() {
37203
+ return _ref3.apply(this, arguments);
37204
+ };
37205
+ }();
37206
+ var loadOptions = typeof options === 'function' ? options : fetchOptionsFromUrl;
37118
37207
  var isInvalidEffective = invalid || showRequiredError;
37119
37208
  var style = {
37120
37209
  border: isInvalidEffective ? '1px solid red' : '1px solid #ccc',
@@ -37127,17 +37216,17 @@ var DropdownSelectMetaAsync = function DropdownSelectMetaAsync(_ref) {
37127
37216
  useEffect(function () {
37128
37217
  setOptionSelected(objValue ? objValue === null || objValue === void 0 ? void 0 : objValue[optionValue] : value !== null && value !== void 0 ? value : null);
37129
37218
  var loadInitialOptions = /*#__PURE__*/function () {
37130
- var _ref3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
37219
+ var _ref5 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2() {
37131
37220
  var result, _result$options, exists;
37132
- return _regenerator().w(function (_context) {
37133
- while (1) switch (_context.n) {
37221
+ return _regenerator().w(function (_context2) {
37222
+ while (1) switch (_context2.n) {
37134
37223
  case 0:
37135
- _context.n = 1;
37136
- return options('', [], {
37224
+ _context2.n = 1;
37225
+ return loadOptions('', [], {
37137
37226
  page: 1
37138
37227
  });
37139
37228
  case 1:
37140
- result = _context.v;
37229
+ result = _context2.v;
37141
37230
  setLoadedOptions((result === null || result === void 0 ? void 0 : result.options) || []);
37142
37231
  if (objValue) {
37143
37232
  exists = result === null || result === void 0 || (_result$options = result.options) === null || _result$options === void 0 ? void 0 : _result$options.some(function (opt) {
@@ -37150,12 +37239,12 @@ var DropdownSelectMetaAsync = function DropdownSelectMetaAsync(_ref) {
37150
37239
  }
37151
37240
  }
37152
37241
  case 2:
37153
- return _context.a(2);
37242
+ return _context2.a(2);
37154
37243
  }
37155
- }, _callee);
37244
+ }, _callee2);
37156
37245
  }));
37157
37246
  return function loadInitialOptions() {
37158
- return _ref3.apply(this, arguments);
37247
+ return _ref5.apply(this, arguments);
37159
37248
  };
37160
37249
  }();
37161
37250
  loadInitialOptions();
@@ -37163,7 +37252,7 @@ var DropdownSelectMetaAsync = function DropdownSelectMetaAsync(_ref) {
37163
37252
  return function () {
37164
37253
  document.removeEventListener('mousedown', handleClickOutside);
37165
37254
  };
37166
- }, [options, objValue, value]);
37255
+ }, [options, optionsUrl, objValue, value]);
37167
37256
  var handleClickOutside = function handleClickOutside(event) {
37168
37257
  if (dropdownRef.current && !dropdownRef.current.contains(event.target)) {
37169
37258
  setIsEditing(false);
@@ -37198,51 +37287,51 @@ var DropdownSelectMetaAsync = function DropdownSelectMetaAsync(_ref) {
37198
37287
  setOptionSelected(null);
37199
37288
  setInputValue('');
37200
37289
  if (onChange) onChange(null);
37201
- options('', [], {
37290
+ loadOptions('', [], {
37202
37291
  page: 1
37203
37292
  }).then(function (result) {
37204
37293
  setLoadedOptions((result === null || result === void 0 ? void 0 : result.options) || []);
37205
37294
  });
37206
37295
  };
37207
37296
  var handleInputChange = /*#__PURE__*/function () {
37208
- var _ref4 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(e) {
37297
+ var _ref6 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(e) {
37209
37298
  var search, result, _result$options2, _result, filteredOptions;
37210
- return _regenerator().w(function (_context2) {
37211
- while (1) switch (_context2.n) {
37299
+ return _regenerator().w(function (_context3) {
37300
+ while (1) switch (_context3.n) {
37212
37301
  case 0:
37213
37302
  search = e.target.value;
37214
37303
  setInputValue(search);
37215
37304
  if (search) {
37216
- _context2.n = 2;
37305
+ _context3.n = 2;
37217
37306
  break;
37218
37307
  }
37219
- _context2.n = 1;
37220
- return options('', [], {
37308
+ _context3.n = 1;
37309
+ return loadOptions('', [], {
37221
37310
  page: 1
37222
37311
  });
37223
37312
  case 1:
37224
- result = _context2.v;
37313
+ result = _context3.v;
37225
37314
  setLoadedOptions((result === null || result === void 0 ? void 0 : result.options) || []);
37226
- _context2.n = 4;
37315
+ _context3.n = 4;
37227
37316
  break;
37228
37317
  case 2:
37229
- _context2.n = 3;
37230
- return options(search, [], {
37318
+ _context3.n = 3;
37319
+ return loadOptions(search, [], {
37231
37320
  page: 1
37232
37321
  });
37233
37322
  case 3:
37234
- _result = _context2.v;
37323
+ _result = _context3.v;
37235
37324
  filteredOptions = (_result === null || _result === void 0 || (_result$options2 = _result.options) === null || _result$options2 === void 0 ? void 0 : _result$options2.filter(function (opt) {
37236
37325
  return opt[optionLabel].toLowerCase().includes(search.toLowerCase());
37237
37326
  })) || [];
37238
37327
  setLoadedOptions(filteredOptions);
37239
37328
  case 4:
37240
- return _context2.a(2);
37329
+ return _context3.a(2);
37241
37330
  }
37242
- }, _callee2);
37331
+ }, _callee3);
37243
37332
  }));
37244
37333
  return function handleInputChange(_x) {
37245
- return _ref4.apply(this, arguments);
37334
+ return _ref6.apply(this, arguments);
37246
37335
  };
37247
37336
  }();
37248
37337
  var selectedOption = loadedOptions.find(function (opt) {
@@ -37519,10 +37608,11 @@ var Dropdown = function Dropdown(props) {
37519
37608
  _props$subItem = props.subItem,
37520
37609
  subItem = _props$subItem === void 0 ? false : _props$subItem,
37521
37610
  _props$required = props.required,
37522
- required = _props$required === void 0 ? false : _props$required;
37611
+ required = _props$required === void 0 ? false : _props$required,
37612
+ optionsUrl = props.optionsUrl;
37523
37613
 
37524
37614
  // --- Async delegation ---
37525
- var isAsyncOptions = typeof options === 'function';
37615
+ var isAsyncOptions = typeof options === 'function' || optionsUrl;
37526
37616
  if (isAsyncOptions) {
37527
37617
  return /*#__PURE__*/React__default.createElement(DropdownSelectMetaAsync, props);
37528
37618
  }
@@ -55744,41 +55834,12 @@ var Table$1 = function Table(_ref13) {
55744
55834
  locked = _useState32[0],
55745
55835
  setLocked = _useState32[1];
55746
55836
  var effectiveEditable = lockable ? editable && !locked : editable;
55747
-
55748
- // Construit l'attributeData complet d'une ligne : une entrée par colonne
55749
- // qui déclare attributeData, disponible dès le chargement (avant toute édition).
55750
- var buildAttributeData = useCallback(function () {
55751
- var result = {};
55752
- columns.forEach(function (col) {
55753
- if (col.attributeData !== undefined) result[col.field] = col.attributeData;
55754
- });
55755
- return result;
55756
- }, [columns]);
55757
-
55758
- // Enrichit chaque ligne avec l'attributeData de toutes les colonnes.
55759
- // Comme les mises à jour font toujours { ...row, [field]: newVal },
55760
- // l'attributeData posé ici est préservé à travers toutes les éditions.
55761
- var enrichRows = useCallback(function (rows) {
55762
- var attributeData = buildAttributeData();
55763
- if (!Object.keys(attributeData).length) return rows;
55764
- return rows.map(function (row) {
55765
- return _objectSpread2(_objectSpread2({}, row), {}, {
55766
- attributeData: attributeData
55767
- });
55768
- });
55769
- }, [buildAttributeData]);
55770
- var _useState33 = useState(function () {
55771
- return enrichRows(value);
55772
- }),
55837
+ var _useState33 = useState(value),
55773
55838
  _useState34 = _slicedToArray$d(_useState33, 2),
55774
55839
  data = _useState34[0],
55775
55840
  setData = _useState34[1];
55776
- // Dépendre uniquement de `value` : enrichRows change de référence si `columns`
55777
- // est recréé par le parent à chaque rendu, ce qui re-synchroniserait la data
55778
- // et écraserait les éditions en cours.
55779
- // eslint-disable-next-line react-hooks/exhaustive-deps
55780
55841
  useEffect(function () {
55781
- setData(enrichRows(value));
55842
+ setData(value);
55782
55843
  }, [value]);
55783
55844
  var onCellChangeRef = useRef(onCellChange);
55784
55845
  useEffect(function () {
@@ -55822,8 +55883,7 @@ var Table$1 = function Table(_ref13) {
55822
55883
  var handleAddRow = useCallback(function () {
55823
55884
  // id temporaire négatif pour éviter les collisions avec les id BDD positifs
55824
55885
  var newRow = {
55825
- id: -Date.now(),
55826
- attributeData: buildAttributeData()
55886
+ id: -Date.now()
55827
55887
  };
55828
55888
  columns.forEach(function (col) {
55829
55889
  switch (col.type) {
@@ -55842,7 +55902,7 @@ var Table$1 = function Table(_ref13) {
55842
55902
  onAdd === null || onAdd === void 0 || onAdd(newRow, updated);
55843
55903
  return updated;
55844
55904
  });
55845
- }, [columns, onChange, onAdd, buildAttributeData]);
55905
+ }, [columns, onChange, onAdd]);
55846
55906
  var _useState37 = useState({}),
55847
55907
  _useState38 = _slicedToArray$d(_useState37, 2),
55848
55908
  editingRows = _useState38[0],
@@ -56966,6 +57026,7 @@ var Table$1 = function Table(_ref13) {
56966
57026
  rowData: rowData,
56967
57027
  col: col,
56968
57028
  editable: colEditable,
57029
+ isRowEditing: !!editingRows[rowData.id],
56969
57030
  onSave: function onSave(v) {
56970
57031
  var _onCellChangeRef$curr2;
56971
57032
  var enrichedFields = _defineProperty$g({}, col.field, v);
@@ -56996,7 +57057,6 @@ var Table$1 = function Table(_ref13) {
56996
57057
  newValue: v
56997
57058
  });
56998
57059
  },
56999
- isRowEditing: !!editingRows[rowData.id],
57000
57060
  renderDisplay: displayFn !== null && displayFn !== void 0 ? displayFn : function (rd) {
57001
57061
  var _rd$col$field;
57002
57062
  return (_rd$col$field = rd[col.field]) !== null && _rd$col$field !== void 0 ? _rd$col$field : '';
@@ -58160,12 +58220,7 @@ var columnsTyped = [
58160
58220
  header: 'Inscription',
58161
58221
  type: 'date',
58162
58222
  editable: true,
58163
- dbDateFormat: 'MMMM/y',
58164
- attributeData: {
58165
- 'data-value': 'bonjour',
58166
- 'data-tata': 'hello',
58167
- 'data-tab': []
58168
- }
58223
+ dbDateFormat: 'MMMM/y'
58169
58224
  }, {
58170
58225
  field: 'dateNaissance',
58171
58226
  header: 'Naissance',
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "arengibook",
3
3
  "private": false,
4
- "version": "3.1.312-main",
4
+ "version": "3.1.313-main",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
7
7
  "exports": {