@csedl/hotwire-svelte-helpers 4.5.0 → 4.7.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.
|
|
3
|
+
"version": "4.7.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": {
|
|
@@ -4,7 +4,11 @@
|
|
|
4
4
|
import { cleanMount } from "../cleanMount.js";
|
|
5
5
|
import { getOverlayTarget } from "../../lib/utils.js";
|
|
6
6
|
|
|
7
|
-
let {
|
|
7
|
+
let {
|
|
8
|
+
panel,
|
|
9
|
+
label,
|
|
10
|
+
svgIcon
|
|
11
|
+
} = $props();
|
|
8
12
|
|
|
9
13
|
let buttonElement, panelInstance;
|
|
10
14
|
|
|
@@ -24,12 +28,8 @@
|
|
|
24
28
|
DropdownPanel, {
|
|
25
29
|
target: getOverlayTarget(),
|
|
26
30
|
props: {
|
|
27
|
-
|
|
31
|
+
...panel,
|
|
28
32
|
closeFunction: closeDropdown,
|
|
29
|
-
buttonElement: buttonElement,
|
|
30
|
-
panelClass: panelClass,
|
|
31
|
-
content: panelContent,
|
|
32
|
-
placement: panelPlacement
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
);
|
|
@@ -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(
|
|
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'}
|
|
@@ -6,9 +6,9 @@
|
|
|
6
6
|
panelClass,
|
|
7
7
|
closeFunction,
|
|
8
8
|
content,
|
|
9
|
-
contentX,
|
|
10
9
|
actionButtonLabel,
|
|
11
10
|
actionButtonFunction,
|
|
11
|
+
actionButtonClass,
|
|
12
12
|
} = $props()
|
|
13
13
|
let panelElement
|
|
14
14
|
|
|
@@ -63,17 +63,17 @@
|
|
|
63
63
|
</div>
|
|
64
64
|
{/if}
|
|
65
65
|
|
|
66
|
-
|
|
67
|
-
|
|
66
|
+
{#if actionButtonLabel}
|
|
67
|
+
<div class="footer">
|
|
68
68
|
<span
|
|
69
69
|
role="button"
|
|
70
70
|
tabindex="0"
|
|
71
71
|
onkeydown={(e) => {}}
|
|
72
|
-
class="action button"
|
|
72
|
+
class={actionButtonClass || "action button"}
|
|
73
73
|
onclick={actionButtonFunction}>
|
|
74
74
|
{actionButtonLabel}
|
|
75
75
|
</span>
|
|
76
|
-
|
|
77
|
-
|
|
76
|
+
</div>
|
|
77
|
+
{/if}
|
|
78
78
|
</div>
|
|
79
79
|
</div>
|
|
@@ -4,7 +4,12 @@
|
|
|
4
4
|
import { cleanMount } from "../cleanMount.js";
|
|
5
5
|
import { getOverlayTarget } from "../../lib/utils.js";
|
|
6
6
|
|
|
7
|
-
let {
|
|
7
|
+
let {
|
|
8
|
+
label,
|
|
9
|
+
svgIcon,
|
|
10
|
+
modal,
|
|
11
|
+
beforeOpen
|
|
12
|
+
} = $props()
|
|
8
13
|
let modalInstance;
|
|
9
14
|
|
|
10
15
|
export function closeModal() {
|
|
@@ -14,12 +19,12 @@
|
|
|
14
19
|
};
|
|
15
20
|
|
|
16
21
|
function openModal() {
|
|
22
|
+
beforeOpen()
|
|
17
23
|
|
|
18
24
|
modalInstance = cleanMount(Modal, {
|
|
19
25
|
target: getOverlayTarget(),
|
|
20
26
|
props: {
|
|
21
|
-
|
|
22
|
-
content: panelContent,
|
|
27
|
+
...modal,
|
|
23
28
|
closeFunction: closeModal
|
|
24
29
|
}
|
|
25
30
|
});
|