arengibook 2.4.636 → 2.4.638

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 +248 -78
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -39088,6 +39088,7 @@ var MultiSelectMetaAsync = function MultiSelectMetaAsync(_ref) {
39088
39088
  optionLabel = _ref$optionLabel === void 0 ? 'label' : _ref$optionLabel,
39089
39089
  _ref$optionValue = _ref.optionValue,
39090
39090
  optionValue = _ref$optionValue === void 0 ? 'value' : _ref$optionValue,
39091
+ optionsUrl = _ref.optionsUrl,
39091
39092
  _ref$valueStyle = _ref.valueStyle,
39092
39093
  valueStyle = _ref$valueStyle === void 0 ? {} : _ref$valueStyle,
39093
39094
  _ref$filter = _ref.filter,
@@ -39117,40 +39118,151 @@ var MultiSelectMetaAsync = function MultiSelectMetaAsync(_ref) {
39117
39118
  _useState4 = _slicedToArray$9(_useState3, 2),
39118
39119
  loadedOptions = _useState4[0],
39119
39120
  setLoadedOptions = _useState4[1];
39120
- var _useState5 = useState(''),
39121
- _useState6 = _slicedToArray$9(_useState5, 2),
39122
- inputValue = _useState6[0];
39123
- _useState6[1];
39124
39121
  var multiSelectRef = useRef(null);
39125
- var _useState7 = useState(false),
39126
- _useState8 = _slicedToArray$9(_useState7, 2),
39127
- loading = _useState8[0],
39128
- setLoading = _useState8[1];
39122
+ var _useState5 = useState(false),
39123
+ _useState6 = _slicedToArray$9(_useState5, 2),
39124
+ loading = _useState6[0],
39125
+ setLoading = _useState6[1];
39129
39126
  var loadLazyTimeout = useRef();
39130
39127
  var currentPageRef = useRef(1);
39131
39128
  var isOptionsArray = Array.isArray(options);
39129
+ var clickedFromList = useRef(false);
39130
+ var fetchOptionsFromUrl = /*#__PURE__*/function () {
39131
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
39132
+ var search,
39133
+ _ref3,
39134
+ _ref3$page,
39135
+ page,
39136
+ length,
39137
+ start,
39138
+ queryParams,
39139
+ response,
39140
+ responseJSON,
39141
+ dataAjax,
39142
+ mappedOptions,
39143
+ _args = arguments,
39144
+ _t;
39145
+ return _regenerator().w(function (_context) {
39146
+ while (1) switch (_context.n) {
39147
+ case 0:
39148
+ search = _args.length > 0 && _args[0] !== undefined ? _args[0] : '';
39149
+ _ref3 = _args.length > 2 ? _args[2] : undefined, _ref3$page = _ref3.page, page = _ref3$page === void 0 ? 1 : _ref3$page;
39150
+ _context.p = 1;
39151
+ length = 25; // Même valeur que dans loadOptions
39152
+ start = (page - 1) * length;
39153
+ queryParams = new URLSearchParams();
39154
+ if (search) queryParams.append('search[value]', search);
39155
+ queryParams.append('start', start);
39156
+ queryParams.append('length', length);
39157
+ _context.n = 2;
39158
+ return fetch("".concat(optionsUrl, "?").concat(queryParams.toString()));
39159
+ case 2:
39160
+ response = _context.v;
39161
+ if (response.ok) {
39162
+ _context.n = 3;
39163
+ break;
39164
+ }
39165
+ throw new Error("Erreur HTTP: ".concat(response.status));
39166
+ case 3:
39167
+ _context.n = 4;
39168
+ return response.json();
39169
+ case 4:
39170
+ responseJSON = _context.v;
39171
+ // Simule le filtrage et le mapping comme dans loadOptions
39172
+ dataAjax = responseJSON.data.filter(function (data) {
39173
+ // Logique de filtrage si nécessaire (à adapter selon vos besoins)
39174
+ return true;
39175
+ });
39176
+ mappedOptions = dataAjax.map(function (opt) {
39177
+ if (!opt.hasOwnProperty('color') || opt.color === null || opt.color.length === 0) {
39178
+ opt.color = '#ccc';
39179
+ }
39180
+ opt.color = opt.color.toLowerCase();
39181
+ opt.label = opt.nom;
39182
+ opt.value = opt.id;
39183
+ return opt;
39184
+ });
39185
+ return _context.a(2, {
39186
+ options: mappedOptions,
39187
+ hasMore: start + responseJSON.data.length < responseJSON.recordsTotal,
39188
+ additional: {
39189
+ page: page + 1
39190
+ }
39191
+ });
39192
+ case 5:
39193
+ _context.p = 5;
39194
+ _t = _context.v;
39195
+ console.error("Erreur lors de la récupération des options :", _t);
39196
+ return _context.a(2, {
39197
+ options: [],
39198
+ hasMore: false
39199
+ });
39200
+ }
39201
+ }, _callee, null, [[1, 5]]);
39202
+ }));
39203
+ return function fetchOptionsFromUrl() {
39204
+ return _ref2.apply(this, arguments);
39205
+ };
39206
+ }();
39207
+ var numObjValue = Array.isArray(objValue) ? objValue.map(function (opt) {
39208
+ return _objectSpread2(_objectSpread2({}, opt), {}, _defineProperty$b({}, optionValue, typeof opt[optionValue] === 'string' ? parseInt(opt[optionValue], 10) : opt[optionValue]));
39209
+ }) : [];
39210
+ var numValue = function numValue() {
39211
+ if (value && Array.isArray(value) && value.length) {
39212
+ return value;
39213
+ } else if (objValue && Array.isArray(objValue) && objValue.length) {
39214
+ return objValue.map(function (opt) {
39215
+ return parseInt(opt.value);
39216
+ });
39217
+ } else {
39218
+ return [];
39219
+ }
39220
+ };
39132
39221
  useEffect(function () {
39133
- setSelectedOptions(objValue && Array.isArray(objValue) ? objValue.map(function (opt) {
39134
- return opt[optionValue];
39135
- }) : value !== null && value !== void 0 ? value : []);
39136
- console.log(objValue ? _toConsumableArray$7(objValue.map(function (opt) {
39222
+ var _numValue;
39223
+ setSelectedOptions(numObjValue && Array.isArray(numObjValue) && numObjValue.length ? numObjValue.map(function (opt) {
39137
39224
  return opt[optionValue];
39138
- })) : value !== null && value !== void 0 ? value : []);
39225
+ }) : (_numValue = numValue()) !== null && _numValue !== void 0 ? _numValue : []);
39139
39226
  var loadInitialOptions = /*#__PURE__*/function () {
39140
- var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
39141
- var result, _result$options, exists;
39142
- return _regenerator().w(function (_context) {
39143
- while (1) switch (_context.n) {
39227
+ var _ref4 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2() {
39228
+ var _result;
39229
+ var result, _result2, exists;
39230
+ return _regenerator().w(function (_context2) {
39231
+ while (1) switch (_context2.n) {
39144
39232
  case 0:
39145
- _context.n = 1;
39233
+ if (!(typeof options === 'function')) {
39234
+ _context2.n = 2;
39235
+ break;
39236
+ }
39237
+ _context2.n = 1;
39146
39238
  return options('', [], {
39147
39239
  page: 1
39148
39240
  });
39149
39241
  case 1:
39150
- result = _context.v;
39151
- setLoadedOptions((result === null || result === void 0 ? void 0 : result.options) || []);
39242
+ result = _context2.v;
39243
+ _context2.n = 5;
39244
+ break;
39245
+ case 2:
39246
+ if (!optionsUrl) {
39247
+ _context2.n = 4;
39248
+ break;
39249
+ }
39250
+ _context2.n = 3;
39251
+ return fetchOptionsFromUrl('', [], {
39252
+ page: 1
39253
+ });
39254
+ case 3:
39255
+ result = _context2.v;
39256
+ _context2.n = 5;
39257
+ break;
39258
+ case 4:
39259
+ result = {
39260
+ options: []
39261
+ };
39262
+ case 5:
39263
+ setLoadedOptions(((_result = result) === null || _result === void 0 ? void 0 : _result.options) || []);
39152
39264
  if (objValue) {
39153
- exists = result === null || result === void 0 || (_result$options = result.options) === null || _result$options === void 0 ? void 0 : _result$options.some(function (opt) {
39265
+ exists = (_result2 = result) === null || _result2 === void 0 || (_result2 = _result2.options) === null || _result2 === void 0 ? void 0 : _result2.some(function (opt) {
39154
39266
  return opt[optionValue] === objValue[optionValue];
39155
39267
  });
39156
39268
  if (!exists) {
@@ -39159,17 +39271,17 @@ var MultiSelectMetaAsync = function MultiSelectMetaAsync(_ref) {
39159
39271
  });
39160
39272
  }
39161
39273
  }
39162
- case 2:
39163
- return _context.a(2);
39274
+ case 6:
39275
+ return _context2.a(2);
39164
39276
  }
39165
- }, _callee);
39277
+ }, _callee2);
39166
39278
  }));
39167
39279
  return function loadInitialOptions() {
39168
- return _ref2.apply(this, arguments);
39280
+ return _ref4.apply(this, arguments);
39169
39281
  };
39170
39282
  }();
39171
39283
  loadInitialOptions();
39172
- }, [options]);
39284
+ }, [options, optionsUrl]);
39173
39285
  useEffect(function () {
39174
39286
  var observer = new MutationObserver(function () {
39175
39287
  var panel = document.querySelector('.p-multiselect-panel.p-component');
@@ -39206,13 +39318,16 @@ var MultiSelectMetaAsync = function MultiSelectMetaAsync(_ref) {
39206
39318
  };
39207
39319
  var optionTemplate = function optionTemplate(option) {
39208
39320
  if (!option) return null;
39209
- var _ref3 = selectMetaConfig || {};
39210
- _ref3.labelStyle;
39211
- var generalIcon = _ref3.generalIcon;
39321
+ var _ref5 = selectMetaConfig || {};
39322
+ _ref5.labelStyle;
39323
+ var generalIcon = _ref5.generalIcon;
39212
39324
  var styleLabel = {
39213
39325
  marginLeft: '10px'
39214
39326
  };
39215
39327
  return /*#__PURE__*/React__default.createElement("div", {
39328
+ onClick: function onClick() {
39329
+ clickedFromList.current = true;
39330
+ },
39216
39331
  style: _objectSpread2({
39217
39332
  fontFamily: 'Arial',
39218
39333
  fontSize: '14px',
@@ -39272,20 +39387,45 @@ var MultiSelectMetaAsync = function MultiSelectMetaAsync(_ref) {
39272
39387
  if (loadLazyTimeout.current) {
39273
39388
  clearTimeout(loadLazyTimeout.current);
39274
39389
  }
39275
- loadLazyTimeout.current = setTimeout(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2() {
39390
+ loadLazyTimeout.current = setTimeout(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3() {
39391
+ var _result3;
39276
39392
  var first, last, _items, result, newOptions, i, virtualscroll;
39277
- return _regenerator().w(function (_context2) {
39278
- while (1) switch (_context2.n) {
39393
+ return _regenerator().w(function (_context3) {
39394
+ while (1) switch (_context3.n) {
39279
39395
  case 0:
39280
39396
  first = event.first, last = event.last;
39281
39397
  _items = _toConsumableArray$7(loadedOptions);
39282
- _context2.n = 1;
39283
- return options(inputValue, [], {
39398
+ if (!(typeof options === 'function')) {
39399
+ _context3.n = 2;
39400
+ break;
39401
+ }
39402
+ _context3.n = 1;
39403
+ return options("", [], {
39284
39404
  page: currentPageRef.current + 1
39285
39405
  });
39286
39406
  case 1:
39287
- result = _context2.v;
39288
- newOptions = (result === null || result === void 0 ? void 0 : result.options) || [];
39407
+ result = _context3.v;
39408
+ _context3.n = 5;
39409
+ break;
39410
+ case 2:
39411
+ if (!optionsUrl) {
39412
+ _context3.n = 4;
39413
+ break;
39414
+ }
39415
+ _context3.n = 3;
39416
+ return fetchOptionsFromUrl("", [], {
39417
+ page: currentPageRef.current + 1
39418
+ });
39419
+ case 3:
39420
+ result = _context3.v;
39421
+ _context3.n = 5;
39422
+ break;
39423
+ case 4:
39424
+ result = {
39425
+ options: []
39426
+ };
39427
+ case 5:
39428
+ newOptions = ((_result3 = result) === null || _result3 === void 0 ? void 0 : _result3.options) || [];
39289
39429
  for (i = first; i < last; i++) {
39290
39430
  if (!_items[i] && newOptions[i - first]) {
39291
39431
  _items[i] = newOptions[i - first];
@@ -39294,16 +39434,15 @@ var MultiSelectMetaAsync = function MultiSelectMetaAsync(_ref) {
39294
39434
  setLoadedOptions(_items);
39295
39435
  setLoading(false);
39296
39436
  currentPageRef.current += 1;
39297
-
39298
- // redimensionnement du conteneur
39437
+ // Redimensionnement du conteneur
39299
39438
  virtualscroll = document.querySelector('.p-virtualscroller.p-dropdown-items-wrapper');
39300
39439
  if (virtualscroll) {
39301
39440
  virtualscroll.style.height = "auto";
39302
39441
  }
39303
- case 2:
39304
- return _context2.a(2);
39442
+ case 6:
39443
+ return _context3.a(2);
39305
39444
  }
39306
- }, _callee2);
39445
+ }, _callee3);
39307
39446
  })), 500);
39308
39447
  };
39309
39448
  return /*#__PURE__*/React__default.createElement("div", {
@@ -39849,71 +39988,102 @@ var MultiSelectPresets = {
39849
39988
  showSelectAll: false
39850
39989
  },
39851
39990
  // Configuration pour les options asynchrones
39991
+ // SelectMetaAsync: {
39992
+ // isSelectMeta: true,
39993
+ // value: [9, 4],
39994
+ // objValue: [{ label: 'Option 9', value: 9, color: "#67688C" }, { label: 'Option 4', value: 4, color: "#39C9BF" }],
39995
+ // options: async (search = '', _, { page }) => {
39996
+ // await simulateNetworkDelay();
39997
+ // const allOptions = createFakeOptions(0, 100);
39998
+ // const filtered = allOptions.filter(opt =>
39999
+ // opt.label.toLowerCase().includes(search.toLowerCase())
40000
+ // );
40001
+ // const pageSize = 30;
40002
+ // const start = (page - 1) * pageSize;
40003
+ // return {
40004
+ // options: filtered.slice(start, start + pageSize),
40005
+ // hasMore: start + pageSize < filtered.length,
40006
+ // additional: { page: page + 1 },
40007
+ // };
40008
+ // },
40009
+ // optionLabel: 'label',
40010
+ // optionValue: 'value',
40011
+ //
40012
+ // // value: [3,4],
40013
+ // // objValue: [{ name: 'Clementine Bauch', id: 3 }, { name: 'Patricia Lebsack', id: 4 }],
40014
+ // // optionsUrl: "https://jsonplaceholder.typicode.com/users",
40015
+ // // optionLabel: 'name',
40016
+ // // optionValue: 'id',
40017
+ //
40018
+ // placeholder: 'Sélectionnez une ou plusieurs options',
40019
+ // valueStyle: { marginRight: '15px', marginBottom: '5px' },
40020
+ // selectMetaConfig: {
40021
+ // labelStyle: { fontWeight: 'bold' },
40022
+ // generalIcon: 'pi pi-tag',
40023
+ // },
40024
+ // filter: false,
40025
+ // showClear: false,
40026
+ // useCheckbox: false,
40027
+ // showSelectAll: false,
40028
+ // },
40029
+
39852
40030
  SelectMetaAsync: {
39853
40031
  isSelectMeta: true,
40032
+ value: [9, 4],
39854
40033
  objValue: [{
39855
40034
  label: 'Option 9',
39856
40035
  value: 9,
39857
- color: "#67688C"
40036
+ color: "#67688C",
40037
+ nom: 'Option 9',
40038
+ id: 9
39858
40039
  }, {
39859
40040
  label: 'Option 4',
39860
40041
  value: 4,
39861
- color: "#39C9BF"
40042
+ color: "#39C9BF",
40043
+ nom: 'Option 4',
40044
+ id: 4
39862
40045
  }],
39863
- // objValue: [
39864
- // {
39865
- // "id": 2299,
39866
- // "nom": "Economique",
39867
- // "color": "#62BAC0",
39868
- // "label": "Economique",
39869
- // "value": 2299
39870
- // },
39871
- // {
39872
- // "id": 2300,
39873
- // "nom": "Financière",
39874
- // "color": "#40839E",
39875
- // "label": "Financière",
39876
- // "value": 2300
39877
- // },
39878
- // {
39879
- // "id": 2301,
39880
- // "nom": "Données bancaires",
39881
- // "color": "#E5E798",
39882
- // "label": "Données bancaires",
39883
- // "value": 2301
39884
- // }
39885
- // ],
39886
- // value: ['3', '4'],
39887
40046
  options: function () {
39888
40047
  var _options = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2() {
39889
40048
  var search,
39890
40049
  _ref3,
40050
+ _ref3$page,
39891
40051
  page,
39892
40052
  allOptions,
39893
40053
  filtered,
39894
- pageSize,
40054
+ length,
39895
40055
  start,
40056
+ paginatedOptions,
39896
40057
  _args2 = arguments;
39897
40058
  return _regenerator().w(function (_context2) {
39898
40059
  while (1) switch (_context2.n) {
39899
40060
  case 0:
39900
40061
  search = _args2.length > 0 && _args2[0] !== undefined ? _args2[0] : '';
39901
- _ref3 = _args2.length > 2 ? _args2[2] : undefined, page = _ref3.page;
40062
+ _ref3 = _args2.length > 2 ? _args2[2] : undefined, _ref3$page = _ref3.page, page = _ref3$page === void 0 ? 1 : _ref3$page;
39902
40063
  _context2.n = 1;
39903
40064
  return simulateNetworkDelay();
39904
40065
  case 1:
39905
- allOptions = createFakeOptions(0, 100);
40066
+ allOptions = createFakeOptions(0, 100).map(function (opt) {
40067
+ return _objectSpread2(_objectSpread2({}, opt), {}, {
40068
+ nom: opt.label,
40069
+ id: opt.value,
40070
+ color: opt.color || '#ccc'
40071
+ });
40072
+ });
39906
40073
  filtered = allOptions.filter(function (opt) {
39907
- return opt.label.toLowerCase().includes(search.toLowerCase());
40074
+ return opt.nom.toLowerCase().includes(search.toLowerCase());
39908
40075
  });
39909
- pageSize = 30;
39910
- start = (page - 1) * pageSize;
40076
+ length = 25;
40077
+ start = (page - 1) * length; // Simule la réponse de votre API Symfony
40078
+ paginatedOptions = filtered.slice(start, start + length);
39911
40079
  return _context2.a(2, {
39912
- options: filtered.slice(start, start + pageSize),
39913
- hasMore: start + pageSize < filtered.length,
40080
+ options: paginatedOptions,
40081
+ hasMore: start + length < filtered.length,
39914
40082
  additional: {
39915
40083
  page: page + 1
39916
- }
40084
+ },
40085
+ data: paginatedOptions,
40086
+ recordsTotal: filtered.length
39917
40087
  });
39918
40088
  }
39919
40089
  }, _callee2);
@@ -39923,9 +40093,9 @@ var MultiSelectPresets = {
39923
40093
  }
39924
40094
  return options;
39925
40095
  }(),
40096
+ optionLabel: 'nom',
40097
+ optionValue: 'id',
39926
40098
  placeholder: 'Sélectionnez une ou plusieurs options',
39927
- optionLabel: 'label',
39928
- optionValue: 'value',
39929
40099
  valueStyle: {
39930
40100
  marginRight: '15px',
39931
40101
  marginBottom: '5px'
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "arengibook",
3
3
  "private": false,
4
- "version": "2.4.636",
4
+ "version": "2.4.638",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
7
7
  "exports": {