@csedl/hotwire-svelte-helpers 4.2.1 → 4.4.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/README.md
CHANGED
|
@@ -45,7 +45,7 @@ to your application.js. This will check for detached instances and unmount them.
|
|
|
45
45
|
## Dropdown Example
|
|
46
46
|
|
|
47
47
|
```html
|
|
48
|
-
<div data-controller="
|
|
48
|
+
<div data-controller="hotwire-svelte-helpers-dropdown" data-panel-id="dropdown-panel-3h5k7l4">
|
|
49
49
|
Button
|
|
50
50
|
</div>
|
|
51
51
|
<div id="dropdown-panel-3h5k7l4" class="dropdownSvelte-panel-example-class" style="display: none;">
|
|
@@ -149,7 +149,7 @@ What these helpers mainly do is to find all the dropdowns by the `has-open-panel
|
|
|
149
149
|
## Tooltip
|
|
150
150
|
|
|
151
151
|
```html
|
|
152
|
-
<span data-controller="
|
|
152
|
+
<span data-controller="hotwire-svelte-helpers-tooltip" data-panel-id="tooltip-123" data-delay="0.2">
|
|
153
153
|
Text-with-tooltip
|
|
154
154
|
</span>
|
|
155
155
|
<div id="tooltip-123" class="tooltip-panel" style="display: none;">
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@csedl/hotwire-svelte-helpers",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.4.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": {
|
|
@@ -21,7 +21,7 @@ export function getAllOpenPanels(scopeElement) {
|
|
|
21
21
|
const elements = []
|
|
22
22
|
|
|
23
23
|
for (const button of buttons) {
|
|
24
|
-
if (button.getAttribute('data-controller') === '
|
|
24
|
+
if (button.getAttribute('data-controller') === 'hotwire-svelte-helpers-dropdown') {
|
|
25
25
|
const getOrSetPanelId = button.getAttribute('data-panel-id')
|
|
26
26
|
const panel = document.getElementById(getOrSetPanelId)
|
|
27
27
|
elements.push([button, panel])
|
package/src/lib/initializers.js
CHANGED
|
@@ -2,6 +2,7 @@ import {debugLog} from "./utils.js";
|
|
|
2
2
|
import {Application} from "@hotwired/stimulus"
|
|
3
3
|
import dc from '../stimulus/dropdown-controller'
|
|
4
4
|
import ttc from '../stimulus/tooltip-controller'
|
|
5
|
+
import mod from '../stimulus/modal-controller'
|
|
5
6
|
import ppc from '../stimulus/move-panels-controller'
|
|
6
7
|
|
|
7
8
|
|
|
@@ -30,9 +31,10 @@ const HotwireSvelteHelpers = {
|
|
|
30
31
|
|
|
31
32
|
const Stimulus = Application.start()
|
|
32
33
|
|
|
33
|
-
Stimulus.register('
|
|
34
|
-
Stimulus.register('
|
|
35
|
-
Stimulus.register('
|
|
34
|
+
Stimulus.register('hotwire-svelte-helpers-modal', mod)
|
|
35
|
+
Stimulus.register('hotwire-svelte-helpers-dropdown', dc)
|
|
36
|
+
Stimulus.register('hotwire-svelte-helpers-tooltip', ttc)
|
|
37
|
+
Stimulus.register('hotwire-svelte-helpers-move-panels', ppc)
|
|
36
38
|
|
|
37
39
|
debugLog('Overlays active, driven by Stimulus')
|
|
38
40
|
|
package/src/lib/utils.js
CHANGED
|
@@ -11,11 +11,13 @@ export function openDropdownPanel(buttonElement, panelElement, options = {}) {
|
|
|
11
11
|
|
|
12
12
|
// link button and panel, initialize
|
|
13
13
|
panelElement.id = getOrSetPanelId(buttonElement);
|
|
14
|
-
initializeDropdown(buttonElement)
|
|
15
|
-
debugLog(`opening panel ${panelElement.id.split('-').pop()}
|
|
16
|
-
panelElement.style.display = 'block';
|
|
14
|
+
initializeDropdown(buttonElement, options)
|
|
15
|
+
debugLog(`opening panel ${panelElement.id.split('-').pop()}`, options)
|
|
16
|
+
panelElement.style.display = (options.isModal ? 'flex' : 'block');
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
if (!options.isModal) {
|
|
19
|
+
positionPanel(buttonElement, panelElement);
|
|
20
|
+
}
|
|
19
21
|
|
|
20
22
|
// Set focus to input element
|
|
21
23
|
if (panelElement.hasAttribute('data-set-focus')) {
|
|
@@ -49,10 +51,10 @@ export function openDropdownPanel(buttonElement, panelElement, options = {}) {
|
|
|
49
51
|
const buttonElement = document.querySelector(`[data-panel-id="${panelElement.id}"]`);
|
|
50
52
|
const ctrl = buttonElement.getAttribute('data-controller');
|
|
51
53
|
|
|
52
|
-
if (ctrl === '
|
|
54
|
+
if (ctrl === 'hotwire-svelte-helpers-dropdown') {
|
|
53
55
|
const wrapper = panelElement.querySelector('.content');
|
|
54
56
|
wrapper.innerHTML = xhr.response;
|
|
55
|
-
} else if (ctrl === '
|
|
57
|
+
} else if (ctrl === 'hotwire-svelte-helpers-tooltip') {
|
|
56
58
|
const wrapper = panelElement.querySelector('.content');
|
|
57
59
|
wrapper.innerHTML = xhr.response;
|
|
58
60
|
} else {
|
|
@@ -152,7 +154,7 @@ export function closeOnOutsideClick(clickedElement) {
|
|
|
152
154
|
|
|
153
155
|
// Add panel functionality, including close event listeners
|
|
154
156
|
|
|
155
|
-
export function initializeDropdown(button) {
|
|
157
|
+
export function initializeDropdown(button, options = {}) {
|
|
156
158
|
|
|
157
159
|
// find panel
|
|
158
160
|
const panel_id = button.getAttribute('data-panel-id');
|
|
@@ -187,6 +189,12 @@ export function initializeDropdown(button) {
|
|
|
187
189
|
debugLog('initializeDropdown: panel already initialized:', panel.id.split('-').pop())
|
|
188
190
|
}
|
|
189
191
|
|
|
192
|
+
// return if isModal
|
|
193
|
+
|
|
194
|
+
if (options.isModal) {
|
|
195
|
+
return
|
|
196
|
+
}
|
|
197
|
+
|
|
190
198
|
// initialize the button
|
|
191
199
|
if (!button.hasAttribute('data-hsh-initialized')) {
|
|
192
200
|
button.setAttribute('data-hsh-initialized', 'true');
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Controller } from "@hotwired/stimulus"
|
|
2
|
+
import { openDropdownPanel, closePanel, findPanelOrThrow } from "../lib/utils.js";
|
|
3
|
+
import { debugLog } from "../lib/utils.js";
|
|
4
|
+
|
|
5
|
+
export default class extends Controller {
|
|
6
|
+
|
|
7
|
+
connect() {
|
|
8
|
+
|
|
9
|
+
this.element.addEventListener('click', (e) => this.toggle(e))
|
|
10
|
+
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
toggle(e) {
|
|
15
|
+
if (this.element.getAttribute('data-prevent-default')) {
|
|
16
|
+
e.preventDefault()
|
|
17
|
+
}
|
|
18
|
+
e.stopPropagation()
|
|
19
|
+
debugLog('toggle panel', e)
|
|
20
|
+
|
|
21
|
+
const panel = findPanelOrThrow(this.element)
|
|
22
|
+
if (panel.style.display === 'block') {
|
|
23
|
+
closePanel(this.element)
|
|
24
|
+
} else {
|
|
25
|
+
openDropdownPanel(this.element, panel, {isModal: true})
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
autocomplete = 'on'
|
|
10
10
|
} = $props();
|
|
11
11
|
|
|
12
|
-
let model = $derived(context._schema.self.
|
|
12
|
+
let model = $derived(context._schema.self.paramKey)
|
|
13
13
|
let columnSchema = $derived(context._schema[columnName])
|
|
14
14
|
let value = $derived(context[columnName])
|
|
15
15
|
let inputType = $derived.by(() => {
|
|
@@ -67,7 +67,8 @@
|
|
|
67
67
|
id="{model}_{columnName}"
|
|
68
68
|
name="{model}[{columnSchema.key}]"
|
|
69
69
|
value="{value}"
|
|
70
|
-
class="input-field"
|
|
70
|
+
class="input-field"
|
|
71
|
+
></textarea>
|
|
71
72
|
{:else}
|
|
72
73
|
<input
|
|
73
74
|
id="{model}_{columnName}"
|