arengibook 2.4.635 → 2.4.637

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 +218 -135
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -36820,12 +36820,12 @@ var DropdownPresets = {
36820
36820
  }
36821
36821
  };
36822
36822
 
36823
- var simulateNetworkDelay$1 = function simulateNetworkDelay() {
36823
+ var simulateNetworkDelay = function simulateNetworkDelay() {
36824
36824
  return new Promise(function (res) {
36825
36825
  return setTimeout(res, 400);
36826
36826
  });
36827
36827
  };
36828
- var createFakeOptions$1 = function createFakeOptions(start, length) {
36828
+ var createFakeOptions = function createFakeOptions(start, length) {
36829
36829
  var options = [];
36830
36830
  for (var i = start; i < start + length; i++) {
36831
36831
  options.push({
@@ -36854,9 +36854,9 @@ var DropdownSelectMetaAsyncPresets = {
36854
36854
  search = _args.length > 0 && _args[0] !== undefined ? _args[0] : '';
36855
36855
  _ref = _args.length > 2 ? _args[2] : undefined, page = _ref.page;
36856
36856
  _context.n = 1;
36857
- return simulateNetworkDelay$1();
36857
+ return simulateNetworkDelay();
36858
36858
  case 1:
36859
- allOptions = createFakeOptions$1(0, 100);
36859
+ allOptions = createFakeOptions(0, 100);
36860
36860
  filtered = allOptions.filter(function (opt) {
36861
36861
  return opt.label.toLowerCase().includes(search.toLowerCase());
36862
36862
  });
@@ -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,154 @@ 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
+ queryParams,
39137
+ response,
39138
+ data,
39139
+ items,
39140
+ filteredItems,
39141
+ pageSize,
39142
+ start,
39143
+ paginatedItems,
39144
+ mappedOptions,
39145
+ _args = arguments,
39146
+ _t;
39147
+ return _regenerator().w(function (_context) {
39148
+ while (1) switch (_context.n) {
39149
+ case 0:
39150
+ search = _args.length > 0 && _args[0] !== undefined ? _args[0] : '';
39151
+ _ref3 = _args.length > 2 ? _args[2] : undefined, _ref3$page = _ref3.page, page = _ref3$page === void 0 ? 1 : _ref3$page;
39152
+ _context.p = 1;
39153
+ // Construction de l'URL avec les paramètres de pagination et de recherche
39154
+ queryParams = new URLSearchParams();
39155
+ if (search) queryParams.append('search', search);
39156
+ queryParams.append('page', page);
39157
+ queryParams.append('pageSize', 30);
39158
+ _context.n = 2;
39159
+ return fetch("".concat(optionsUrl, "?").concat(queryParams.toString()));
39160
+ case 2:
39161
+ response = _context.v;
39162
+ if (response.ok) {
39163
+ _context.n = 3;
39164
+ break;
39165
+ }
39166
+ throw new Error("Erreur HTTP: ".concat(response.status));
39167
+ case 3:
39168
+ _context.n = 4;
39169
+ return response.json();
39170
+ case 4:
39171
+ data = _context.v;
39172
+ // Récupération des données paginées ou filtrées
39173
+ // (adaptez cette partie si votre API retourne les données dans un champ spécifique, comme `data.results`)
39174
+ items = Array.isArray(data) ? data : data.results || data.items || []; // Filtrage côté client si nécessaire
39175
+ filteredItems = search ? items.filter(function (item) {
39176
+ return String(item[optionLabel]).toLowerCase().includes(search.toLowerCase());
39177
+ }) : items; // Pagination côté client
39178
+ pageSize = 30;
39179
+ start = (page - 1) * pageSize;
39180
+ paginatedItems = filteredItems.slice(start, start + pageSize); // Mapping dynamique des champs
39181
+ mappedOptions = paginatedItems.map(function (item) {
39182
+ var option = _objectSpread2({}, item);
39183
+ // Si optionLabel et optionValue sont différents des clés par défaut
39184
+ option.label = item[optionLabel];
39185
+ option.value = item[optionValue];
39186
+ return option;
39187
+ });
39188
+ return _context.a(2, {
39189
+ options: mappedOptions,
39190
+ hasMore: start + pageSize < filteredItems.length,
39191
+ additional: {
39192
+ page: page + 1
39193
+ }
39194
+ });
39195
+ case 5:
39196
+ _context.p = 5;
39197
+ _t = _context.v;
39198
+ console.error("Erreur lors de la récupération des options :", _t);
39199
+ return _context.a(2, {
39200
+ options: [],
39201
+ hasMore: false
39202
+ });
39203
+ }
39204
+ }, _callee, null, [[1, 5]]);
39205
+ }));
39206
+ return function fetchOptionsFromUrl() {
39207
+ return _ref2.apply(this, arguments);
39208
+ };
39209
+ }();
39210
+ var numObjValue = Array.isArray(objValue) ? objValue.map(function (opt) {
39211
+ return _objectSpread2(_objectSpread2({}, opt), {}, _defineProperty$b({}, optionValue, typeof opt[optionValue] === 'string' ? parseInt(opt[optionValue], 10) : opt[optionValue]));
39212
+ }) : [];
39213
+ var numValue = function numValue() {
39214
+ if (value && Array.isArray(value) && value.length) {
39215
+ return value;
39216
+ } else if (objValue && Array.isArray(objValue) && objValue.length) {
39217
+ return objValue.map(function (opt) {
39218
+ return parseInt(opt.value);
39219
+ });
39220
+ } else {
39221
+ return [];
39222
+ }
39223
+ };
39132
39224
  useEffect(function () {
39133
- setSelectedOptions(objValue ? _toConsumableArray$7(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) {
39225
+ var _numValue;
39226
+ setSelectedOptions(numObjValue && Array.isArray(numObjValue) && numObjValue.length ? numObjValue.map(function (opt) {
39137
39227
  return opt[optionValue];
39138
- })) : value !== null && value !== void 0 ? value : []);
39228
+ }) : (_numValue = numValue()) !== null && _numValue !== void 0 ? _numValue : []);
39139
39229
  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) {
39230
+ var _ref4 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2() {
39231
+ var _result;
39232
+ var result, _result2, exists;
39233
+ return _regenerator().w(function (_context2) {
39234
+ while (1) switch (_context2.n) {
39144
39235
  case 0:
39145
- _context.n = 1;
39236
+ if (!(typeof options === 'function')) {
39237
+ _context2.n = 2;
39238
+ break;
39239
+ }
39240
+ _context2.n = 1;
39146
39241
  return options('', [], {
39147
39242
  page: 1
39148
39243
  });
39149
39244
  case 1:
39150
- result = _context.v;
39151
- setLoadedOptions((result === null || result === void 0 ? void 0 : result.options) || []);
39245
+ result = _context2.v;
39246
+ _context2.n = 5;
39247
+ break;
39248
+ case 2:
39249
+ if (!optionsUrl) {
39250
+ _context2.n = 4;
39251
+ break;
39252
+ }
39253
+ _context2.n = 3;
39254
+ return fetchOptionsFromUrl('', [], {
39255
+ page: 1
39256
+ });
39257
+ case 3:
39258
+ result = _context2.v;
39259
+ _context2.n = 5;
39260
+ break;
39261
+ case 4:
39262
+ result = {
39263
+ options: []
39264
+ };
39265
+ case 5:
39266
+ setLoadedOptions(((_result = result) === null || _result === void 0 ? void 0 : _result.options) || []);
39152
39267
  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) {
39268
+ exists = (_result2 = result) === null || _result2 === void 0 || (_result2 = _result2.options) === null || _result2 === void 0 ? void 0 : _result2.some(function (opt) {
39154
39269
  return opt[optionValue] === objValue[optionValue];
39155
39270
  });
39156
39271
  if (!exists) {
@@ -39159,17 +39274,17 @@ var MultiSelectMetaAsync = function MultiSelectMetaAsync(_ref) {
39159
39274
  });
39160
39275
  }
39161
39276
  }
39162
- case 2:
39163
- return _context.a(2);
39277
+ case 6:
39278
+ return _context2.a(2);
39164
39279
  }
39165
- }, _callee);
39280
+ }, _callee2);
39166
39281
  }));
39167
39282
  return function loadInitialOptions() {
39168
- return _ref2.apply(this, arguments);
39283
+ return _ref4.apply(this, arguments);
39169
39284
  };
39170
39285
  }();
39171
39286
  loadInitialOptions();
39172
- }, [options]);
39287
+ }, [options, optionsUrl]);
39173
39288
  useEffect(function () {
39174
39289
  var observer = new MutationObserver(function () {
39175
39290
  var panel = document.querySelector('.p-multiselect-panel.p-component');
@@ -39206,13 +39321,17 @@ var MultiSelectMetaAsync = function MultiSelectMetaAsync(_ref) {
39206
39321
  };
39207
39322
  var optionTemplate = function optionTemplate(option) {
39208
39323
  if (!option) return null;
39209
- var _ref3 = selectMetaConfig || {};
39210
- _ref3.labelStyle;
39211
- var generalIcon = _ref3.generalIcon;
39324
+ console.log(option);
39325
+ var _ref5 = selectMetaConfig || {};
39326
+ _ref5.labelStyle;
39327
+ var generalIcon = _ref5.generalIcon;
39212
39328
  var styleLabel = {
39213
39329
  marginLeft: '10px'
39214
39330
  };
39215
39331
  return /*#__PURE__*/React__default.createElement("div", {
39332
+ onClick: function onClick() {
39333
+ clickedFromList.current = true;
39334
+ },
39216
39335
  style: _objectSpread2({
39217
39336
  fontFamily: 'Arial',
39218
39337
  fontSize: '14px',
@@ -39229,16 +39348,16 @@ var MultiSelectMetaAsync = function MultiSelectMetaAsync(_ref) {
39229
39348
  style: styleLabel
39230
39349
  }, option[optionLabel]));
39231
39350
  };
39232
- var selectedItemTemplate = function selectedItemTemplate(optionValue, index) {
39351
+ var selectedItemTemplate = function selectedItemTemplate(paramValue, index) {
39233
39352
  var selectedOption = loadedOptions.find(function (opt) {
39234
- return opt.value === optionValue;
39353
+ return opt[optionValue] === paramValue;
39235
39354
  });
39236
39355
  if (!selectedOption) return null;
39237
39356
  // const isLastItem = index === selectedOptions.length - 1;
39238
39357
  var handleRemove = function handleRemove(e) {
39239
39358
  e.stopPropagation();
39240
39359
  var newSelectedOptions = selectedOptions.filter(function (opt) {
39241
- return opt !== optionValue;
39360
+ return opt !== paramValue;
39242
39361
  });
39243
39362
  setSelectedOptions(newSelectedOptions);
39244
39363
  if (onChange) onChange(newSelectedOptions);
@@ -39272,20 +39391,45 @@ var MultiSelectMetaAsync = function MultiSelectMetaAsync(_ref) {
39272
39391
  if (loadLazyTimeout.current) {
39273
39392
  clearTimeout(loadLazyTimeout.current);
39274
39393
  }
39275
- loadLazyTimeout.current = setTimeout(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2() {
39394
+ loadLazyTimeout.current = setTimeout(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3() {
39395
+ var _result3;
39276
39396
  var first, last, _items, result, newOptions, i, virtualscroll;
39277
- return _regenerator().w(function (_context2) {
39278
- while (1) switch (_context2.n) {
39397
+ return _regenerator().w(function (_context3) {
39398
+ while (1) switch (_context3.n) {
39279
39399
  case 0:
39280
39400
  first = event.first, last = event.last;
39281
39401
  _items = _toConsumableArray$7(loadedOptions);
39282
- _context2.n = 1;
39283
- return options(inputValue, [], {
39402
+ if (!(typeof options === 'function')) {
39403
+ _context3.n = 2;
39404
+ break;
39405
+ }
39406
+ _context3.n = 1;
39407
+ return options("", [], {
39284
39408
  page: currentPageRef.current + 1
39285
39409
  });
39286
39410
  case 1:
39287
- result = _context2.v;
39288
- newOptions = (result === null || result === void 0 ? void 0 : result.options) || [];
39411
+ result = _context3.v;
39412
+ _context3.n = 5;
39413
+ break;
39414
+ case 2:
39415
+ if (!optionsUrl) {
39416
+ _context3.n = 4;
39417
+ break;
39418
+ }
39419
+ _context3.n = 3;
39420
+ return fetchOptionsFromUrl("", [], {
39421
+ page: currentPageRef.current + 1
39422
+ });
39423
+ case 3:
39424
+ result = _context3.v;
39425
+ _context3.n = 5;
39426
+ break;
39427
+ case 4:
39428
+ result = {
39429
+ options: []
39430
+ };
39431
+ case 5:
39432
+ newOptions = ((_result3 = result) === null || _result3 === void 0 ? void 0 : _result3.options) || [];
39289
39433
  for (i = first; i < last; i++) {
39290
39434
  if (!_items[i] && newOptions[i - first]) {
39291
39435
  _items[i] = newOptions[i - first];
@@ -39294,16 +39438,15 @@ var MultiSelectMetaAsync = function MultiSelectMetaAsync(_ref) {
39294
39438
  setLoadedOptions(_items);
39295
39439
  setLoading(false);
39296
39440
  currentPageRef.current += 1;
39297
-
39298
- // redimensionnement du conteneur
39441
+ // Redimensionnement du conteneur
39299
39442
  virtualscroll = document.querySelector('.p-virtualscroller.p-dropdown-items-wrapper');
39300
39443
  if (virtualscroll) {
39301
39444
  virtualscroll.style.height = "auto";
39302
39445
  }
39303
- case 2:
39304
- return _context2.a(2);
39446
+ case 6:
39447
+ return _context3.a(2);
39305
39448
  }
39306
- }, _callee2);
39449
+ }, _callee3);
39307
39450
  })), 500);
39308
39451
  };
39309
39452
  return /*#__PURE__*/React__default.createElement("div", {
@@ -39665,11 +39808,6 @@ var MultiSelect = function MultiSelect(props) {
39665
39808
  }, errorMessage || 'Sélection invalide')));
39666
39809
  };
39667
39810
 
39668
- var simulateNetworkDelay = function simulateNetworkDelay() {
39669
- return new Promise(function (res) {
39670
- return setTimeout(res, 400);
39671
- });
39672
- };
39673
39811
  var optionsExample = [{
39674
39812
  label: 'New York',
39675
39813
  value: 'NY'
@@ -39756,17 +39894,6 @@ var syncOptions$1 = [{
39756
39894
  value: '5',
39757
39895
  color: '#ec4899'
39758
39896
  }];
39759
- var createFakeOptions = function createFakeOptions(start, length) {
39760
- var options = [];
39761
- for (var i = start; i < start + length; i++) {
39762
- options.push({
39763
- value: i,
39764
- label: "Option ".concat(i),
39765
- color: 'black'
39766
- });
39767
- }
39768
- return options;
39769
- };
39770
39897
  var MultiSelectPresets = {
39771
39898
  Default: {
39772
39899
  placeholder: 'Sélectionnez des options',
@@ -39851,81 +39978,37 @@ var MultiSelectPresets = {
39851
39978
  // Configuration pour les options asynchrones
39852
39979
  SelectMetaAsync: {
39853
39980
  isSelectMeta: true,
39981
+ // value: [9, 4],
39982
+ // objValue: [{ label: 'Option 9', value: 9, color: "#67688C" }, { label: 'Option 4', value: 4, color: "#39C9BF" }],
39983
+ // options: async (search = '', _, { page }) => {
39984
+ // await simulateNetworkDelay();
39985
+ // const allOptions = createFakeOptions(0, 100);
39986
+ // const filtered = allOptions.filter(opt =>
39987
+ // opt.label.toLowerCase().includes(search.toLowerCase())
39988
+ // );
39989
+ // const pageSize = 30;
39990
+ // const start = (page - 1) * pageSize;
39991
+ // return {
39992
+ // options: filtered.slice(start, start + pageSize),
39993
+ // hasMore: start + pageSize < filtered.length,
39994
+ // additional: { page: page + 1 },
39995
+ // };
39996
+ // },
39997
+ // optionLabel: 'label',
39998
+ // optionValue: 'value',
39999
+
40000
+ value: [3, 4],
39854
40001
  objValue: [{
39855
- label: 'Option 9',
39856
- value: 9,
39857
- color: "#67688C"
40002
+ name: 'Clementine Bauch',
40003
+ id: 3
39858
40004
  }, {
39859
- label: 'Option 4',
39860
- value: 4,
39861
- color: "#39C9BF"
40005
+ name: 'Patricia Lebsack',
40006
+ id: 4
39862
40007
  }],
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
- options: function () {
39888
- var _options = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2() {
39889
- var search,
39890
- _ref3,
39891
- page,
39892
- allOptions,
39893
- filtered,
39894
- pageSize,
39895
- start,
39896
- _args2 = arguments;
39897
- return _regenerator().w(function (_context2) {
39898
- while (1) switch (_context2.n) {
39899
- case 0:
39900
- search = _args2.length > 0 && _args2[0] !== undefined ? _args2[0] : '';
39901
- _ref3 = _args2.length > 2 ? _args2[2] : undefined, page = _ref3.page;
39902
- _context2.n = 1;
39903
- return simulateNetworkDelay();
39904
- case 1:
39905
- allOptions = createFakeOptions(0, 100);
39906
- filtered = allOptions.filter(function (opt) {
39907
- return opt.label.toLowerCase().includes(search.toLowerCase());
39908
- });
39909
- pageSize = 30;
39910
- start = (page - 1) * pageSize;
39911
- return _context2.a(2, {
39912
- options: filtered.slice(start, start + pageSize),
39913
- hasMore: start + pageSize < filtered.length,
39914
- additional: {
39915
- page: page + 1
39916
- }
39917
- });
39918
- }
39919
- }, _callee2);
39920
- }));
39921
- function options() {
39922
- return _options.apply(this, arguments);
39923
- }
39924
- return options;
39925
- }(),
40008
+ optionsUrl: "https://jsonplaceholder.typicode.com/users",
40009
+ optionLabel: 'name',
40010
+ optionValue: 'id',
39926
40011
  placeholder: 'Sélectionnez une ou plusieurs options',
39927
- optionLabel: 'label',
39928
- optionValue: 'value',
39929
40012
  valueStyle: {
39930
40013
  marginRight: '15px',
39931
40014
  marginBottom: '5px'
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "arengibook",
3
3
  "private": false,
4
- "version": "2.4.635",
4
+ "version": "2.4.637",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
7
7
  "exports": {