@sumaris-net/ngx-components 18.22.5 → 18.22.7

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.
@@ -615,13 +615,21 @@ function compareValuesDesc(a, b) {
615
615
  * @typeParam T - Type of compared objects.
616
616
  * @param path - Property path or array path (e.g. "a.b[0].c").
617
617
  * @param direction - Sort direction, 'asc' by default.
618
+ * @param nullsFirst
618
619
  * @returns A comparator compatible with `Array.prototype.sort`.
619
620
  */
620
- function propertyPathComparator(path, direction = 'asc') {
621
+ function propertyPathComparator(path, direction = 'asc', nullsFirst) {
622
+ nullsFirst = nullsFirst ?? direction == 'desc';
621
623
  const compareFn = direction === 'asc' ? compareValues : compareValuesDesc;
622
624
  return (a, b) => {
623
625
  const valueA = getPropertyByPath(a, path);
624
626
  const valueB = getPropertyByPath(b, path);
627
+ if (valueA == null && valueB == null)
628
+ return 0;
629
+ if (valueA == null)
630
+ return nullsFirst ? -1 : 1;
631
+ if (valueB == null)
632
+ return nullsFirst ? 1 : -1;
625
633
  return compareFn(valueA, valueB);
626
634
  };
627
635
  }
@@ -634,14 +642,21 @@ function propertyPathComparator(path, direction = 'asc') {
634
642
  * @typeParam K - Key of the property in `T`.
635
643
  * @param property - Property name to compare.
636
644
  * @param direction - Sort direction, 'asc' by default.
637
- * @param defaultValue - Value used when the property is undefined.
645
+ * @param nullsFirst - If true, nil values are placed first, else last. By default, 'false' if direction='asc', 'true' if direction='desc'
638
646
  * @returns A comparator compatible with `Array.prototype.sort`.
639
647
  */
640
- function propertyComparator(property, direction = 'asc', defaultValue) {
648
+ function propertyComparator(property, direction = 'asc', nullsFirst) {
649
+ nullsFirst = nullsFirst ?? direction === 'desc';
641
650
  const compareFn = direction === 'asc' ? compareValues : compareValuesDesc;
642
651
  return (a, b) => {
643
- const valueA = a[property] !== undefined ? a[property] : defaultValue;
644
- const valueB = b[property] ? b[property] : defaultValue;
652
+ const valueA = a[property];
653
+ const valueB = b[property];
654
+ if (valueA == null && valueB == null)
655
+ return 0;
656
+ if (valueA == null)
657
+ return nullsFirst ? -1 : 1;
658
+ if (valueB == null)
659
+ return nullsFirst ? 1 : -1;
645
660
  return compareFn(valueA, valueB);
646
661
  };
647
662
  }
@@ -655,19 +670,26 @@ function propertyComparator(property, direction = 'asc', defaultValue) {
655
670
  * @typeParam T - Type of compared objects.
656
671
  * @param keys - Ordered list of property paths to compare.
657
672
  * @param direction - Sort direction applied to each key, 'asc' by default.
658
- * @param defaultValues - Optional default values, aligned with `keys`.
673
+ * @param nullsFirst - Optional
659
674
  * @throws Error when `keys` is empty or when `defaultValues` length is invalid.
660
675
  * @returns A comparator compatible with `Array.prototype.sort`.
661
676
  */
662
- function propertiesPathComparator(keys, direction = 'asc', defaultValues) {
663
- if (!keys || !keys.length || (defaultValues && keys.length > defaultValues.length)) {
677
+ function propertiesPathComparator(keys, direction = 'asc', nullsFirst) {
678
+ if (isEmptyArray(keys)) {
664
679
  throw new Error("Invalid arguments: missing 'keys' or array 'defaultValues' has a bad length");
665
680
  }
681
+ nullsFirst = nullsFirst ?? direction === 'desc';
666
682
  const compareFn = direction === 'asc' ? compareValues : compareValuesDesc;
667
683
  return (a, b) => keys
668
684
  .map((key, index) => {
669
- const valueA = getPropertyByPath(a, key, defaultValues && defaultValues[index]);
670
- const valueB = getPropertyByPath(b, key, defaultValues && defaultValues[index]);
685
+ const valueA = getPropertyByPath(a, key);
686
+ const valueB = getPropertyByPath(b, key);
687
+ if (valueA == null && valueB == null)
688
+ return 0;
689
+ if (valueA == null)
690
+ return nullsFirst ? -1 : 1;
691
+ if (valueB == null)
692
+ return nullsFirst ? 1 : -1;
671
693
  return compareFn(valueA, valueB);
672
694
  })
673
695
  // Stop if not equals, otherwise continue with the next key
@@ -686,9 +708,10 @@ function propertiesPathComparator(keys, direction = 'asc', defaultValues) {
686
708
  */
687
709
  function composeComparators(...comparators) {
688
710
  return (a, b) => {
689
- return comparators?.map(comparator => comparator(a, b))
711
+ return (comparators
712
+ ?.map((comparator) => comparator(a, b))
690
713
  // Stop if not equals, otherwise continue with the next key
691
- .find((res) => res !== 0) || 0;
714
+ .find((res) => res !== 0) || 0);
692
715
  };
693
716
  }
694
717
  function sort(array, attribute, opts) {
@@ -27164,11 +27187,11 @@ function RxStateComputed(dependencies, computeFn, opts) {
27164
27187
  function RxStateOutput(statePropertyName, opts) {
27165
27188
  return function (target, key) {
27166
27189
  // Naming convention check
27167
- if (!production && !key.endsWith('Changes')) {
27168
- console.warn(`[RxStateOutput] Convention: Property ${target.constructor?.name}.${String(key)} should end with 'Changes' to indicate it's an Output`);
27190
+ if (!production && !key.endsWith('Changes') && !key.endsWith('Change')) {
27191
+ console.warn(`[RxStateOutput] Convention: Property ${target.constructor?.name}.${String(key)} should end with 'Change' or 'Changes' to indicate it's an Output`);
27169
27192
  }
27170
27193
  // Determine state property name
27171
- const finalStatePropertyName = statePropertyName || key.replace(/Changes$/, '');
27194
+ const finalStatePropertyName = statePropertyName || key.replace(/Changes?$/, '');
27172
27195
  // Determine state object
27173
27196
  const stateVarName = target instanceof RxState ? null : target[STATE_VAR_NAME_KEY] || opts?.stateName || DEFAULT_STATE_VAR_NAME;
27174
27197
  const cachePropertyName = `__${key}_cache`;
@@ -39604,7 +39627,7 @@ class AppTable {
39604
39627
  startCellValueChanges(name, row) {
39605
39628
  const def = this._cellValueChangesDefs[name];
39606
39629
  if (!def) {
39607
- console.warn('[table] Listener with name {' + name + '} not registered! Please call registerCellValueChanges() before;');
39630
+ console.warn(`[table] Listener with name {${name} not registered! Please call registerCellValueChanges() before`);
39608
39631
  return;
39609
39632
  }
39610
39633
  // Stop previous subscription