grav-svelte 0.0.73 → 0.0.75

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.
@@ -13,6 +13,7 @@
13
13
  <button
14
14
  type="button"
15
15
  class="{item[header.colorField ?? ''] ?? ''} dynamic-button "
16
+ style="{header.styleField ? (item[header.styleField] ?? '') : ''}"
16
17
  on:click={() => {
17
18
  if (header.onButtonClick) {
18
19
  header.onButtonClick(item[idField], item);
@@ -39,6 +39,12 @@ export interface TableHeader {
39
39
  * Used for DynamicButton type.
40
40
  */
41
41
  colorField?: string;
42
+ /**
43
+ * Field name that contains inline CSS styles for the dynamic button.
44
+ * Used for DynamicButton type.
45
+ * Has higher specificity than colorField classes, useful for avoiding CSS hierarchy conflicts.
46
+ */
47
+ styleField?: string;
42
48
  /**
43
49
  * Field name that contains the icon class (e.g., Font Awesome class).
44
50
  * Used for DynamicButton type.
@@ -2,17 +2,49 @@
2
2
  import { onMount } from 'svelte';
3
3
  import InputFormSelect from './InputFormSelect.svelte';
4
4
 
5
- export let levels = []; // [{ label, fetchFn, default, field }]
5
+ export let levels = []; // [{ label, fetchFn, default, field, showPlusIcon?, onPlusClick? }]
6
6
  // Cargar datos iniciales para el primer nivel
7
7
  let varS = false;
8
8
  let fetchFnCloned = [];
9
9
  export let selectedValues = {};
10
- onMount(() => {
10
+
11
+ onMount(async () => {
11
12
  varS = false;
13
+
14
+ // Clonar las funciones fetch
12
15
  levels.forEach((item) => {
13
16
  fetchFnCloned.push({ fetchFn: item.fetchFn });
14
- selectedValues[item.field] = item.default?.value;
15
17
  });
18
+
19
+ // Si hay valores iniciales, cargar y establecer los objetos Select completos
20
+ for (let i = 0; i < levels.length; i++) {
21
+ const level = levels[i];
22
+ const initialValue = selectedValues[level.field];
23
+
24
+ if (initialValue) {
25
+ // Cargar las opciones para este nivel
26
+ let options = [];
27
+ if (i === 0) {
28
+ options = await fetchFnCloned[i].fetchFn();
29
+ } else {
30
+ // Para niveles subsecuentes, necesitamos el valor del nivel anterior
31
+ const parentValue = selectedValues[levels[i - 1].field];
32
+ if (parentValue) {
33
+ options = await fetchFnCloned[i].fetchFn(parentValue);
34
+ }
35
+ }
36
+
37
+ // Buscar el objeto Select que coincida con el valor inicial
38
+ const selectedOption = options.find(opt => opt.value == initialValue);
39
+ if (selectedOption) {
40
+ levels[i].default = selectedOption;
41
+ cacheResults[i] = options; // Cachear los resultados
42
+ }
43
+ } else {
44
+ selectedValues[level.field] = level.default?.value;
45
+ }
46
+ }
47
+
16
48
  varS = true;
17
49
  });
18
50
 
@@ -44,6 +76,8 @@
44
76
  {res}
45
77
  changeFunction={(e) => handleChange(0, e.detail, level.field)}
46
78
  onClear={() => handleChange(0, null, level.field)}
79
+ showPlusIcon={level.showPlusIcon ?? false}
80
+ onPlusClick={level.onPlusClick ?? (() => {})}
47
81
  />
48
82
  {/await}
49
83
  {/if}
@@ -62,6 +96,8 @@
62
96
  {res}
63
97
  changeFunction={(e) => handleChange(i, e.detail, level.field)}
64
98
  onClear={() => handleChange(i, null, level.field)}
99
+ showPlusIcon={level.showPlusIcon ?? false}
100
+ onPlusClick={level.onPlusClick ?? (() => {})}
65
101
  />
66
102
  {/await}
67
103
  {:else}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "grav-svelte",
3
- "version": "0.0.73",
3
+ "version": "0.0.75",
4
4
  "description": "A collection of Svelte components",
5
5
  "license": "MIT",
6
6
  "scripts": {