@profitlich/template-toolkit 1.0.0 → 1.0.1

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.
@@ -1,10 +1,7 @@
1
1
  /**
2
2
  * FormieFillIn – Füllt Formie-Formulare in der Entwicklungsumgebung automatisch aus.
3
3
  *
4
- * Initialisierung im Projekt-Dev-Script:
5
- * import config from '../config.json';
6
- * import { FormieFillIn } from 'profitlich-template-toolkit/dev/formie-fill-in/FormieFillIn';
7
- * new FormieFillIn(config.formie);
4
+ * Initialisierung via initDev() in dev/Dev.js – kein manueller Aufruf nötig.
8
5
  *
9
6
  * Konfiguration in config.json (zwei Ebenen: Form-Handle → Feld-Handle → Wert):
10
7
  * "formie": {
@@ -28,25 +25,18 @@ export class FormieFillIn {
28
25
  document.addEventListener('onFormieInit', this.#onFormieInit);
29
26
  }
30
27
 
31
- #onFormieInit = () => {
32
- const forms = document.querySelectorAll('form[data-fui-form]');
33
- forms.forEach((formElement) => {
34
- const handle = this.#getFormHandle(formElement);
35
- if (!handle || !this.#formConfig[handle]) return;
28
+ #onFormieInit = (e) => {
29
+ const Formie = e.detail?.formie;
30
+ if (!Formie) return;
36
31
 
37
- this.#fillForm(formElement, this.#formConfig[handle]);
38
- console.info(`FormieFillIn: "${handle}" ausgefüllt.`);
39
- });
40
- };
32
+ for (const [handle, fields] of Object.entries(this.#formConfig)) {
33
+ const form = Formie.getFormByHandle(handle);
34
+ if (!form?.$form) continue;
41
35
 
42
- #getFormHandle(formElement) {
43
- try {
44
- const data = JSON.parse(formElement.getAttribute('data-fui-form'));
45
- return data?.handle ?? null;
46
- } catch {
47
- return null;
36
+ this.#fillForm(form.$form, fields);
37
+ console.info(`FormieFillIn: "${handle}" ausgefüllt.`);
48
38
  }
49
- }
39
+ };
50
40
 
51
41
  #fillForm(formElement, fields) {
52
42
  for (const [fieldHandle, value] of Object.entries(fields)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@profitlich/template-toolkit",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Shared SCSS layout system, JS utilities, components and build scripts for profitlich template repos",
5
5
  "type": "module",
6
6
  "exports": {