@lavalogic/scoria 0.0.31 → 0.0.33

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.
@@ -12,6 +12,9 @@
12
12
  snippet: Snippet<[T, number]>;
13
13
  itemName?: string;
14
14
  border?: boolean;
15
+ padding?: string;
16
+ gap?: string;
17
+ height?: string;
15
18
  }
16
19
  </script>
17
20
 
@@ -22,7 +25,10 @@
22
25
  pageSize = 20,
23
26
  snippet,
24
27
  itemName = 'Item',
25
- border = false
28
+ border = false,
29
+ padding = '1.5rem', //sizing.$regular-padding
30
+ gap = '1.5rem', // sizing.$regular-gap
31
+ height
26
32
  }: PaginationProps<T> = $props();
27
33
 
28
34
  const _uuid = generateShortUUID();
@@ -80,7 +86,13 @@
80
86
  </div>
81
87
  </div> -->
82
88
 
83
- <div class="wrapper" class:border>
89
+ <div
90
+ class="wrapper"
91
+ class:border
92
+ style={`${padding ? `padding: ${padding};` : ''}` +
93
+ `${gap ? `gap: ${gap};` : ''}` +
94
+ `${height ? `height: ${height};` : ''}`}
95
+ >
84
96
  {#each pageItems as item, index (item[key])}
85
97
  {@render snippet(item, index)}
86
98
  {/each}
@@ -166,6 +178,8 @@
166
178
  <style>.wrapper {
167
179
  display: flex;
168
180
  flex: 1;
181
+ flex-flow: column nowrap;
182
+ overflow: scroll;
169
183
  }
170
184
  .wrapper.border {
171
185
  border: solid 3px #cbd4da;
@@ -186,9 +200,6 @@
186
200
  line-height: 1;
187
201
  bottom: 0;
188
202
  }
189
- .spread_row.limited {
190
- overflow: hidden;
191
- }
192
203
  .spread_row .scrollable {
193
204
  display: flex;
194
205
  flex-flow: row nowrap;
@@ -6,6 +6,9 @@ export interface PaginationProps<T extends object> {
6
6
  snippet: Snippet<[T, number]>;
7
7
  itemName?: string;
8
8
  border?: boolean;
9
+ padding?: string;
10
+ gap?: string;
11
+ height?: string;
9
12
  }
10
13
  declare function $$render<T extends object>(): {
11
14
  props: PaginationProps<T>;
@@ -34,6 +34,7 @@
34
34
  import { AccessorDef } from '../Types/Columns/Definitions/Accessors/AccessorDef.svelte.js';
35
35
  import { NumberInputDef } from '../Types/Columns/Definitions/Accessors/NumberInputDef.svelte.js';
36
36
  import { dev } from '$app/environment';
37
+ import { QuerySelect } from '../../../index.js';
37
38
 
38
39
  export interface QuickSearchCellProps<T extends object> {
39
40
  column: Column<T>;
@@ -77,6 +78,8 @@
77
78
  : []
78
79
  );
79
80
  const isDate = $derived(def instanceof DateInputDef);
81
+ const isRemoteSelect = $derived(customFilter?.type === CustomFilterType.Select);
82
+ const hasQuery = $derived(isRemoteSelect && customFilter?.query);
80
83
 
81
84
  let inputRef: HTMLInputElement | undefined = $state();
82
85
 
@@ -88,7 +91,7 @@
88
91
 
89
92
  const isSelectOpen = $derived(openedSelect?.value === selectSymbol);
90
93
 
91
- let value: string | number | null | undefined = $state(null);
94
+ let value: SelectOption<string | number> | string | number | null | undefined = $state(null);
92
95
  let valueMin: number | null = $state(null);
93
96
  let valueMax: number | null = $state(null);
94
97
 
@@ -98,6 +101,7 @@
98
101
  );
99
102
 
100
103
  let selectedOptions: Array<SelectOption<string | number>> = $state([]);
104
+ let lastQueryOptions: Array<SelectOption<unknown>> = $state([]);
101
105
 
102
106
  const inputId = $derived(`${tableContext.tableName}-cell-quicksearch-${column.id}`);
103
107
 
@@ -118,22 +122,38 @@
118
122
  }
119
123
 
120
124
  $effect(() => {
121
- if (isSelect) {
122
- if (!tableContext.paginationRepo?.filtering) {
123
- return;
124
- }
125
-
125
+ if (hasQuery) {
126
126
  untrack(async () => {
127
127
  const gotValue = getFilteringStateValue() as unknown as
128
128
  | Array<string | number | SelectOption<string | number>>
129
129
  | undefined;
130
- if (dev) {
131
- // eslint-disable-next-line no-debugger
132
- debugger;
133
- return;
130
+
131
+ try {
132
+ // as unknown as string | number | undefined;
133
+
134
+ if (gotValue != undefined) {
135
+ const key = customFilter?.label ?? customFilter?.objectName ?? customFilter?.queryKey;
136
+ const x = key == null ? null : tableContext.__queryValues.get(key);
137
+ value = (x ?? null) as SelectOption<string | number> | null;
138
+ }
139
+ } catch (e) {
140
+ console.warn(e);
141
+ value = null;
134
142
  }
135
- //TODO redo the below in a more performant way if possible
136
- const x = (await options).filter((it) => gotValue?.includes(it.value));
143
+ });
144
+ } else if (isSelect) {
145
+ if (!tableContext.paginationRepo?.filtering) {
146
+ return;
147
+ }
148
+
149
+ const gotValue = getFilteringStateValue() as unknown as
150
+ | Array<string | number | SelectOption<string | number>>
151
+ | undefined;
152
+
153
+ untrack(async () => {
154
+ const x = (await options).filter((it) => {
155
+ return (gotValue as unknown as Array<string | number> | undefined)?.includes(it.value);
156
+ });
137
157
  selectedOptions = x;
138
158
  });
139
159
  } else if (isNumeric) {
@@ -186,7 +206,7 @@
186
206
  } else {
187
207
  value = valueMin?.toString();
188
208
  }
189
- } else {
209
+ } else if (!hasQuery) {
190
210
  const gotValue = filterOption.value;
191
211
  if (gotValue == null || typeof gotValue == 'string' || typeof gotValue == 'number') {
192
212
  value = gotValue;
@@ -260,22 +280,49 @@
260
280
  {/if}
261
281
  {/if}
262
282
  {:else if isSelect}
263
- {#await options then options}
264
- <MultiSelect
265
- labelProp="label"
266
- valueProp="value"
267
- {options}
268
- valueAsObject
269
- onchange={(e) => {
270
- tableContext.paginationRepo?.filterBy(
271
- def.id,
272
- e.map((it) => it.value)
273
- );
274
- }}
275
- selectedValues={selectedOptions}
276
- collapseSelection
277
- />
278
- {/await}
283
+ {#if hasQuery}
284
+ {#if typeof value == 'object'}
285
+ {@const label =
286
+ customFilter!.label ?? customFilter?.objectName ?? customFilter!.queryKey!}
287
+ <!-- TODO: multiselect -->
288
+
289
+ <QuerySelect
290
+ valueAsObject
291
+ {label}
292
+ clearable
293
+ name={customFilter?.objectName ?? 'Item'}
294
+ valueProp="value"
295
+ labelProp="label"
296
+ selectedValue={value}
297
+ query={customFilter!.query!}
298
+ bind:options={lastQueryOptions}
299
+ onchange={(newValue) => {
300
+ console.log(newValue);
301
+ tableContext.paginationRepo?.filterBy(def.id, newValue?.value ?? null);
302
+ tableContext.__queryValues.set(label, newValue);
303
+ }}
304
+ />
305
+ {:else}
306
+ {@debug value}
307
+ {/if}
308
+ {:else}
309
+ {#await options then options}
310
+ <MultiSelect
311
+ labelProp="label"
312
+ valueProp="value"
313
+ {options}
314
+ valueAsObject
315
+ onchange={(e) => {
316
+ tableContext.paginationRepo?.filterBy(
317
+ def.id,
318
+ e.map((it) => it.value)
319
+ );
320
+ }}
321
+ selectedValues={selectedOptions}
322
+ collapseSelection
323
+ />
324
+ {/await}
325
+ {/if}
279
326
  {:else if isNumeric}
280
327
  {#if selectedNumberFilterType.value === NumberDateFilterMode.Between}
281
328
  <div class="input-wrapper left">
@@ -304,7 +351,7 @@
304
351
  onkeydown={closeOnCtrlF}
305
352
  />
306
353
  </div>
307
- {:else if typeof value != 'number'}
354
+ {:else if value == null || typeof value == 'string'}
308
355
  <div class="input-wrapper right">
309
356
  <TextInput
310
357
  data-type="quicksearch"
@@ -319,7 +366,7 @@
319
366
  />
320
367
  </div>
321
368
  {/if}
322
- {:else if typeof value != 'number'}
369
+ {:else if value == null || typeof value == 'string'}
323
370
  <div class="input-wrapper right">
324
371
  <TextInput
325
372
  data-type="quicksearch"
@@ -173,14 +173,9 @@
173
173
  value = null;
174
174
  }
175
175
  });
176
- } else if (def instanceof SelectDef) {
176
+ } else if (isSelect) {
177
177
  untrack(async () => {
178
178
  try {
179
- if (dev) {
180
- // eslint-disable-next-line no-debugger
181
- debugger;
182
- }
183
- // TODO see if we can change the below not to use array.includes
184
179
  const x = (await options).filter((it) => {
185
180
  return (filteringStateValue as unknown as Array<string | number> | undefined)?.includes(
186
181
  it.value
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.31",
4
+ "version": "0.0.33",
5
5
  "publishConfig": {
6
6
  "access": "restricted"
7
7
  },