reneco-hierarchized-picker 0.4.2-beta.14 → 0.4.2-beta.15

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.
@@ -339,9 +339,11 @@ Tree.prototype.bindEvent = function (ele) {
339
339
  // If source is webservice (it shouldn't be something else)
340
340
  if (this.options.parentApi.theOptions.source == 'webservice') {
341
341
  if (this.options.parentApi.theOptions.origin == 'classification') {
342
+ const contextualApiParams = this.options.parentApi.getContextualApiParams(Object.assign(Object.assign({}, this.options.parentApi.theOptions.options), { startNode: target.parentNode.nodeId }));
343
+ const contextualApiURL = this.options.parentApi.getContextualApiURL();
342
344
  // WS Call
343
345
  this.options.rawDataManager
344
- .getFromClassification(this.options.parentApi.getContextualApiURL(), this.options.parentApi.getContextualApiParams(Object.assign(Object.assign({}, this.options.parentApi.theOptions.options), { startNode: target.parentNode.nodeId })), document.querySelector("#hierarchized-picker-" + this.options.parentApi.componentID + ".loader"))
346
+ .getFromClassification(contextualApiURL, contextualApiParams, document.querySelector("#hierarchized-picker-" + this.options.parentApi.componentID + ".loader"))
345
347
  .then(data => {
346
348
  this.options.completeCurrentTreeWithTree(this, data, this.options.parentApi.theOptions);
347
349
  });
@@ -18192,7 +18194,7 @@ class RawDataManager {
18192
18194
  continue;
18193
18195
  const value = options[key];
18194
18196
  const lowerKey = key.toLowerCase();
18195
- if ((lowerKey === 'startnode' || lowerKey === 'startnodeid') && !pathSegment) {
18197
+ if ((lowerKey === 'startnode') && !pathSegment) {
18196
18198
  pathSegment = encodeURIComponent(value);
18197
18199
  continue; // Skip adding this to the query string
18198
18200
  }
@@ -18279,8 +18281,16 @@ class RawDataManager {
18279
18281
  * Merge new data into the existing data.
18280
18282
  * @param newData New data to merge.
18281
18283
  */
18282
- mergeData(newData) {
18283
- this.rawData = this.genericMerge(this.rawData || {}, newData, 'key', 'children');
18284
+ mergeData(newData, idKey) {
18285
+ if (!this.rawData)
18286
+ this.rawData = newData;
18287
+ else {
18288
+ this.rawData = this.genericMerge(this.rawData, newData, idKey, 'children');
18289
+ }
18290
+ }
18291
+ reorderItems(referenceArray, toReorderArray, idKey) {
18292
+ const idMap = new Map(toReorderArray.map(item => [item[idKey], item]));
18293
+ return referenceArray.map(refItem => idMap.get(refItem[idKey])).filter(Boolean);
18284
18294
  }
18285
18295
  /**
18286
18296
  * Generic merge method.
@@ -18296,9 +18306,11 @@ class RawDataManager {
18296
18306
  }
18297
18307
  if (!toAdd || !((_a = toAdd[childrenKey]) === null || _a === void 0 ? void 0 : _a.length))
18298
18308
  return source;
18309
+ if (source[childrenKey] && source[childrenKey].length > 0 && toAdd[childrenKey] && toAdd[childrenKey].length > 0)
18310
+ toAdd[childrenKey] = this.reorderItems(source[childrenKey], toAdd[childrenKey], idKey);
18299
18311
  source[childrenKey] = ((_b = source[childrenKey]) === null || _b === void 0 ? void 0 : _b.length)
18300
18312
  ? source[childrenKey].map((child, index) => {
18301
- return this.genericMerge(child, toAdd[childrenKey].filter(item => item.key == child.key)[0], idKey, childrenKey);
18313
+ return this.genericMerge(child, toAdd[childrenKey].filter(item => item.key == child.key)[index], idKey, childrenKey);
18302
18314
  })
18303
18315
  : toAdd[childrenKey];
18304
18316
  return source;
@@ -18368,6 +18380,12 @@ class OptionsManager {
18368
18380
  delete this.options.defaultValue;
18369
18381
  }
18370
18382
  }
18383
+ // This method is pretty ugly and shouldn't have to be called, but temporarily works until a better solution is set
18384
+ dropReach() {
18385
+ if (this.options.options && this.options.options.Reach) {
18386
+ delete this.options.options.Reach;
18387
+ }
18388
+ }
18371
18389
  }
18372
18390
 
18373
18391
  /**
@@ -18422,7 +18440,7 @@ function fillTreeWithObject(tree, myObject, searched, options, depth = 0) {
18422
18440
  const searchResultPresentsUnMatched = options.searchResultPresentsUnMatched;
18423
18441
  if (myObject && myObject.length) {
18424
18442
  myObject.forEach(value => {
18425
- var _a, _b, _c, _d, _e;
18443
+ var _a, _b, _c;
18426
18444
  let keyPropFromNode = null;
18427
18445
  let valueTranslatedPropFromNode = null;
18428
18446
  let fullpathPropFromNode = null;
@@ -18430,15 +18448,8 @@ function fillTreeWithObject(tree, myObject, searched, options, depth = 0) {
18430
18448
  if (options.origin == "classification") {
18431
18449
  keyPropFromNode = getPropertyFromNode(value, 'ID');
18432
18450
  valueTranslatedPropFromNode = (_a = getPropertyFromNode(value, 'Translations')[options.language]) === null || _a === void 0 ? void 0 : _a.translated_name;
18433
- // TODO Not sure this is correct in the latest versions, may require review during second half of 2025
18434
- if (searched) {
18435
- fullpathPropFromNode = (_b = getPropertyFromNode(value, 'Properties')) === null || _b === void 0 ? void 0 : _b.System_FullPath;
18436
- fullpathTranslatedPropFromNode = (_c = getPropertyFromNode(value, 'fullpathTranslated')[options.language]) === null || _c === void 0 ? void 0 : _c.translated_fullpath;
18437
- }
18438
- else {
18439
- fullpathPropFromNode = (_d = getPropertyFromNode(value, 'Properties')) === null || _d === void 0 ? void 0 : _d.System_Fullpath;
18440
- fullpathTranslatedPropFromNode = (_e = getPropertyFromNode(value, 'Translations')[options.language]) === null || _e === void 0 ? void 0 : _e.translated_fullpath;
18441
- }
18451
+ fullpathPropFromNode = (_b = getPropertyFromNode(value, 'Properties')) === null || _b === void 0 ? void 0 : _b.System_Fullpath;
18452
+ fullpathTranslatedPropFromNode = (_c = getPropertyFromNode(value, 'Translations')[options.language]) === null || _c === void 0 ? void 0 : _c.translated_fullpath;
18442
18453
  }
18443
18454
  else {
18444
18455
  keyPropFromNode = getPropertyFromNode(value, 'key');
@@ -19127,15 +19138,15 @@ const HierarchizedPickerComponent = class {
19127
19138
  const pathSegments = parsedUrl.pathname.split('/');
19128
19139
  const dynamicType = pathSegments[pathSegments.length - 2];
19129
19140
  const newPathname = `/api/v1/classification/reach/${dynamicType}/${options.Reach}`;
19141
+ this.optionsManager.dropReach();
19130
19142
  return `${parsedUrl.origin}${newPathname}`;
19131
19143
  }
19132
19144
  return url;
19133
19145
  }
19134
- getContextualApiParams(options = null) {
19135
- if (!options)
19136
- options = this.optionsManager.getOptions().options;
19146
+ getContextualApiParams(search = null) {
19147
+ const options = this.optionsManager.getOptions().options;
19148
+ let optionsToReturn = Object.assign({}, options);
19137
19149
  if (options.Reach) {
19138
- let optionsToReturn = Object.assign({}, options);
19139
19150
  delete optionsToReturn.Reach;
19140
19151
  if ("startNode" in optionsToReturn) {
19141
19152
  optionsToReturn.startingnode = optionsToReturn.startNode;
@@ -19145,10 +19156,17 @@ const HierarchizedPickerComponent = class {
19145
19156
  optionsToReturn.startingnode = optionsToReturn.StartNodeID;
19146
19157
  delete optionsToReturn.StartNodeID;
19147
19158
  }
19148
- return optionsToReturn;
19159
+ }
19160
+ else if (search) {
19161
+ optionsToReturn.searchedValue = search;
19162
+ if ("startNode" in optionsToReturn) {
19163
+ optionsToReturn.StartNodeID = optionsToReturn.startNode;
19164
+ delete optionsToReturn.startNode;
19165
+ }
19149
19166
  }
19150
19167
  else
19151
19168
  return options;
19169
+ return optionsToReturn;
19152
19170
  }
19153
19171
  translateDataForTree(dataToLoad, searchID = null, searched = null) {
19154
19172
  if (searched && searched != "") {
@@ -19161,7 +19179,7 @@ const HierarchizedPickerComponent = class {
19161
19179
  loadSearchDataInCurrentTree(searchID, searched) {
19162
19180
  let displayResults = (newtree) => {
19163
19181
  if (this.searchToDisplay > -1) { // TODO > Not working anymore after refact, prevents issues in displaying results when running multiple researchs at the same time && searchID == this.searchToDisplay) {
19164
- this.rawDataManager.mergeData(newtree);
19182
+ this.rawDataManager.mergeData(newtree, this.theOptions.origin == 'classification' ? "ID" : "key");
19165
19183
  newtree.children.forEach((value, index) => {
19166
19184
  completeCurrentTreeWithTree(this.loadedTreeJs, value, this.optionsManager.getOptions());
19167
19185
  });
@@ -19183,9 +19201,7 @@ const HierarchizedPickerComponent = class {
19183
19201
  if (this.theOptions.source == 'webservice') {
19184
19202
  if (this.theOptions.origin == 'classification') {
19185
19203
  // WS Call
19186
- this.rawDataManager.getFromClassification(this.getApiSearchURL(), {
19187
- searchedValue: searched
19188
- }, document.querySelector("#hierarchized-picker-" + this.componentID + ".loader"))
19204
+ this.rawDataManager.getFromClassification(this.getApiSearchURL(), Object.assign({}, this.getContextualApiParams(searched)), document.querySelector("#hierarchized-picker-" + this.componentID + ".loader"))
19189
19205
  .then((data) => {
19190
19206
  displayResults(data);
19191
19207
  if (!searched) {
@@ -19334,19 +19350,24 @@ const HierarchizedPickerComponent = class {
19334
19350
  // ----- BEGIN -----
19335
19351
  let node = treeToUpdate.nodesById[id];
19336
19352
  let onChange = treeToUpdate.options.onChange;
19337
- if (!node.disabled) {
19338
- treeToUpdate.setValue(id);
19339
- treeToUpdate.updateLiElements();
19353
+ if (!node) {
19354
+ this.logError("The current selected value is not part of the loaded tree!");
19340
19355
  }
19341
- userClick && onChange && onChange.call(treeToUpdate);
19342
- // ------ END ------
19343
- if (this.setValueOnClick) {
19344
- this.editValue(node, userClick);
19345
- if (this.shownTree && userClick) {
19346
- // TODO > is this required ?
19347
- // await focusMainInput(this);
19348
- if (!this.optionsManager.getOptions().multiple) {
19349
- this.showTree('hide');
19356
+ else {
19357
+ if (!node.disabled) {
19358
+ treeToUpdate.setValue(id);
19359
+ treeToUpdate.updateLiElements();
19360
+ }
19361
+ userClick && onChange && onChange.call(treeToUpdate);
19362
+ // ------ END ------
19363
+ if (this.setValueOnClick) {
19364
+ this.editValue(node, userClick);
19365
+ if (this.shownTree && userClick) {
19366
+ // TODO > is this required ?
19367
+ // await focusMainInput(this);
19368
+ if (!this.optionsManager.getOptions().multiple) {
19369
+ this.showTree('hide');
19370
+ }
19350
19371
  }
19351
19372
  }
19352
19373
  }
@@ -19479,6 +19500,7 @@ const HierarchizedPickerComponent = class {
19479
19500
  }
19480
19501
  // Search a value in the tree and triggers a search when necessary
19481
19502
  search(searched) {
19503
+ this.loader.classList.add('loading');
19482
19504
  let searchinput = document.querySelector('#hierarchized-picker-' + this.componentID + ' .hierarchized-picker-search input');
19483
19505
  if (this.optionsManager.getOptions().mode == 'input' && searchinput) {
19484
19506
  searchinput.classList.remove('fieldError');
@@ -19515,6 +19537,7 @@ const HierarchizedPickerComponent = class {
19515
19537
  // this.checkFields(this.value, false);
19516
19538
  this.setSearchResults([]);
19517
19539
  }
19540
+ this.loader.classList.remove('loading');
19518
19541
  }
19519
19542
  // Refresh the tree with search results
19520
19543
  triggerSearch(searched) {
@@ -19533,7 +19556,9 @@ const HierarchizedPickerComponent = class {
19533
19556
  loadDataForTree(init, loader) {
19534
19557
  if (this.optionsManager.getOptions().source == 'webservice') {
19535
19558
  if (this.optionsManager.getOptions().origin == 'classification') {
19536
- this.rawDataManager.getFromClassification(this.getContextualApiURL(), this.getContextualApiParams(), loader).then((data) => {
19559
+ const contextualApiParams = this.getContextualApiParams();
19560
+ const contextualApiURL = this.getContextualApiURL();
19561
+ this.rawDataManager.getFromClassification(contextualApiURL, contextualApiParams, loader).then((data) => {
19537
19562
  this.rawData = data;
19538
19563
  if (init) {
19539
19564
  this.formatDefaultValue();
@@ -459,15 +459,15 @@ export class HierarchizedPickerComponent {
459
459
  const pathSegments = parsedUrl.pathname.split('/');
460
460
  const dynamicType = pathSegments[pathSegments.length - 2];
461
461
  const newPathname = `/api/v1/classification/reach/${dynamicType}/${options.Reach}`;
462
+ this.optionsManager.dropReach();
462
463
  return `${parsedUrl.origin}${newPathname}`;
463
464
  }
464
465
  return url;
465
466
  }
466
- getContextualApiParams(options = null) {
467
- if (!options)
468
- options = this.optionsManager.getOptions().options;
467
+ getContextualApiParams(search = null) {
468
+ const options = this.optionsManager.getOptions().options;
469
+ let optionsToReturn = Object.assign({}, options);
469
470
  if (options.Reach) {
470
- let optionsToReturn = Object.assign({}, options);
471
471
  delete optionsToReturn.Reach;
472
472
  if ("startNode" in optionsToReturn) {
473
473
  optionsToReturn.startingnode = optionsToReturn.startNode;
@@ -477,10 +477,17 @@ export class HierarchizedPickerComponent {
477
477
  optionsToReturn.startingnode = optionsToReturn.StartNodeID;
478
478
  delete optionsToReturn.StartNodeID;
479
479
  }
480
- return optionsToReturn;
480
+ }
481
+ else if (search) {
482
+ optionsToReturn.searchedValue = search;
483
+ if ("startNode" in optionsToReturn) {
484
+ optionsToReturn.StartNodeID = optionsToReturn.startNode;
485
+ delete optionsToReturn.startNode;
486
+ }
481
487
  }
482
488
  else
483
489
  return options;
490
+ return optionsToReturn;
484
491
  }
485
492
  translateDataForTree(dataToLoad, searchID = null, searched = null) {
486
493
  if (searched && searched != "") {
@@ -493,7 +500,7 @@ export class HierarchizedPickerComponent {
493
500
  loadSearchDataInCurrentTree(searchID, searched) {
494
501
  let displayResults = (newtree) => {
495
502
  if (this.searchToDisplay > -1) { // TODO > Not working anymore after refact, prevents issues in displaying results when running multiple researchs at the same time && searchID == this.searchToDisplay) {
496
- this.rawDataManager.mergeData(newtree);
503
+ this.rawDataManager.mergeData(newtree, this.theOptions.origin == 'classification' ? "ID" : "key");
497
504
  newtree.children.forEach((value, index) => {
498
505
  completeCurrentTreeWithTree(this.loadedTreeJs, value, this.optionsManager.getOptions());
499
506
  });
@@ -515,9 +522,7 @@ export class HierarchizedPickerComponent {
515
522
  if (this.theOptions.source == 'webservice') {
516
523
  if (this.theOptions.origin == 'classification') {
517
524
  // WS Call
518
- this.rawDataManager.getFromClassification(this.getApiSearchURL(), {
519
- searchedValue: searched
520
- }, document.querySelector("#hierarchized-picker-" + this.componentID + ".loader"))
525
+ this.rawDataManager.getFromClassification(this.getApiSearchURL(), Object.assign({}, this.getContextualApiParams(searched)), document.querySelector("#hierarchized-picker-" + this.componentID + ".loader"))
521
526
  .then((data) => {
522
527
  displayResults(data);
523
528
  if (!searched) {
@@ -666,19 +671,24 @@ export class HierarchizedPickerComponent {
666
671
  // ----- BEGIN -----
667
672
  let node = treeToUpdate.nodesById[id];
668
673
  let onChange = treeToUpdate.options.onChange;
669
- if (!node.disabled) {
670
- treeToUpdate.setValue(id);
671
- treeToUpdate.updateLiElements();
672
- }
673
- userClick && onChange && onChange.call(treeToUpdate);
674
- // ------ END ------
675
- if (this.setValueOnClick) {
676
- this.editValue(node, userClick);
677
- if (this.shownTree && userClick) {
678
- // TODO > is this required ?
679
- // await focusMainInput(this);
680
- if (!this.optionsManager.getOptions().multiple) {
681
- this.showTree('hide');
674
+ if (!node) {
675
+ this.logError("The current selected value is not part of the loaded tree!");
676
+ }
677
+ else {
678
+ if (!node.disabled) {
679
+ treeToUpdate.setValue(id);
680
+ treeToUpdate.updateLiElements();
681
+ }
682
+ userClick && onChange && onChange.call(treeToUpdate);
683
+ // ------ END ------
684
+ if (this.setValueOnClick) {
685
+ this.editValue(node, userClick);
686
+ if (this.shownTree && userClick) {
687
+ // TODO > is this required ?
688
+ // await focusMainInput(this);
689
+ if (!this.optionsManager.getOptions().multiple) {
690
+ this.showTree('hide');
691
+ }
682
692
  }
683
693
  }
684
694
  }
@@ -811,6 +821,7 @@ export class HierarchizedPickerComponent {
811
821
  }
812
822
  // Search a value in the tree and triggers a search when necessary
813
823
  search(searched) {
824
+ this.loader.classList.add('loading');
814
825
  let searchinput = document.querySelector('#hierarchized-picker-' + this.componentID + ' .hierarchized-picker-search input');
815
826
  if (this.optionsManager.getOptions().mode == 'input' && searchinput) {
816
827
  searchinput.classList.remove('fieldError');
@@ -847,6 +858,7 @@ export class HierarchizedPickerComponent {
847
858
  // this.checkFields(this.value, false);
848
859
  this.setSearchResults([]);
849
860
  }
861
+ this.loader.classList.remove('loading');
850
862
  }
851
863
  // Refresh the tree with search results
852
864
  triggerSearch(searched) {
@@ -865,7 +877,9 @@ export class HierarchizedPickerComponent {
865
877
  loadDataForTree(init, loader) {
866
878
  if (this.optionsManager.getOptions().source == 'webservice') {
867
879
  if (this.optionsManager.getOptions().origin == 'classification') {
868
- this.rawDataManager.getFromClassification(this.getContextualApiURL(), this.getContextualApiParams(), loader).then((data) => {
880
+ const contextualApiParams = this.getContextualApiParams();
881
+ const contextualApiURL = this.getContextualApiURL();
882
+ this.rawDataManager.getFromClassification(contextualApiURL, contextualApiParams, loader).then((data) => {
869
883
  this.rawData = data;
870
884
  if (init) {
871
885
  this.formatDefaultValue();
@@ -207,9 +207,11 @@ Tree.prototype.bindEvent = function (ele) {
207
207
  // If source is webservice (it shouldn't be something else)
208
208
  if (this.options.parentApi.theOptions.source == 'webservice') {
209
209
  if (this.options.parentApi.theOptions.origin == 'classification') {
210
+ const contextualApiParams = this.options.parentApi.getContextualApiParams(Object.assign(Object.assign({}, this.options.parentApi.theOptions.options), { startNode: target.parentNode.nodeId }));
211
+ const contextualApiURL = this.options.parentApi.getContextualApiURL();
210
212
  // WS Call
211
213
  this.options.rawDataManager
212
- .getFromClassification(this.options.parentApi.getContextualApiURL(), this.options.parentApi.getContextualApiParams(Object.assign(Object.assign({}, this.options.parentApi.theOptions.options), { startNode: target.parentNode.nodeId })), document.querySelector("#hierarchized-picker-" + this.options.parentApi.componentID + ".loader"))
214
+ .getFromClassification(contextualApiURL, contextualApiParams, document.querySelector("#hierarchized-picker-" + this.options.parentApi.componentID + ".loader"))
213
215
  .then(data => {
214
216
  this.options.completeCurrentTreeWithTree(this, data, this.options.parentApi.theOptions);
215
217
  });
@@ -45,4 +45,10 @@ export class OptionsManager {
45
45
  delete this.options.defaultValue;
46
46
  }
47
47
  }
48
+ // This method is pretty ugly and shouldn't have to be called, but temporarily works until a better solution is set
49
+ dropReach() {
50
+ if (this.options.options && this.options.options.Reach) {
51
+ delete this.options.options.Reach;
52
+ }
53
+ }
48
54
  }
@@ -62,7 +62,7 @@ export class RawDataManager {
62
62
  continue;
63
63
  const value = options[key];
64
64
  const lowerKey = key.toLowerCase();
65
- if ((lowerKey === 'startnode' || lowerKey === 'startnodeid') && !pathSegment) {
65
+ if ((lowerKey === 'startnode') && !pathSegment) {
66
66
  pathSegment = encodeURIComponent(value);
67
67
  continue; // Skip adding this to the query string
68
68
  }
@@ -149,8 +149,16 @@ export class RawDataManager {
149
149
  * Merge new data into the existing data.
150
150
  * @param newData New data to merge.
151
151
  */
152
- mergeData(newData) {
153
- this.rawData = this.genericMerge(this.rawData || {}, newData, 'key', 'children');
152
+ mergeData(newData, idKey) {
153
+ if (!this.rawData)
154
+ this.rawData = newData;
155
+ else {
156
+ this.rawData = this.genericMerge(this.rawData, newData, idKey, 'children');
157
+ }
158
+ }
159
+ reorderItems(referenceArray, toReorderArray, idKey) {
160
+ const idMap = new Map(toReorderArray.map(item => [item[idKey], item]));
161
+ return referenceArray.map(refItem => idMap.get(refItem[idKey])).filter(Boolean);
154
162
  }
155
163
  /**
156
164
  * Generic merge method.
@@ -166,9 +174,11 @@ export class RawDataManager {
166
174
  }
167
175
  if (!toAdd || !((_a = toAdd[childrenKey]) === null || _a === void 0 ? void 0 : _a.length))
168
176
  return source;
177
+ if (source[childrenKey] && source[childrenKey].length > 0 && toAdd[childrenKey] && toAdd[childrenKey].length > 0)
178
+ toAdd[childrenKey] = this.reorderItems(source[childrenKey], toAdd[childrenKey], idKey);
169
179
  source[childrenKey] = ((_b = source[childrenKey]) === null || _b === void 0 ? void 0 : _b.length)
170
180
  ? source[childrenKey].map((child, index) => {
171
- return this.genericMerge(child, toAdd[childrenKey].filter(item => item.key == child.key)[0], idKey, childrenKey);
181
+ return this.genericMerge(child, toAdd[childrenKey].filter(item => item.key == child.key)[index], idKey, childrenKey);
172
182
  })
173
183
  : toAdd[childrenKey];
174
184
  return source;
@@ -51,7 +51,7 @@ export function fillTreeWithObject(tree, myObject, searched, options, depth = 0)
51
51
  const searchResultPresentsUnMatched = options.searchResultPresentsUnMatched;
52
52
  if (myObject && myObject.length) {
53
53
  myObject.forEach(value => {
54
- var _a, _b, _c, _d, _e;
54
+ var _a, _b, _c;
55
55
  let keyPropFromNode = null;
56
56
  let valueTranslatedPropFromNode = null;
57
57
  let fullpathPropFromNode = null;
@@ -59,15 +59,8 @@ export function fillTreeWithObject(tree, myObject, searched, options, depth = 0)
59
59
  if (options.origin == "classification") {
60
60
  keyPropFromNode = getPropertyFromNode(value, 'ID');
61
61
  valueTranslatedPropFromNode = (_a = getPropertyFromNode(value, 'Translations')[options.language]) === null || _a === void 0 ? void 0 : _a.translated_name;
62
- // TODO Not sure this is correct in the latest versions, may require review during second half of 2025
63
- if (searched) {
64
- fullpathPropFromNode = (_b = getPropertyFromNode(value, 'Properties')) === null || _b === void 0 ? void 0 : _b.System_FullPath;
65
- fullpathTranslatedPropFromNode = (_c = getPropertyFromNode(value, 'fullpathTranslated')[options.language]) === null || _c === void 0 ? void 0 : _c.translated_fullpath;
66
- }
67
- else {
68
- fullpathPropFromNode = (_d = getPropertyFromNode(value, 'Properties')) === null || _d === void 0 ? void 0 : _d.System_Fullpath;
69
- fullpathTranslatedPropFromNode = (_e = getPropertyFromNode(value, 'Translations')[options.language]) === null || _e === void 0 ? void 0 : _e.translated_fullpath;
70
- }
62
+ fullpathPropFromNode = (_b = getPropertyFromNode(value, 'Properties')) === null || _b === void 0 ? void 0 : _b.System_Fullpath;
63
+ fullpathTranslatedPropFromNode = (_c = getPropertyFromNode(value, 'Translations')[options.language]) === null || _c === void 0 ? void 0 : _c.translated_fullpath;
71
64
  }
72
65
  else {
73
66
  keyPropFromNode = getPropertyFromNode(value, 'key');
@@ -336,9 +336,11 @@ Tree.prototype.bindEvent = function (ele) {
336
336
  // If source is webservice (it shouldn't be something else)
337
337
  if (this.options.parentApi.theOptions.source == 'webservice') {
338
338
  if (this.options.parentApi.theOptions.origin == 'classification') {
339
+ const contextualApiParams = this.options.parentApi.getContextualApiParams(Object.assign(Object.assign({}, this.options.parentApi.theOptions.options), { startNode: target.parentNode.nodeId }));
340
+ const contextualApiURL = this.options.parentApi.getContextualApiURL();
339
341
  // WS Call
340
342
  this.options.rawDataManager
341
- .getFromClassification(this.options.parentApi.getContextualApiURL(), this.options.parentApi.getContextualApiParams(Object.assign(Object.assign({}, this.options.parentApi.theOptions.options), { startNode: target.parentNode.nodeId })), document.querySelector("#hierarchized-picker-" + this.options.parentApi.componentID + ".loader"))
343
+ .getFromClassification(contextualApiURL, contextualApiParams, document.querySelector("#hierarchized-picker-" + this.options.parentApi.componentID + ".loader"))
342
344
  .then(data => {
343
345
  this.options.completeCurrentTreeWithTree(this, data, this.options.parentApi.theOptions);
344
346
  });
@@ -18189,7 +18191,7 @@ class RawDataManager {
18189
18191
  continue;
18190
18192
  const value = options[key];
18191
18193
  const lowerKey = key.toLowerCase();
18192
- if ((lowerKey === 'startnode' || lowerKey === 'startnodeid') && !pathSegment) {
18194
+ if ((lowerKey === 'startnode') && !pathSegment) {
18193
18195
  pathSegment = encodeURIComponent(value);
18194
18196
  continue; // Skip adding this to the query string
18195
18197
  }
@@ -18276,8 +18278,16 @@ class RawDataManager {
18276
18278
  * Merge new data into the existing data.
18277
18279
  * @param newData New data to merge.
18278
18280
  */
18279
- mergeData(newData) {
18280
- this.rawData = this.genericMerge(this.rawData || {}, newData, 'key', 'children');
18281
+ mergeData(newData, idKey) {
18282
+ if (!this.rawData)
18283
+ this.rawData = newData;
18284
+ else {
18285
+ this.rawData = this.genericMerge(this.rawData, newData, idKey, 'children');
18286
+ }
18287
+ }
18288
+ reorderItems(referenceArray, toReorderArray, idKey) {
18289
+ const idMap = new Map(toReorderArray.map(item => [item[idKey], item]));
18290
+ return referenceArray.map(refItem => idMap.get(refItem[idKey])).filter(Boolean);
18281
18291
  }
18282
18292
  /**
18283
18293
  * Generic merge method.
@@ -18293,9 +18303,11 @@ class RawDataManager {
18293
18303
  }
18294
18304
  if (!toAdd || !((_a = toAdd[childrenKey]) === null || _a === void 0 ? void 0 : _a.length))
18295
18305
  return source;
18306
+ if (source[childrenKey] && source[childrenKey].length > 0 && toAdd[childrenKey] && toAdd[childrenKey].length > 0)
18307
+ toAdd[childrenKey] = this.reorderItems(source[childrenKey], toAdd[childrenKey], idKey);
18296
18308
  source[childrenKey] = ((_b = source[childrenKey]) === null || _b === void 0 ? void 0 : _b.length)
18297
18309
  ? source[childrenKey].map((child, index) => {
18298
- return this.genericMerge(child, toAdd[childrenKey].filter(item => item.key == child.key)[0], idKey, childrenKey);
18310
+ return this.genericMerge(child, toAdd[childrenKey].filter(item => item.key == child.key)[index], idKey, childrenKey);
18299
18311
  })
18300
18312
  : toAdd[childrenKey];
18301
18313
  return source;
@@ -18365,6 +18377,12 @@ class OptionsManager {
18365
18377
  delete this.options.defaultValue;
18366
18378
  }
18367
18379
  }
18380
+ // This method is pretty ugly and shouldn't have to be called, but temporarily works until a better solution is set
18381
+ dropReach() {
18382
+ if (this.options.options && this.options.options.Reach) {
18383
+ delete this.options.options.Reach;
18384
+ }
18385
+ }
18368
18386
  }
18369
18387
 
18370
18388
  /**
@@ -18419,7 +18437,7 @@ function fillTreeWithObject(tree, myObject, searched, options, depth = 0) {
18419
18437
  const searchResultPresentsUnMatched = options.searchResultPresentsUnMatched;
18420
18438
  if (myObject && myObject.length) {
18421
18439
  myObject.forEach(value => {
18422
- var _a, _b, _c, _d, _e;
18440
+ var _a, _b, _c;
18423
18441
  let keyPropFromNode = null;
18424
18442
  let valueTranslatedPropFromNode = null;
18425
18443
  let fullpathPropFromNode = null;
@@ -18427,15 +18445,8 @@ function fillTreeWithObject(tree, myObject, searched, options, depth = 0) {
18427
18445
  if (options.origin == "classification") {
18428
18446
  keyPropFromNode = getPropertyFromNode(value, 'ID');
18429
18447
  valueTranslatedPropFromNode = (_a = getPropertyFromNode(value, 'Translations')[options.language]) === null || _a === void 0 ? void 0 : _a.translated_name;
18430
- // TODO Not sure this is correct in the latest versions, may require review during second half of 2025
18431
- if (searched) {
18432
- fullpathPropFromNode = (_b = getPropertyFromNode(value, 'Properties')) === null || _b === void 0 ? void 0 : _b.System_FullPath;
18433
- fullpathTranslatedPropFromNode = (_c = getPropertyFromNode(value, 'fullpathTranslated')[options.language]) === null || _c === void 0 ? void 0 : _c.translated_fullpath;
18434
- }
18435
- else {
18436
- fullpathPropFromNode = (_d = getPropertyFromNode(value, 'Properties')) === null || _d === void 0 ? void 0 : _d.System_Fullpath;
18437
- fullpathTranslatedPropFromNode = (_e = getPropertyFromNode(value, 'Translations')[options.language]) === null || _e === void 0 ? void 0 : _e.translated_fullpath;
18438
- }
18448
+ fullpathPropFromNode = (_b = getPropertyFromNode(value, 'Properties')) === null || _b === void 0 ? void 0 : _b.System_Fullpath;
18449
+ fullpathTranslatedPropFromNode = (_c = getPropertyFromNode(value, 'Translations')[options.language]) === null || _c === void 0 ? void 0 : _c.translated_fullpath;
18439
18450
  }
18440
18451
  else {
18441
18452
  keyPropFromNode = getPropertyFromNode(value, 'key');
@@ -19125,15 +19136,15 @@ const HierarchizedPickerComponent = class extends HTMLElement {
19125
19136
  const pathSegments = parsedUrl.pathname.split('/');
19126
19137
  const dynamicType = pathSegments[pathSegments.length - 2];
19127
19138
  const newPathname = `/api/v1/classification/reach/${dynamicType}/${options.Reach}`;
19139
+ this.optionsManager.dropReach();
19128
19140
  return `${parsedUrl.origin}${newPathname}`;
19129
19141
  }
19130
19142
  return url;
19131
19143
  }
19132
- getContextualApiParams(options = null) {
19133
- if (!options)
19134
- options = this.optionsManager.getOptions().options;
19144
+ getContextualApiParams(search = null) {
19145
+ const options = this.optionsManager.getOptions().options;
19146
+ let optionsToReturn = Object.assign({}, options);
19135
19147
  if (options.Reach) {
19136
- let optionsToReturn = Object.assign({}, options);
19137
19148
  delete optionsToReturn.Reach;
19138
19149
  if ("startNode" in optionsToReturn) {
19139
19150
  optionsToReturn.startingnode = optionsToReturn.startNode;
@@ -19143,10 +19154,17 @@ const HierarchizedPickerComponent = class extends HTMLElement {
19143
19154
  optionsToReturn.startingnode = optionsToReturn.StartNodeID;
19144
19155
  delete optionsToReturn.StartNodeID;
19145
19156
  }
19146
- return optionsToReturn;
19157
+ }
19158
+ else if (search) {
19159
+ optionsToReturn.searchedValue = search;
19160
+ if ("startNode" in optionsToReturn) {
19161
+ optionsToReturn.StartNodeID = optionsToReturn.startNode;
19162
+ delete optionsToReturn.startNode;
19163
+ }
19147
19164
  }
19148
19165
  else
19149
19166
  return options;
19167
+ return optionsToReturn;
19150
19168
  }
19151
19169
  translateDataForTree(dataToLoad, searchID = null, searched = null) {
19152
19170
  if (searched && searched != "") {
@@ -19159,7 +19177,7 @@ const HierarchizedPickerComponent = class extends HTMLElement {
19159
19177
  loadSearchDataInCurrentTree(searchID, searched) {
19160
19178
  let displayResults = (newtree) => {
19161
19179
  if (this.searchToDisplay > -1) { // TODO > Not working anymore after refact, prevents issues in displaying results when running multiple researchs at the same time && searchID == this.searchToDisplay) {
19162
- this.rawDataManager.mergeData(newtree);
19180
+ this.rawDataManager.mergeData(newtree, this.theOptions.origin == 'classification' ? "ID" : "key");
19163
19181
  newtree.children.forEach((value, index) => {
19164
19182
  completeCurrentTreeWithTree(this.loadedTreeJs, value, this.optionsManager.getOptions());
19165
19183
  });
@@ -19181,9 +19199,7 @@ const HierarchizedPickerComponent = class extends HTMLElement {
19181
19199
  if (this.theOptions.source == 'webservice') {
19182
19200
  if (this.theOptions.origin == 'classification') {
19183
19201
  // WS Call
19184
- this.rawDataManager.getFromClassification(this.getApiSearchURL(), {
19185
- searchedValue: searched
19186
- }, document.querySelector("#hierarchized-picker-" + this.componentID + ".loader"))
19202
+ this.rawDataManager.getFromClassification(this.getApiSearchURL(), Object.assign({}, this.getContextualApiParams(searched)), document.querySelector("#hierarchized-picker-" + this.componentID + ".loader"))
19187
19203
  .then((data) => {
19188
19204
  displayResults(data);
19189
19205
  if (!searched) {
@@ -19332,19 +19348,24 @@ const HierarchizedPickerComponent = class extends HTMLElement {
19332
19348
  // ----- BEGIN -----
19333
19349
  let node = treeToUpdate.nodesById[id];
19334
19350
  let onChange = treeToUpdate.options.onChange;
19335
- if (!node.disabled) {
19336
- treeToUpdate.setValue(id);
19337
- treeToUpdate.updateLiElements();
19351
+ if (!node) {
19352
+ this.logError("The current selected value is not part of the loaded tree!");
19338
19353
  }
19339
- userClick && onChange && onChange.call(treeToUpdate);
19340
- // ------ END ------
19341
- if (this.setValueOnClick) {
19342
- this.editValue(node, userClick);
19343
- if (this.shownTree && userClick) {
19344
- // TODO > is this required ?
19345
- // await focusMainInput(this);
19346
- if (!this.optionsManager.getOptions().multiple) {
19347
- this.showTree('hide');
19354
+ else {
19355
+ if (!node.disabled) {
19356
+ treeToUpdate.setValue(id);
19357
+ treeToUpdate.updateLiElements();
19358
+ }
19359
+ userClick && onChange && onChange.call(treeToUpdate);
19360
+ // ------ END ------
19361
+ if (this.setValueOnClick) {
19362
+ this.editValue(node, userClick);
19363
+ if (this.shownTree && userClick) {
19364
+ // TODO > is this required ?
19365
+ // await focusMainInput(this);
19366
+ if (!this.optionsManager.getOptions().multiple) {
19367
+ this.showTree('hide');
19368
+ }
19348
19369
  }
19349
19370
  }
19350
19371
  }
@@ -19477,6 +19498,7 @@ const HierarchizedPickerComponent = class extends HTMLElement {
19477
19498
  }
19478
19499
  // Search a value in the tree and triggers a search when necessary
19479
19500
  search(searched) {
19501
+ this.loader.classList.add('loading');
19480
19502
  let searchinput = document.querySelector('#hierarchized-picker-' + this.componentID + ' .hierarchized-picker-search input');
19481
19503
  if (this.optionsManager.getOptions().mode == 'input' && searchinput) {
19482
19504
  searchinput.classList.remove('fieldError');
@@ -19513,6 +19535,7 @@ const HierarchizedPickerComponent = class extends HTMLElement {
19513
19535
  // this.checkFields(this.value, false);
19514
19536
  this.setSearchResults([]);
19515
19537
  }
19538
+ this.loader.classList.remove('loading');
19516
19539
  }
19517
19540
  // Refresh the tree with search results
19518
19541
  triggerSearch(searched) {
@@ -19531,7 +19554,9 @@ const HierarchizedPickerComponent = class extends HTMLElement {
19531
19554
  loadDataForTree(init, loader) {
19532
19555
  if (this.optionsManager.getOptions().source == 'webservice') {
19533
19556
  if (this.optionsManager.getOptions().origin == 'classification') {
19534
- this.rawDataManager.getFromClassification(this.getContextualApiURL(), this.getContextualApiParams(), loader).then((data) => {
19557
+ const contextualApiParams = this.getContextualApiParams();
19558
+ const contextualApiURL = this.getContextualApiURL();
19559
+ this.rawDataManager.getFromClassification(contextualApiURL, contextualApiParams, loader).then((data) => {
19535
19560
  this.rawData = data;
19536
19561
  if (init) {
19537
19562
  this.formatDefaultValue();