@lavalogic/scoria 0.25.2 → 0.26.0

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.
@@ -1,4 +1,4 @@
1
- import { asyncSleep } from '../../../Helpers/Helpers.svelte.js';
1
+ import { asyncSleep, generateShortUUID, getAccessorSortingFn, } from '../../../Helpers/Helpers.svelte.js';
2
2
  import { Colour } from '../../../scss/colours.js';
3
3
  import { ExampleSelectEnum } from '../../../Types/Examples/ExampleSelectEnum.js';
4
4
  import { Validity } from '../../../Types/Internal/Validity.js';
@@ -55,6 +55,16 @@ export function generateExampleItemColumnDefs(modal) {
55
55
  isEnabled: () => true,
56
56
  isValid,
57
57
  }));
58
+ const uuidByIndex = new Map();
59
+ const statusAccessorFn = async (item) => {
60
+ const foundByIndex = uuidByIndex.get(item.id);
61
+ if (foundByIndex) {
62
+ return foundByIndex;
63
+ }
64
+ const newlyMade = generateShortUUID();
65
+ uuidByIndex.set(item.id, newlyMade);
66
+ return newlyMade;
67
+ };
58
68
  let defs = $state([
59
69
  expandDef,
60
70
  new ValidityDef({
@@ -64,6 +74,26 @@ export function generateExampleItemColumnDefs(modal) {
64
74
  isValid,
65
75
  modal,
66
76
  }),
77
+ new DisplayDef({
78
+ id: 'orderLineStatus',
79
+ header: 'Order Line Status',
80
+ allowSorting: true,
81
+ debug: true,
82
+ accessorFn: statusAccessorFn,
83
+ filterValueType: 'Select',
84
+ getOptions: async () => {
85
+ void uuidByIndex.size;
86
+ const mapped = [
87
+ { label: 'Pending', value: 'Pending' },
88
+ ...[...uuidByIndex.values()].map((it) => {
89
+ return { label: it, value: it };
90
+ }),
91
+ ];
92
+ return mapped;
93
+ },
94
+ getSortingFn: (desc) => getAccessorSortingFn(statusAccessorFn, desc),
95
+ allowFiltering: true,
96
+ }),
67
97
  new DisplayDef({
68
98
  header: 'ID',
69
99
  id: 'id',
@@ -4,7 +4,6 @@ import { AccessorDef, type AccessorDefProps } from './AccessorDef.svelte.js';
4
4
  export interface SelectDefProps<T extends object, in FilterValueType, out SelectValueType> extends AccessorDefProps<T, FilterValueType, SelectValueType> {
5
5
  getOptions: () => Array<SelectOption<SelectValueType>> | Promise<Array<SelectOption<SelectValueType>>>;
6
6
  getDisplayValue: (item: T, index: number) => string | null | Promise<string | null>;
7
- sortingFn?: (a: T, b: T) => 1 | -1 | 0;
8
7
  getSpecificOptions?: (item: T, index: number) => Array<SelectOption<SelectValueType>> | Promise<Array<SelectOption<SelectValueType>>>;
9
8
  optional?: boolean;
10
9
  clearable?: boolean;
@@ -15,7 +14,6 @@ export declare class SelectDef<T extends object, in FilterValueType, out SelectV
15
14
  private _filterFn;
16
15
  get filterFn(): FilterFn<T, FilterValueType> | undefined;
17
16
  set filterFn(v: FilterFn<T, FilterValueType> | undefined);
18
- readonly sortingFn?: (a: T, b: T) => 1 | -1 | 0;
19
17
  readonly optional: boolean;
20
18
  readonly clearable: boolean;
21
19
  readonly getSpecificOptions?: (item: T, index: number) => Array<SelectOption<SelectValueType>> | Promise<Array<SelectOption<SelectValueType>>>;
@@ -5,7 +5,6 @@ export class SelectDef extends AccessorDef {
5
5
  super(props);
6
6
  this.getSpecificOptions = $derived(props.getSpecificOptions); //done in the base class now
7
7
  // this.getOptions = $derived(props.getOptions); // done in the base class now
8
- this.sortingFn = $derived(props.sortingFn);
9
8
  this.optional = $derived(props.optional ?? false);
10
9
  this.clearable = $derived(props.clearable ?? true);
11
10
  // this.getDisplayValue = $derived(props.getDisplayValue); //done in the base class now
@@ -19,7 +18,6 @@ export class SelectDef extends AccessorDef {
19
18
  set filterFn(v) {
20
19
  this._filterFn = v;
21
20
  }
22
- sortingFn;
23
21
  optional;
24
22
  clearable;
25
23
  getSpecificOptions;
@@ -21,6 +21,7 @@ export interface ColumnDefProps<T extends object, in FilterFnType, out OptionsTy
21
21
  resizable?: boolean;
22
22
  isValid?: ValidationFn<T>;
23
23
  filterFn?: FilterFn<T, FilterFnType>;
24
+ getSortingFn?: (desc: boolean) => (a: T, b: T) => 1 | -1 | 0;
24
25
  filterValueType?: FilterValueType;
25
26
  getOptions?: () => Array<SelectOption<OptionsType>> | Promise<Array<SelectOption<OptionsType>>>;
26
27
  accessorFn?: AccessorFn<T>;
@@ -57,6 +58,7 @@ export declare abstract class ColumnDef<T extends object, in FilterFnType = neve
57
58
  set filterValueType(v: FilterValueType | undefined);
58
59
  readonly getDisplayValue: ((item: T, index: number) => string | null | Promise<string | null>) | undefined;
59
60
  toJSON(): ColumnJSONRepresentation;
61
+ readonly getSortingFn: ((desc: boolean) => (a: T, b: T) => 1 | -1 | 0) | undefined;
60
62
  readonly isEditable: (item: T, index: number) => boolean | Promise<boolean>;
61
63
  readonly resizable: boolean;
62
64
  readonly header: string | Snippet;
@@ -16,6 +16,7 @@ export class ColumnDef {
16
16
  this._filterValueType = $derived(props.filterValueType);
17
17
  this.getDisplayValue = $derived(props.getDisplayValue);
18
18
  this.debug = $derived(props.debug ?? false);
19
+ this.getSortingFn = $derived(props.getSortingFn);
19
20
  this.getOptions = $derived(props.getOptions);
20
21
  }
21
22
  id;
@@ -84,6 +85,7 @@ export class ColumnDef {
84
85
  filterValueType: this.filterValueType,
85
86
  };
86
87
  }
88
+ getSortingFn;
87
89
  isEditable;
88
90
  resizable;
89
91
  header;
@@ -725,6 +725,9 @@ export class TableContext {
725
725
  if (!def) {
726
726
  return undefined;
727
727
  }
728
+ if (def.getSortingFn != undefined) {
729
+ return def.getSortingFn(desc);
730
+ }
728
731
  if (def instanceof DisplayDef ||
729
732
  def instanceof TextInputDef ||
730
733
  def instanceof NumberInputDef ||
@@ -735,7 +738,7 @@ export class TableContext {
735
738
  return checkboxSortingFn(id, desc);
736
739
  }
737
740
  if (def instanceof SelectDef) {
738
- return def.sortingFn ?? comparableSortingFn(id, desc);
741
+ return comparableSortingFn(id, desc);
739
742
  }
740
743
  if (def instanceof ProgressBarDef) {
741
744
  return progressSortingFn(id, desc);
@@ -64,3 +64,4 @@ export interface ICreateTableArgs<T extends object, RowIdType extends Primitive>
64
64
  selectionExtractor: (item: T) => RowIdType | Promise<RowIdType>;
65
65
  }
66
66
  export declare function createLocalTable<T extends object, RowIdType extends Primitive>(args: ICreateTableArgs<T, RowIdType>): TableContext<T, RowIdType>;
67
+ export declare function getAccessorSortingFn<T, V>(accessorFn: (item: T) => V, desc: boolean): (a: T, b: T) => 1 | 0 | -1;
@@ -421,3 +421,40 @@ export function createLocalTable(args) {
421
421
  getUserId: args.getUserId,
422
422
  });
423
423
  }
424
+ export function getAccessorSortingFn(accessorFn, desc) {
425
+ return desc
426
+ ? (_a, _b) => {
427
+ const a = accessorFn(_a);
428
+ const b = accessorFn(_b);
429
+ if (a == undefined && b != undefined) {
430
+ return 1;
431
+ }
432
+ if (b == undefined && a != undefined) {
433
+ return -1;
434
+ }
435
+ if (a < b) {
436
+ return 1;
437
+ }
438
+ if (a > b) {
439
+ return -1;
440
+ }
441
+ return 0;
442
+ }
443
+ : (_a, _b) => {
444
+ const a = accessorFn(_a);
445
+ const b = accessorFn(_b);
446
+ if (a == undefined && b != undefined) {
447
+ return 1;
448
+ }
449
+ if (b == undefined && a != undefined) {
450
+ return -1;
451
+ }
452
+ if (a < b) {
453
+ return -1;
454
+ }
455
+ if (a > b) {
456
+ return 1;
457
+ }
458
+ return 0;
459
+ };
460
+ }
package/dist/index.d.ts CHANGED
@@ -132,7 +132,7 @@ export { TooltipContext } from './Contexts/TooltipContext.svelte.js';
132
132
  export { UntypedInputContext } from './Contexts/UntypedInputContext.svelte.js';
133
133
  export { Delay } from './Delay/Delay.js';
134
134
  export { DATAMatrix } from './Helpers/Datamatrix.js';
135
- export { asyncAll, asyncEvery, asyncFilter, asyncFilterIndices, asyncFlatMap, asyncForEach, asyncMap, asyncSleep, asyncSome, autoPluralise, createLocalTable, devCatch, generateShortUUID, generateUUID, getCanvasContext, getErrorMessage, gridItem, isDateTuple, isNumericArray, isValidEmailAddress, loadingText, localTimeFormat, passthrough, refWrapper, SQLFriendly, SQLFriendlyWithLocalTime, vowels, type ICreateTableArgs, } from './Helpers/Helpers.svelte.js';
135
+ export { asyncAll, asyncEvery, asyncFilter, asyncFilterIndices, asyncFlatMap, asyncForEach, asyncMap, asyncSleep, asyncSome, autoPluralise, createLocalTable, devCatch, generateShortUUID, generateUUID, getAccessorSortingFn, getCanvasContext, getErrorMessage, gridItem, isDateTuple, isNumericArray, isValidEmailAddress, loadingText, localTimeFormat, passthrough, refWrapper, SQLFriendly, SQLFriendlyWithLocalTime, vowels, type ICreateTableArgs, } from './Helpers/Helpers.svelte.js';
136
136
  export { type INamed } from './Helpers/INamed.js';
137
137
  export { AttributeOperation } from './Types/Internal/AttributeOperation.js';
138
138
  export { type BigRadioOption } from './Types/Internal/BigRadioOption.js';
package/dist/index.js CHANGED
@@ -132,7 +132,7 @@ export { TooltipContext } from './Contexts/TooltipContext.svelte.js';
132
132
  export { UntypedInputContext } from './Contexts/UntypedInputContext.svelte.js';
133
133
  export { Delay } from './Delay/Delay.js';
134
134
  export { DATAMatrix } from './Helpers/Datamatrix.js';
135
- export { asyncAll, asyncEvery, asyncFilter, asyncFilterIndices, asyncFlatMap, asyncForEach, asyncMap, asyncSleep, asyncSome, autoPluralise, createLocalTable, devCatch, generateShortUUID, generateUUID, getCanvasContext, getErrorMessage, gridItem, isDateTuple, isNumericArray, isValidEmailAddress, loadingText, localTimeFormat, passthrough, refWrapper, SQLFriendly, SQLFriendlyWithLocalTime, vowels, } from './Helpers/Helpers.svelte.js';
135
+ export { asyncAll, asyncEvery, asyncFilter, asyncFilterIndices, asyncFlatMap, asyncForEach, asyncMap, asyncSleep, asyncSome, autoPluralise, createLocalTable, devCatch, generateShortUUID, generateUUID, getAccessorSortingFn, getCanvasContext, getErrorMessage, gridItem, isDateTuple, isNumericArray, isValidEmailAddress, loadingText, localTimeFormat, passthrough, refWrapper, SQLFriendly, SQLFriendlyWithLocalTime, vowels, } from './Helpers/Helpers.svelte.js';
136
136
  export {} from './Helpers/INamed.js';
137
137
  export { AttributeOperation } from './Types/Internal/AttributeOperation.js';
138
138
  export {} from './Types/Internal/BigRadioOption.js';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@lavalogic/scoria",
3
3
  "description": "Svelte components used for the FloWMS Web Frontend",
4
- "version": "0.25.2",
4
+ "version": "0.26.0",
5
5
  "publishConfig": {
6
6
  "access": "restricted"
7
7
  },