@profitlich/template-toolkit 1.0.1 → 2.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/dev/Dev.js CHANGED
@@ -1,5 +1,4 @@
1
1
  import { Toolbar } from './toolbar/Toolbar.js';
2
- import { FormieFillIn } from './formie-fill-in/FormieFillIn.js';
3
2
 
4
3
  let _config = {};
5
4
 
@@ -12,8 +11,5 @@ export function initDev(config = {}) {
12
11
 
13
12
  document.addEventListener('DOMContentLoaded', () => {
14
13
  new Toolbar();
15
- if (_config.formie) {
16
- new FormieFillIn(_config.formie);
17
- }
18
14
  console.info('Dev initialized.');
19
15
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@profitlich/template-toolkit",
3
- "version": "1.0.1",
3
+ "version": "2.0.0",
4
4
  "description": "Shared SCSS layout system, JS utilities, components and build scripts for profitlich template repos",
5
5
  "type": "module",
6
6
  "exports": {
@@ -1,81 +0,0 @@
1
- /**
2
- * FormieFillIn – Füllt Formie-Formulare in der Entwicklungsumgebung automatisch aus.
3
- *
4
- * Initialisierung via initDev() in dev/Dev.js – kein manueller Aufruf nötig.
5
- *
6
- * Konfiguration in config.json (zwei Ebenen: Form-Handle → Feld-Handle → Wert):
7
- * "formie": {
8
- * "kontaktformular": {
9
- * "vorname": "Max",
10
- * "email": "max@example.com",
11
- * "nachricht": "Testanfrage"
12
- * }
13
- * }
14
- */
15
- export class FormieFillIn {
16
- #formConfig;
17
-
18
- /**
19
- * @param {Object} formConfig - Aus config.json, z.B. { kontaktformular: { email: 'test@example.com' } }
20
- */
21
- constructor(formConfig) {
22
- if (!formConfig || typeof formConfig !== 'object') return;
23
-
24
- this.#formConfig = formConfig;
25
- document.addEventListener('onFormieInit', this.#onFormieInit);
26
- }
27
-
28
- #onFormieInit = (e) => {
29
- const Formie = e.detail?.formie;
30
- if (!Formie) return;
31
-
32
- for (const [handle, fields] of Object.entries(this.#formConfig)) {
33
- const form = Formie.getFormByHandle(handle);
34
- if (!form?.$form) continue;
35
-
36
- this.#fillForm(form.$form, fields);
37
- console.info(`FormieFillIn: "${handle}" ausgefüllt.`);
38
- }
39
- };
40
-
41
- #fillForm(formElement, fields) {
42
- for (const [fieldHandle, value] of Object.entries(fields)) {
43
- const name = `fields[${fieldHandle}]`;
44
- const inputs = formElement.querySelectorAll(`[name="${name}"], [name="${name}[]"]`);
45
-
46
- if (!inputs.length) {
47
- console.warn(`FormieFillIn: Feld "${fieldHandle}" nicht gefunden.`);
48
- continue;
49
- }
50
-
51
- this.#setFieldValue(inputs, value);
52
- }
53
- }
54
-
55
- #setFieldValue(inputs, value) {
56
- const first = inputs[0];
57
- const type = first.type?.toLowerCase();
58
-
59
- if (type === 'radio') {
60
- inputs.forEach((radio) => {
61
- radio.checked = radio.value === String(value);
62
- if (radio.checked) radio.dispatchEvent(new Event('change', { bubbles: true }));
63
- });
64
- } else if (type === 'checkbox') {
65
- if (inputs.length === 1) {
66
- first.checked = Boolean(value);
67
- } else {
68
- // Checkbox-Gruppe: value ist Array mit den gewünschten Werten
69
- const selected = Array.isArray(value) ? value.map(String) : [String(value)];
70
- inputs.forEach((checkbox) => {
71
- checkbox.checked = selected.includes(checkbox.value);
72
- });
73
- }
74
- inputs.forEach((cb) => cb.dispatchEvent(new Event('change', { bubbles: true })));
75
- } else {
76
- first.value = value;
77
- first.dispatchEvent(new Event('input', { bubbles: true }));
78
- first.dispatchEvent(new Event('change', { bubbles: true }));
79
- }
80
- }
81
- }