@csedl/hotwire-svelte-helpers 4.5.0 → 4.6.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@csedl/hotwire-svelte-helpers",
3
- "version": "4.5.0",
3
+ "version": "4.6.0",
4
4
  "description": "Hotwire + Svelte helpers for Rails: Stimulus floating dropdowns/toolips + Svelte global panels/modals + RTurbo-friendly utilities. Build together with the rubygem svelte-on-rails and its npm-package.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -6,11 +6,25 @@
6
6
  errors,
7
7
  onChangeFunction,
8
8
  type,
9
- autocomplete = 'on'
9
+ autocomplete = 'on',
10
+ collection,
11
+ includeBlank = false,
10
12
  } = $props();
11
13
 
12
14
  let model = $derived(context._schema.self.paramKey)
13
- let columnSchema = $derived(context._schema[columnName])
15
+ let columnSchema = $derived.by(() => {
16
+ const cnt = context._schema[columnName]
17
+ if (!cnt) {
18
+ const keys = Object.keys(context._schema).sort()
19
+ if (keys.length > 0) {
20
+ throw new Error(`Column ${columnName} not found in schema, available keys in _schema are:\n • ${keys.join('\n • ')}`)
21
+ } else {
22
+ throw new Error(`Column ${columnName} not found in schema, _schema is empty!`)
23
+ }
24
+
25
+ }
26
+ return cnt
27
+ })
14
28
  let value = $derived(context[columnName])
15
29
  let inputType = $derived.by(() => {
16
30
  const t = {
@@ -55,11 +69,23 @@
55
69
  <select
56
70
  id="{model}_{columnName}"
57
71
  name="{model}[{columnSchema.key}]"
58
- value="{value}"
59
72
  onchange="{onChangeFunction}"
60
73
  class="input-field">
61
74
  {#each Object.entries(columnSchema.enum) as [key, label]}
62
- <option value="{key}">{label}</option>
75
+ <option value="{key}" selected={key == value}>{label}</option>
76
+ {/each}
77
+ </select>
78
+ {:else if collection}
79
+ <select
80
+ id="{model}_{columnName}"
81
+ name="{model}[{columnSchema.key}]"
82
+ onchange="{onChangeFunction}"
83
+ class="input-field">
84
+ {#if includeBlank}
85
+ <option></option>
86
+ {/if}
87
+ {#each Object.entries(collection) as [key, label]}
88
+ <option value="{key}" selected={key == value}>{label}</option>
63
89
  {/each}
64
90
  </select>
65
91
  {:else if inputType === 'textarea'}