@lavalogic/scoria 0.0.34 → 0.0.36

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,16 +1,17 @@
1
1
  <svelte:options runes />
2
2
 
3
3
  <script lang="ts" module>
4
- interface commonProps<V extends object, VP extends string & keyof V> {
5
- options?: V[];
6
- name: string;
7
- labelProp: string & keyof V;
4
+ interface QuerySelectPropsAsObjectCommonProps<V extends object, VP extends ValueProp<V>> {
5
+ options: V[];
6
+
7
+ labelProp: NonNullableKey<V>;
8
8
  valueProp: VP;
9
+
9
10
  query: (value: string) => Promise<V[]>;
10
- onchange: (e: V | null) => void;
11
+ onchange: (newValue: V | null) => void;
11
12
 
13
+ name?: string;
12
14
  disabled?: boolean;
13
-
14
15
  width?: string;
15
16
  height?: string;
16
17
  label?: string;
@@ -23,25 +24,25 @@
23
24
  isValid?: (item: V | null) => boolean;
24
25
  }
25
26
 
26
- export interface QuerySelectPropsAsObject<V extends object, VP extends string & keyof V>
27
- extends commonProps<V, VP> {
27
+ export interface QuerySelectPropsAsObject<V extends object, VP extends ValueProp<V>>
28
+ extends QuerySelectPropsAsObjectCommonProps<V, VP> {
28
29
  valueAsObject: true;
29
- selectedValue: V | null;
30
+ value: V | null;
30
31
  }
31
32
 
32
- export interface QuerySelectPropsAsPrimitive<V extends object, VP extends string & keyof V>
33
- extends commonProps<V, VP> {
33
+ export interface QuerySelectPropsAsPrimitive<V extends object, VP extends ValueProp<V>>
34
+ extends QuerySelectPropsAsObjectCommonProps<V, VP> {
34
35
  valueAsObject: false;
35
- selectedValue: V[VP] | null;
36
+ value: V[VP] | null;
36
37
  }
37
38
 
38
- export type QuerySelectProps<V extends object, VP extends string & keyof V> =
39
+ export type QuerySelectProps<V extends object, VP extends ValueProp<V>> =
39
40
  | QuerySelectPropsAsObject<V, VP>
40
41
  | QuerySelectPropsAsPrimitive<V, VP>;
41
42
  </script>
42
43
 
43
44
  <!-- #region Script -->
44
- <script lang="ts" generics="V extends object, VP extends string&keyof V">
45
+ <script lang="ts" generics="V extends object, VP extends ValueProp<V>">
45
46
  import { ToastContext } from '../Contexts/ToastContext.svelte.js';
46
47
 
47
48
  import {
@@ -56,6 +57,7 @@
56
57
  import Action from './Action.svelte';
57
58
  import { Size } from '../Types/Internal/Size.js';
58
59
  import { Validity } from '../Types/Internal/Validity.js';
60
+ import type { NonNullableKey, ValueProp } from '../Types/Internal/Misc.js';
59
61
 
60
62
  let {
61
63
  label,
@@ -65,20 +67,32 @@
65
67
  required = false,
66
68
  invalid = false,
67
69
  valueAsObject,
68
- name,
70
+ name = 'Item',
69
71
  disabled,
70
72
  query,
71
73
  width,
72
74
  height,
73
75
  focusOnLoad = false,
74
76
  inputId = generateShortUUID(),
75
- selectedValue,
76
- options = $bindable([]),
77
+ value: selectedValue,
78
+ options = $bindable<V[]>([]),
77
79
  isValid,
78
80
  onchange,
79
81
  onfocus
80
82
  }: QuerySelectProps<V, VP> = $props();
81
83
 
84
+ export function forceQuery() {
85
+ clearTimeout(timeoutHandler);
86
+
87
+ const input = document.getElementById(inputId);
88
+ const searchValue = (input as HTMLInputElement).value;
89
+
90
+ const currentHandler = (timeoutHandler = setTimeout(() => {
91
+ tryQuery(currentHandler, searchValue);
92
+ }, 500) as unknown as number);
93
+ tryQuery(currentHandler, searchValue);
94
+ }
95
+
82
96
  let ref: Svelecte | undefined = $state();
83
97
  let hasAutoFocused = $state(false);
84
98
  let loadingDiv: HTMLDivElement | undefined = $state();
@@ -86,11 +100,10 @@
86
100
  let hasRegisteredListeners = $state(false);
87
101
 
88
102
  $effect.pre(() => {
89
- // eslint-disable-next-line @typescript-eslint/no-unused-expressions
90
- selectedValue;
103
+ void selectedValue;
91
104
  untrack(() => {
92
105
  if (selectedValue != null) {
93
- if (typeof selectedValue == 'object') {
106
+ if (valueAsObject) {
94
107
  if (!options.some((opt: V) => opt[valueProp] === (selectedValue as V)[valueProp])) {
95
108
  options.push(selectedValue! as V);
96
109
  }
@@ -104,16 +117,12 @@
104
117
  });
105
118
  });
106
119
 
107
- function valueIsObject(value: V | V[VP] | null): value is V {
108
- return selectedValue == null || typeof selectedValue == 'object';
109
- }
110
-
111
120
  let isInvalid = $derived(
112
121
  (required && !selectedValue) ||
113
122
  invalid ||
114
123
  isValid?.(
115
- valueIsObject(selectedValue)
116
- ? selectedValue
124
+ valueAsObject
125
+ ? (selectedValue as V)
117
126
  : (options.find((a) => a[valueProp] === selectedValue) ?? null)
118
127
  ) === false
119
128
  );
@@ -1,10 +1,10 @@
1
- interface commonProps<V extends object, VP extends string & keyof V> {
2
- options?: V[];
3
- name: string;
4
- labelProp: string & keyof V;
1
+ interface QuerySelectPropsAsObjectCommonProps<V extends object, VP extends ValueProp<V>> {
2
+ options: V[];
3
+ labelProp: NonNullableKey<V>;
5
4
  valueProp: VP;
6
5
  query: (value: string) => Promise<V[]>;
7
- onchange: (e: V | null) => void;
6
+ onchange: (newValue: V | null) => void;
7
+ name?: string;
8
8
  disabled?: boolean;
9
9
  width?: string;
10
10
  height?: string;
@@ -17,36 +17,41 @@ interface commonProps<V extends object, VP extends string & keyof V> {
17
17
  clearable?: boolean;
18
18
  isValid?: (item: V | null) => boolean;
19
19
  }
20
- export interface QuerySelectPropsAsObject<V extends object, VP extends string & keyof V> extends commonProps<V, VP> {
20
+ export interface QuerySelectPropsAsObject<V extends object, VP extends ValueProp<V>> extends QuerySelectPropsAsObjectCommonProps<V, VP> {
21
21
  valueAsObject: true;
22
- selectedValue: V | null;
22
+ value: V | null;
23
23
  }
24
- export interface QuerySelectPropsAsPrimitive<V extends object, VP extends string & keyof V> extends commonProps<V, VP> {
24
+ export interface QuerySelectPropsAsPrimitive<V extends object, VP extends ValueProp<V>> extends QuerySelectPropsAsObjectCommonProps<V, VP> {
25
25
  valueAsObject: false;
26
- selectedValue: V[VP] | null;
26
+ value: V[VP] | null;
27
27
  }
28
- export type QuerySelectProps<V extends object, VP extends string & keyof V> = QuerySelectPropsAsObject<V, VP> | QuerySelectPropsAsPrimitive<V, VP>;
29
- declare function $$render<V extends object, VP extends string & keyof V>(): {
28
+ export type QuerySelectProps<V extends object, VP extends ValueProp<V>> = QuerySelectPropsAsObject<V, VP> | QuerySelectPropsAsPrimitive<V, VP>;
29
+ import type { NonNullableKey, ValueProp } from '../Types/Internal/Misc.js';
30
+ declare function $$render<V extends object, VP extends ValueProp<V>>(): {
30
31
  props: QuerySelectProps<V, VP>;
31
- exports: {};
32
+ exports: {
33
+ forceQuery: () => void;
34
+ };
32
35
  bindings: "options";
33
36
  slots: {};
34
37
  events: {};
35
38
  };
36
- declare class __sveltets_Render<V extends object, VP extends string & keyof V> {
39
+ declare class __sveltets_Render<V extends object, VP extends ValueProp<V>> {
37
40
  props(): ReturnType<typeof $$render<V, VP>>['props'];
38
41
  events(): ReturnType<typeof $$render<V, VP>>['events'];
39
42
  slots(): ReturnType<typeof $$render<V, VP>>['slots'];
40
43
  bindings(): "options";
41
- exports(): {};
44
+ exports(): {
45
+ forceQuery: () => void;
46
+ };
42
47
  }
43
48
  interface $$IsomorphicComponent {
44
- new <V extends object, VP extends string & keyof V>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<V, VP>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<V, VP>['props']>, ReturnType<__sveltets_Render<V, VP>['events']>, ReturnType<__sveltets_Render<V, VP>['slots']>> & {
49
+ new <V extends object, VP extends ValueProp<V>>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<V, VP>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<V, VP>['props']>, ReturnType<__sveltets_Render<V, VP>['events']>, ReturnType<__sveltets_Render<V, VP>['slots']>> & {
45
50
  $$bindings?: ReturnType<__sveltets_Render<V, VP>['bindings']>;
46
51
  } & ReturnType<__sveltets_Render<V, VP>['exports']>;
47
- <V extends object, VP extends string & keyof V>(internal: unknown, props: ReturnType<__sveltets_Render<V, VP>['props']> & {}): ReturnType<__sveltets_Render<V, VP>['exports']>;
52
+ <V extends object, VP extends ValueProp<V>>(internal: unknown, props: ReturnType<__sveltets_Render<V, VP>['props']> & {}): ReturnType<__sveltets_Render<V, VP>['exports']>;
48
53
  z_$$bindings?: ReturnType<__sveltets_Render<any, any>['bindings']>;
49
54
  }
50
55
  declare const QuerySelect: $$IsomorphicComponent;
51
- type QuerySelect<V extends object, VP extends string & keyof V> = InstanceType<typeof QuerySelect<V, VP>>;
56
+ type QuerySelect<V extends object, VP extends ValueProp<V>> = InstanceType<typeof QuerySelect<V, VP>>;
52
57
  export default QuerySelect;
@@ -9,13 +9,15 @@
9
9
  import { onMount, tick } from 'svelte';
10
10
  import Action from './Action.svelte';
11
11
 
12
- interface commonProps<V extends object, VP extends ValueProp<V> = ValueProp<V>> {
12
+ interface SingleSelectCommonProps<V extends object, VP extends ValueProp<V>> {
13
13
  options: V[];
14
14
 
15
15
  labelProp: NonNullableKey<V>;
16
16
  valueProp: VP;
17
17
  // value: V | V[VP] | null;
18
18
 
19
+ onchange: (newValue: V | null) => void;
20
+
19
21
  name?: string;
20
22
  width?: string;
21
23
  height?: string;
@@ -37,31 +39,26 @@
37
39
  createFilter?: (value: string) => boolean;
38
40
  onkeydown?: (e: KeyboardEvent) => void;
39
41
  onfocus?: (target: HTMLInputElement) => void;
40
- onchange: (newValue: V | null) => void;
41
42
  }
42
43
 
43
- export interface SingleSelectPropsAsObject<
44
- V extends object,
45
- VP extends ValueProp<V> = ValueProp<V>
46
- > extends commonProps<V, VP> {
44
+ export interface SingleSelectPropsAsObject<V extends object, VP extends ValueProp<V>>
45
+ extends SingleSelectCommonProps<V, VP> {
47
46
  valueAsObject: true;
48
47
  value: V | null;
49
48
  }
50
49
 
51
- export interface SingleSelectPropsAsPrimitive<
52
- V extends object,
53
- VP extends ValueProp<V> = ValueProp<V>
54
- > extends commonProps<V, VP> {
50
+ export interface SingleSelectPropsAsPrimitive<V extends object, VP extends ValueProp<V>>
51
+ extends SingleSelectCommonProps<V, VP> {
55
52
  valueAsObject: false;
56
53
  value: V[VP] | null;
57
54
  }
58
55
 
59
- export type SingleSelectProps<V extends object, VP extends ValueProp<V> = ValueProp<V>> =
56
+ export type SingleSelectProps<V extends object, VP extends ValueProp<V>> =
60
57
  | SingleSelectPropsAsPrimitive<V, VP>
61
58
  | SingleSelectPropsAsObject<V, VP>;
62
59
  </script>
63
60
 
64
- <script lang="ts" generics="V extends object, VP extends ValueProp<V> = ValueProp<V>">
61
+ <script lang="ts" generics="V extends object, VP extends ValueProp<V>">
65
62
  const {
66
63
  label,
67
64
  options,
@@ -1,8 +1,9 @@
1
1
  import type { NonNullableKey, ValueProp } from '../Types/Internal/Misc.js';
2
- interface commonProps<V extends object, VP extends ValueProp<V> = ValueProp<V>> {
2
+ interface SingleSelectCommonProps<V extends object, VP extends ValueProp<V>> {
3
3
  options: V[];
4
4
  labelProp: NonNullableKey<V>;
5
5
  valueProp: VP;
6
+ onchange: (newValue: V | null) => void;
6
7
  name?: string;
7
8
  width?: string;
8
9
  height?: string;
@@ -24,25 +25,24 @@ interface commonProps<V extends object, VP extends ValueProp<V> = ValueProp<V>>
24
25
  createFilter?: (value: string) => boolean;
25
26
  onkeydown?: (e: KeyboardEvent) => void;
26
27
  onfocus?: (target: HTMLInputElement) => void;
27
- onchange: (newValue: V | null) => void;
28
28
  }
29
- export interface SingleSelectPropsAsObject<V extends object, VP extends ValueProp<V> = ValueProp<V>> extends commonProps<V, VP> {
29
+ export interface SingleSelectPropsAsObject<V extends object, VP extends ValueProp<V>> extends SingleSelectCommonProps<V, VP> {
30
30
  valueAsObject: true;
31
31
  value: V | null;
32
32
  }
33
- export interface SingleSelectPropsAsPrimitive<V extends object, VP extends ValueProp<V> = ValueProp<V>> extends commonProps<V, VP> {
33
+ export interface SingleSelectPropsAsPrimitive<V extends object, VP extends ValueProp<V>> extends SingleSelectCommonProps<V, VP> {
34
34
  valueAsObject: false;
35
35
  value: V[VP] | null;
36
36
  }
37
- export type SingleSelectProps<V extends object, VP extends ValueProp<V> = ValueProp<V>> = SingleSelectPropsAsPrimitive<V, VP> | SingleSelectPropsAsObject<V, VP>;
38
- declare function $$render<V extends object, VP extends ValueProp<V> = ValueProp<V>>(): {
37
+ export type SingleSelectProps<V extends object, VP extends ValueProp<V>> = SingleSelectPropsAsPrimitive<V, VP> | SingleSelectPropsAsObject<V, VP>;
38
+ declare function $$render<V extends object, VP extends ValueProp<V>>(): {
39
39
  props: SingleSelectProps<V, VP>;
40
40
  exports: {};
41
41
  bindings: "";
42
42
  slots: {};
43
43
  events: {};
44
44
  };
45
- declare class __sveltets_Render<V extends object, VP extends ValueProp<V> = ValueProp<V>> {
45
+ declare class __sveltets_Render<V extends object, VP extends ValueProp<V>> {
46
46
  props(): ReturnType<typeof $$render<V, VP>>['props'];
47
47
  events(): ReturnType<typeof $$render<V, VP>>['events'];
48
48
  slots(): ReturnType<typeof $$render<V, VP>>['slots'];
@@ -50,12 +50,12 @@ declare class __sveltets_Render<V extends object, VP extends ValueProp<V> = Valu
50
50
  exports(): {};
51
51
  }
52
52
  interface $$IsomorphicComponent {
53
- new <V extends object, VP extends ValueProp<V> = ValueProp<V>>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<V, VP>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<V, VP>['props']>, ReturnType<__sveltets_Render<V, VP>['events']>, ReturnType<__sveltets_Render<V, VP>['slots']>> & {
53
+ new <V extends object, VP extends ValueProp<V>>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<V, VP>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<V, VP>['props']>, ReturnType<__sveltets_Render<V, VP>['events']>, ReturnType<__sveltets_Render<V, VP>['slots']>> & {
54
54
  $$bindings?: ReturnType<__sveltets_Render<V, VP>['bindings']>;
55
55
  } & ReturnType<__sveltets_Render<V, VP>['exports']>;
56
- <V extends object, VP extends ValueProp<V> = ValueProp<V>>(internal: unknown, props: ReturnType<__sveltets_Render<V, VP>['props']> & {}): ReturnType<__sveltets_Render<V, VP>['exports']>;
56
+ <V extends object, VP extends ValueProp<V>>(internal: unknown, props: ReturnType<__sveltets_Render<V, VP>['props']> & {}): ReturnType<__sveltets_Render<V, VP>['exports']>;
57
57
  z_$$bindings?: ReturnType<__sveltets_Render<any, any>['bindings']>;
58
58
  }
59
59
  declare const SingleSelect: $$IsomorphicComponent;
60
- type SingleSelect<V extends object, VP extends ValueProp<V> = ValueProp<V>> = InstanceType<typeof SingleSelect<V, VP>>;
60
+ type SingleSelect<V extends object, VP extends ValueProp<V>> = InstanceType<typeof SingleSelect<V, VP>>;
61
61
  export default SingleSelect;
@@ -95,11 +95,6 @@
95
95
  let valueMin: number | null = $state(null);
96
96
  let valueMax: number | null = $state(null);
97
97
 
98
- let selectedOption: SelectOption<string | number> | null = $state(
99
- // HACK crappy bodge to get typescript to understand that this won't be always null
100
- null as unknown as SelectOption<string | number>
101
- );
102
-
103
98
  let selectedOptions: Array<SelectOption<string | number>> = $state([]);
104
99
  let lastQueryOptions: Array<SelectOption<unknown>> = $state([]);
105
100
 
@@ -116,15 +111,18 @@
116
111
  return stringFilterTypes.find((it) => it.value === value)!;
117
112
  });
118
113
 
119
- function getFilteringStateValue(): unknown {
120
- const gotValue = tableContext.paginationRepo?.filtering.find((it) => it.id === def.id)?.value;
121
- return gotValue;
122
- }
114
+ const filteringStateValue = $derived(
115
+ tableContext.paginationRepo?.filtering.find((it) => it.id === def.id)?.value
116
+ );
123
117
 
124
118
  $effect(() => {
119
+ if (isRemoteSelect && !tableContext.paginationRepo?.filtering) {
120
+ return;
121
+ }
122
+ void filteringStateValue;
125
123
  if (hasQuery) {
126
124
  untrack(async () => {
127
- const gotValue = getFilteringStateValue() as unknown as
125
+ const gotValue = filteringStateValue as unknown as
128
126
  | Array<string | number | SelectOption<string | number>>
129
127
  | undefined;
130
128
 
@@ -146,7 +144,7 @@
146
144
  return;
147
145
  }
148
146
 
149
- const gotValue = getFilteringStateValue() as unknown as
147
+ const gotValue = filteringStateValue as unknown as
150
148
  | Array<string | number | SelectOption<string | number>>
151
149
  | undefined;
152
150
 
@@ -161,7 +159,7 @@
161
159
  selectedNumberFilterType.value === NumberDateFilterMode.Between &&
162
160
  tableContext.paginationRepo?.filtering
163
161
  ) {
164
- const gotValue = getFilteringStateValue();
162
+ const gotValue = filteringStateValue;
165
163
  if (gotValue != undefined) {
166
164
  const [min, max] = gotValue as [number, number | undefined];
167
165
  value = min;
@@ -171,7 +169,7 @@
171
169
  value = valueMin = valueMax = null;
172
170
  }
173
171
  } else if (tableContext.paginationRepo?.filtering) {
174
- const gotValue = getFilteringStateValue();
172
+ const gotValue = filteringStateValue;
175
173
  if (gotValue != undefined) {
176
174
  const [min] = gotValue as [number, number | undefined];
177
175
  value = min;
@@ -182,7 +180,7 @@
182
180
  }
183
181
  }
184
182
  } else if (tableContext.paginationRepo?.filtering) {
185
- const gotValue = getFilteringStateValue();
183
+ const gotValue = filteringStateValue;
186
184
  if (gotValue == null || typeof gotValue == 'string' || typeof gotValue == 'number') {
187
185
  value = gotValue;
188
186
  }
@@ -296,9 +294,9 @@
296
294
  query={customFilter!.query!}
297
295
  bind:options={lastQueryOptions}
298
296
  onchange={(newValue) => {
299
- console.log(newValue);
300
297
  tableContext.paginationRepo?.filterBy(def.id, newValue?.value ?? null);
301
298
  tableContext.__queryValues.set(label, newValue);
299
+ value = newValue as SelectOption<string | number> | null;
302
300
  }}
303
301
  />
304
302
  {:else}
@@ -150,10 +150,8 @@
150
150
  );
151
151
 
152
152
  $effect(() => {
153
- if (isRemoteSelect) {
154
- if (!tableContext.paginationRepo?.filtering) {
155
- return;
156
- }
153
+ if (isRemoteSelect && !tableContext.paginationRepo?.filtering) {
154
+ return;
157
155
  }
158
156
  void filteringStateValue;
159
157
 
@@ -370,9 +368,9 @@
370
368
  query={customFilter!.query!}
371
369
  bind:options={lastQueryOptions}
372
370
  onchange={(newValue) => {
373
- console.log(newValue);
374
371
  tableContext.paginationRepo?.filterBy(def.id, newValue?.value ?? null);
375
372
  tableContext.__queryValues.set(label ?? _uuid, newValue);
373
+ value = newValue as SelectOption<string | number> | null;
376
374
  }}
377
375
  />
378
376
  {:else}
@@ -8,6 +8,7 @@ export interface ExpandDefProps<T extends object, R extends object> extends Colu
8
8
  headerIcon: IconProps['name'];
9
9
  innerTableName: string;
10
10
  innerTableOptions: TableInitOptions<R>;
11
+ accessorFn: (item: T, index: number) => R;
11
12
  }
12
13
  export declare class ExpandDef<T extends object, R extends object = object> extends ColumnDef<T> {
13
14
  readonly columnType: "Expand";
@@ -1,5 +1,5 @@
1
1
  export type NonNullableKey<T> = T extends null ? never : string & keyof T;
2
- export type ValueProp<V> = keyof V & string;
2
+ export type ValueProp<V> = V extends null ? never : keyof V & string;
3
3
  export type Unsubscriber = () => void;
4
4
  export type Pixels = number;
5
5
  export type BrandedString<T> = string & {
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.0.34",
4
+ "version": "0.0.36",
5
5
  "publishConfig": {
6
6
  "access": "restricted"
7
7
  },