@csedl/hotwire-svelte-helpers 2.3.0 → 3.0.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
@@ -15,56 +15,6 @@ HotwireSvelteHelpers.debug = true
15
15
  HotwireSvelteHelpers.initializeOverlays()
16
16
  ```
17
17
 
18
- This package has a Server-Side Rendering (SSR) safe configuration, which means:
19
-
20
- You must add the file `<vite-sourcee-code-dir>/config/hotwire-svelte-helpers.js`.
21
- The package inside does a fixed `import customConfigs from '@/config/hotwire-svelte-helpers.js'`.
22
- By this, it must find that file.
23
-
24
- The alias `@` is by default a alias set by vite_rails, pointing to `sourceCodeDir`.
25
- For this package it is required not to change override this.
26
-
27
- Minimal content of this file:
28
-
29
- ```javascript
30
- export default {
31
- }
32
- ```
33
-
34
- ## Configuration
35
-
36
- The package-internal default configs, which can be overwritten hereby, are:
37
-
38
- ```javascript
39
- export default {
40
- closeButtonSelector: '.close-button',
41
- dropdownContentSelector: '.content',
42
- // when a data-src attribute is added to the panel, the content-tag is replaced by the result of the xhr-response
43
- tooltipContentSelector: '.content',
44
- // same as dropdownContentSelector
45
- addArrow: true,
46
- // add element with id #arrow within the panel, on opening
47
- persistTooltipOnClick: false,
48
- // clicking on the tooltip-label causes the tooltip-panel to persist open
49
- // this may mostly be helpful for development, so you may make it environment-dependent
50
- closeButtonSvg: null,
51
- // raw import of svg-icon,
52
-
53
- formFieldWrapperClass: 'form-field-wrapper',
54
- formFieldLabelWrapperClass: 'form-field-label-wrapper',
55
- formFieldInputWrapperClass: 'form-field-input-wrapper',
56
- }
57
- ```
58
-
59
- The code you can find in this package under `src/lib/configs.js`
60
-
61
- You can add as many keys as you like and fetch them from anywhere by:
62
-
63
- ```javascript
64
- import { hotwireSvelteConfig } from "@csedl/hotwire-svelte-helpers";
65
- hotwireSvelteConfig('closeButtonSelector')
66
- ```
67
-
68
18
  ## cleanMount()
69
19
 
70
20
  Interaction with (Svelte) components can lead to orphaned instances.
package/index.js CHANGED
@@ -1,10 +1,9 @@
1
1
 
2
2
  import { cleanMount, unmountAllDetached } from './src/svelte/cleanMount.js';
3
3
  import { initializeDropdown, openDropdownPanel, getOrSetPanelId, debugLog, getCsrfToken } from './src/lib/utils.js'
4
- import { hotwireSvelteConfig } from './src/lib/config.js'
5
4
 
6
5
  export {
7
- cleanMount, unmountAllDetached, hotwireSvelteConfig,
6
+ cleanMount, unmountAllDetached,
8
7
  initializeDropdown, openDropdownPanel, getOrSetPanelId,
9
8
  debugLog, getCsrfToken
10
9
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@csedl/hotwire-svelte-helpers",
3
- "version": "2.3.0",
3
+ "version": "3.0.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": {
@@ -58,6 +58,7 @@
58
58
  "homepage": "https://gitlab.com/sedl/csedl-hotwire-svelte-helpers",
59
59
  "dependencies": {
60
60
  "@floating-ui/dom": ">=1.5.1",
61
- "@hotwired/stimulus": ">=3.2.1"
61
+ "@hotwired/stimulus": ">=3.2.1",
62
+ "fast-glob": ">=3.3.3"
62
63
  }
63
64
  }
package/src/lib/utils.js CHANGED
@@ -1,5 +1,4 @@
1
1
  import {positionPanelSelf, positionPanelByButton, positionPanel} from "./floating-ui-functions.js";
2
- import {hotwireSvelteConfig} from "./config.js";
3
2
 
4
3
  // Fetch content from server based on panel's data-src attribute and update content
5
4
  export function openDropdownPanel(buttonElement, panelElement, options = {}) {
@@ -15,15 +14,6 @@ export function openDropdownPanel(buttonElement, panelElement, options = {}) {
15
14
  debugLog(`opening panel ${panelElement.id.split('-').pop()}`)
16
15
  panelElement.style.display = 'block';
17
16
 
18
- // add arrow
19
- if (hotwireSvelteConfig('addArrow')) {
20
- if (!panelElement.querySelector(':scope > #arrow')) {
21
- const arrowTag = document.createElement('div');
22
- arrowTag.id = 'arrow';
23
- panelElement.appendChild(arrowTag)
24
- }
25
- }
26
-
27
17
  positionPanel(buttonElement, panelElement);
28
18
 
29
19
  // Set focus to input element
@@ -57,18 +47,14 @@ export function openDropdownPanel(buttonElement, panelElement, options = {}) {
57
47
  } else {
58
48
  const buttonElement = document.querySelector(`[data-panel-id="${panelElement.id}"]`);
59
49
  const ctrl = buttonElement.getAttribute('data-controller');
60
- const contentSelector = hotwireSvelteConfig('dropdownContentSelector');
61
50
 
62
- if (ctrl === 'csedl-dropdown' && contentSelector) {
63
- debugLog(`dropdown / contentSelector: «${contentSelector}»`);
64
- const wrapper = panelElement.querySelector(contentSelector);
51
+ if (ctrl === 'csedl-dropdown' ) {
52
+ const wrapper = panelElement.querySelector('.content');
65
53
  wrapper.innerHTML = xhr.response;
66
- } else if (ctrl === 'csedl-tooltip' && contentSelector) {
67
- debugLog(`tooltip / contentSelector: «${contentSelector}»`);
68
- const wrapper = panelElement.querySelector(hotwireSvelteConfig('tooltipContentSelector'));
54
+ } else if (ctrl === 'csedl-tooltip') {
55
+ const wrapper = panelElement.querySelector('.content');
69
56
  wrapper.innerHTML = xhr.response;
70
57
  } else {
71
- debugLog(`? / contentSelector: «${contentSelector}»`);
72
58
  panelElement.innerHTML = xhr.response;
73
59
  console.error('fallback to replace whole panel');
74
60
  }
@@ -182,8 +168,7 @@ export function initializeDropdown(button) {
182
168
 
183
169
  // Add close button functionality
184
170
 
185
- const selector = hotwireSvelteConfig('closeButtonSelector');
186
- const closeButtons = panel.querySelectorAll(selector);
171
+ const closeButtons = panel.querySelectorAll('.close-button');
187
172
  for (const btn of closeButtons) {
188
173
  btn.addEventListener('click', () => {
189
174
  const ev = new Event('close');
@@ -1,7 +1,6 @@
1
1
  import {Controller} from "@hotwired/stimulus"
2
2
  import {positionPanelByButton} from "../lib/floating-ui-functions.js";
3
3
  import { debugLog, findPanelOrThrow, openDropdownPanel} from "../lib/utils.js";
4
- import {hotwireSvelteConfig} from "../lib/config.js";
5
4
 
6
5
  export default class extends Controller {
7
6
 
@@ -18,9 +17,7 @@ export default class extends Controller {
18
17
  }
19
18
  this.element.addEventListener('mouseenter', (e) => this.start_opening(e, panel_id, delay_sec * 1000))
20
19
  this.element.addEventListener('mouseleave', (e) => this.close(e, panel_id))
21
- if (hotwireSvelteConfig('persistTooltipOnClick')) {
22
- this.element.addEventListener('click', (e) => this.toggleByClick(e, panel_id))
23
- }
20
+ this.element.addEventListener('click', (e) => this.toggleByClick(e, panel_id))
24
21
  }
25
22
 
26
23
  start_opening(e, panel_id, delay_ms) {
@@ -1,5 +1,5 @@
1
1
  <script>
2
- import { openDropdownPanel, hotwireSvelteConfig } from "@csedl/hotwire-svelte-helpers";
2
+ import { openDropdownPanel } from "@csedl/hotwire-svelte-helpers";
3
3
  import { onMount } from "svelte";
4
4
 
5
5
  let {
@@ -26,18 +26,6 @@
26
26
  }, 0)
27
27
  }
28
28
 
29
- function closeSvg() {
30
- const value = hotwireSvelteConfig('closeButtonSvg');
31
-
32
- if (!value) return '?';
33
-
34
- if (typeof value === 'function') {
35
- return value();
36
- }
37
-
38
- return String(value);
39
- }
40
-
41
29
  </script>
42
30
 
43
31
  <div class="dropdown-panel {panelClass}" bind:this={panelElement} onclose={closeFunc}>
@@ -48,8 +36,9 @@
48
36
  {title || 'missing title'}
49
37
  </span>
50
38
  <span class="buttons">
51
- <button class={ hotwireSvelteConfig('closeButtonSelector').replace('.', '') || 'close-btn' }
52
- onclick={closeFunction}>{@html closeSvg()}
39
+ <button class='close-button'
40
+ onclick={closeFunction}>
41
+ X
53
42
  </button>
54
43
  </span>
55
44
  </div>
@@ -1,7 +1,5 @@
1
1
  <script>
2
2
 
3
- import { hotwireSvelteConfig } from "../../lib/config.js";
4
-
5
3
  let {
6
4
  context,
7
5
  columnName,
@@ -47,11 +45,11 @@
47
45
  </script>
48
46
 
49
47
 
50
- <div class="{hotwireSvelteConfig('formFieldWrapperClass')} {model}_{columnName} {inputType} {fieldErrorsClass}">
51
- <div class={hotwireSvelteConfig('formFieldLabelWrapperClass')}>
48
+ <div class="hotwire-svelte-helpers-form-input {model}_{columnName} {inputType} {fieldErrorsClass}">
49
+ <div class='label-wrapper'>
52
50
  <label for="{model}_{columnName}">{label()}</label>
53
51
  </div>
54
- <div class={hotwireSvelteConfig('formFieldInputWrapperClass')}>
52
+ <div class='input-wrapper'>
55
53
 
56
54
  {#if columnSchema.enum}
57
55
  <select
@@ -1,5 +1,4 @@
1
1
  <script>
2
- import {hotwireSvelteConfig} from "@csedl/hotwire-svelte-helpers";
3
2
  import {onMount} from "svelte";
4
3
 
5
4
  let {
@@ -22,12 +21,6 @@
22
21
  }, 0)
23
22
  }
24
23
 
25
- function closeSvg() {
26
- const path = hotwireSvelteConfig('closeButtonSvg');
27
- const svg = (path ? path : '?')
28
- return svg;
29
- }
30
-
31
24
  export function setTitle(newTitle) {
32
25
  title = newTitle
33
26
  }
@@ -42,8 +35,9 @@
42
35
  {title || 'missing title'}
43
36
  </span>
44
37
  <span class="buttons">
45
- <button class={ hotwireSvelteConfig('closeButtonSelector').replace('.', '') || 'close-btn' }
46
- onclick={closeFunction}>{@html closeSvg()}
38
+ <button class='close-button'
39
+ onclick={closeFunction}>
40
+ X
47
41
  </button>
48
42
  </span>
49
43
  </div>
package/src/lib/config.js DELETED
@@ -1,25 +0,0 @@
1
- import customConfigs from '@/config/hotwire-svelte-helpers.js'
2
-
3
- export function hotwireSvelteConfig(key) {
4
-
5
- const defaultConfig = {
6
- closeButtonSelector: '.close-button',
7
- dropdownContentSelector: '.content',
8
- tooltipContentSelector: '.content',
9
- addArrow: true,
10
- persistTooltipOnClick: false,
11
- closeButtonSvg: '',
12
-
13
- formFieldWrapperClass: 'form-field-wrapper',
14
- formFieldLabelWrapperClass: 'form-field-label-wrapper',
15
- formFieldInputWrapperClass: 'form-field-input-wrapper',
16
- }
17
-
18
- const configs = {...defaultConfig, ...customConfigs}
19
-
20
- if (!Object.keys(configs).includes(key)) {
21
- throw new Error(`[@csedl/hotwire-svelte-helpers] unknown config key: ${key}, actual keys are:\n • ${Object.keys(configs).join("\n • ")}`)
22
- }
23
-
24
- return configs[key] || null
25
- }