@formique/semantq 1.1.0 → 1.1.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.
Files changed (2) hide show
  1. package/formique-semantq.js +45 -178
  2. package/package.json +1 -1
@@ -1728,12 +1728,10 @@ if (attributes.binding === 'bind:value' && name) {
1728
1728
  // Textarea field rendering
1729
1729
 
1730
1730
  renderTextAreaField(type, name, label, validate, attributes) {
1731
- const textInputValidationAttributes = [
1732
- 'required',
1733
- 'minlength',
1734
- 'maxlength',
1735
- 'pattern',
1736
- ];
1731
+ const textInputValidationAttributes = ['required', 'minlength', 'maxlength', 'pattern'];
1732
+
1733
+ // 1. Extract content value to place between tags later
1734
+ const textareaValue = attributes.value || '';
1737
1735
 
1738
1736
  // Construct validation attributes
1739
1737
  let validationAttrs = '';
@@ -1743,115 +1741,74 @@ renderTextAreaField(type, name, label, validate, attributes) {
1743
1741
  if (typeof value === 'boolean' && value) {
1744
1742
  validationAttrs += ` ${key}\n`;
1745
1743
  } else {
1746
- switch (key) {
1747
- case 'pattern':
1748
- case 'minlength':
1749
- case 'maxlength':
1750
- validationAttrs += ` ${key}="${value}"\n`;
1751
- break;
1752
- default:
1753
- if (!textInputValidationAttributes.includes(key)) {
1754
- console.warn(`\x1b[31mUnsupported validation attribute '${key}' for field '${name}' of type 'number'.\x1b[0m`);
1755
- }
1756
- break;
1757
- }
1744
+ validationAttrs += ` ${key}="${value}"\n`;
1758
1745
  }
1759
1746
  } else {
1760
- console.warn(`\x1b[31mUnsupported validation attribute '${key}' for field '${name}' of type 'text'.\x1b[0m`);
1747
+ console.warn(`\x1b[31mUnsupported validation attribute '${key}' for field '${name}' of type 'textarea'.\x1b[0m`);
1761
1748
  }
1762
1749
  });
1763
1750
  }
1764
1751
 
1765
-
1766
-
1767
1752
  // Handle the binding syntax
1768
1753
  let bindingDirective = '';
1769
- if (attributes.binding) {
1770
- if (attributes.binding === 'bind:value' && name) {
1754
+ if (attributes.binding && name) {
1771
1755
  bindingDirective = `bind:value="${name}"\n`;
1772
1756
  }
1773
- if (attributes.binding.startsWith('::') && name) {
1774
- bindingDirective = `bind:value="${name}"\n`;
1775
- }
1776
- if (attributes.binding && !name) {
1777
- console.log(`\x1b[31m%s\x1b[0m`, `You cannot set binding value when there is no name attribute defined in ${name} ${type} field.`);
1778
- return;
1779
- }
1780
- }
1781
-
1782
1757
 
1783
-
1784
- // Get the id from attributes or fall back to name
1785
1758
  let id = attributes.id || name;
1786
- // Determine if semanti is true based on formSettings
1787
1759
  const framework = this.formSettings?.framework || false;
1788
1760
 
1789
- // Construct additional attributes dynamically
1761
+ // Construct additional attributes (excluding internal keys and the 'value' content)
1790
1762
  let additionalAttrs = '';
1791
1763
  for (const [key, value] of Object.entries(attributes)) {
1792
- if (key !== 'id' && key !== 'class' && key !== 'dependsOn' && key !== 'dependents' && value !== undefined) { if (key.startsWith('on')) {
1793
- // Handle event attributes
1794
- if (framework === 'semantq') {
1795
- const eventValue = value.endsWith('()') ? value.slice(0, -2) : value;
1796
- additionalAttrs += ` @${key.replace(/^on/, '')}={${eventValue}}\n`;
1797
- } else {
1798
- // Add parentheses if not present
1799
- const eventValue = value.endsWith('()') ? value : `${value}()`;
1800
- additionalAttrs += ` ${key}="${eventValue}"\n`;
1801
- }
1764
+ if (!['id', 'class', 'dependsOn', 'dependents', 'value', 'binding'].includes(key) && value !== undefined) {
1765
+ if (key.startsWith('on')) {
1766
+ const eventValue = value.endsWith('()') ? value : `${value}()`;
1767
+ additionalAttrs += ` ${key}="${eventValue}"\n`;
1802
1768
  } else {
1803
- // Handle boolean attributes
1769
+ const attrName = key.replace(/_/g, '-');
1804
1770
  if (value === true) {
1805
- additionalAttrs += ` ${key.replace(/_/g, '-')}\n`;
1771
+ additionalAttrs += ` ${attrName}\n`;
1806
1772
  } else if (value !== false) {
1807
- // Convert underscores to hyphens and set the attribute
1808
- additionalAttrs += ` ${key.replace(/_/g, '-')}="${value}"\n`;
1773
+ additionalAttrs += ` ${attrName}="${value}"\n`;
1809
1774
  }
1810
1775
  }
1811
1776
  }
1812
1777
  }
1813
1778
 
1779
+ let inputClass = attributes.class || this.inputClass;
1814
1780
 
1781
+ // Build the raw HTML structure
1782
+ let formHTML = `
1783
+ <div class="${this.divClass}" id="${id + '-block'}">
1784
+ <label for="${id}">${label}
1785
+ ${validationAttrs.includes('required') && this.formSettings.requiredFieldIndicator ? this.formSettings.asteriskHtml : ''}
1786
+ </label>
1787
+ <textarea
1788
+ name="${name}"
1789
+ ${bindingDirective}
1790
+ id="${id}"
1791
+ class="${inputClass}"
1792
+ ${additionalAttrs}
1793
+ ${validationAttrs}
1794
+ ${(additionalAttrs.includes('placeholder') || attributes.placeholder) ? '' : (this.formSettings.placeholders ? `placeholder="${label}"` : '')}>${textareaValue}</textarea>
1795
+ </div>`.replace(/^\s*\n/gm, '').trim();
1796
+
1797
+ // Vertical layout formatting for attributes while preserving content
1798
+ let formattedHtml = formHTML.replace(/<textarea\s+([\s\S]*?)>([\s\S]*?)<\/textarea>/, (match, attrPart, content) => {
1799
+ // Split by whitespace only if it is NOT inside quotes (prevents stacking text/placeholders)
1800
+ const attrs = attrPart.trim()
1801
+ .split(/\s+(?=(?:[^"]*"[^"]*")*[^"]*$)/)
1802
+ .filter(a => a.trim() !== '')
1803
+ .map(attr => ` ${attr.trim()}`)
1804
+ .join('\n');
1805
+
1806
+ return `<textarea\n${attrs}\n>${content}</textarea>`;
1807
+ });
1815
1808
 
1816
- let inputClass;
1817
- if ('class' in attributes) {
1818
- inputClass = attributes.class;
1819
- } else {
1820
- inputClass = this.inputClass;
1821
- }
1822
-
1823
- // Construct the final HTML string for textarea
1824
- let formHTML = `
1825
- <div class="${this.divClass}" id="${id + '-block'}">
1826
- <label for="${id}">${label}
1827
- ${validationAttrs.includes('required') && this.formSettings.requiredFieldIndicator ? this.formSettings.asteriskHtml : ''}
1828
- </label>
1829
- <textarea
1830
- name="${name}"
1831
- ${bindingDirective}
1832
- id="${id}"
1833
- class="${inputClass}"
1834
- ${additionalAttrs}
1835
- ${validationAttrs}
1836
- ${additionalAttrs.includes('placeholder') ? '' : (this.formSettings.placeholders ? `placeholder="${label}"` : '')}>
1837
- </textarea>
1838
- </div>
1839
- `.replace(/^\s*\n/gm, '').trim();
1840
-
1841
- let formattedHtml = formHTML;
1842
-
1843
- // Apply vertical layout to the <textarea> element only
1844
- formattedHtml = formattedHtml.replace(/<textarea\s+([^>]*)>\s*<\/textarea>/, (match, p1) => {
1845
- // Reformat attributes into a vertical layout
1846
- const attributes = p1.trim().split(/\s+/).map(attr => ` ${attr}`).join('\n');
1847
- return `<textarea\n${attributes}\n></textarea>`;
1848
- });
1849
-
1850
- this.formMarkUp += formattedHtml;
1851
-
1809
+ this.formMarkUp += formattedHtml;
1852
1810
  }
1853
1811
 
1854
-
1855
1812
  // New method for rendering tel fields
1856
1813
  renderTelField(type, name, label, validate, attributes) {
1857
1814
 
@@ -3409,97 +3366,7 @@ renderImageField(type, name, label, validate, attributes) {
3409
3366
 
3410
3367
 
3411
3368
 
3412
- // Textarea field rendering
3413
- renderTextAreaField(type, name, label, validate, attributes) {
3414
- const textAreaValidationAttributes = [
3415
- 'required',
3416
- 'minlength',
3417
- 'maxlength'
3418
- ];
3419
-
3420
- // Construct validation attributes
3421
- let validationAttrs = '';
3422
- if (validate) {
3423
- Object.entries(validate).forEach(([key, value]) => {
3424
- if (textAreaValidationAttributes.includes(key)) {
3425
- if (typeof value === 'boolean' && value) {
3426
- validationAttrs += ` ${key}\n`;
3427
- } else {
3428
- validationAttrs += ` ${key}="${value}"\n`;
3429
- }
3430
- } else {
3431
- console.warn(`\x1b[31mUnsupported validation attribute '${key}' for field '${name}' of type '${type}'.\x1b[0m`);
3432
- }
3433
- });
3434
- }
3435
-
3436
- // Handle the binding syntax
3437
- let bindingDirective = '';
3438
- if (attributes.binding) {
3439
- if (attributes.binding === 'bind:value' && name) {
3440
- bindingDirective = `bind:value="${name}"\n`;
3441
- }
3442
- if (attributes.binding.startsWith('::') && name) {
3443
- bindingDirective = `bind:value="${name}"\n`;
3444
- }
3445
- if (attributes.binding && !name) {
3446
- console.log(`\x1b[31m%s\x1b[0m`, `You cannot set binding value when there is no name attribute defined in ${name} ${type} field.`);
3447
- return;
3448
- }
3449
- }
3450
-
3451
- // Get the id from attributes or fall back to name
3452
- let id = attributes.id || name;
3453
-
3454
- // Construct additional attributes dynamically
3455
- let additionalAttrs = '';
3456
- for (const [key, value] of Object.entries(attributes)) {
3457
- if (key !== 'id' && key !== 'class' && key !== 'dependsOn' && key !== 'dependents' && value !== undefined) {
3458
- if (key.startsWith('on')) {
3459
- const eventValue = value.endsWith('()') ? value : `${value}()`;
3460
- additionalAttrs += ` ${key}="${eventValue}"\n`;
3461
- } else {
3462
- if (value === true) {
3463
- additionalAttrs += ` ${key.replace(/_/g, '-')}\n`;
3464
- } else if (value !== false) {
3465
- additionalAttrs += ` ${key.replace(/_/g, '-')}="${value}"\n`;
3466
- }
3467
- }
3468
- }
3469
- }
3470
-
3471
- let inputClass = attributes.class || this.inputClass;
3472
-
3473
- // Construct the final HTML string
3474
- let formHTML = `
3475
- <div class="${this.divClass}" id="${id + '-block'}">
3476
- <label for="${id}">${label}
3477
- ${validationAttrs.includes('required') && this.formSettings.requiredFieldIndicator ? this.formSettings.asteriskHtml : ''}
3478
- </label>
3479
- <textarea
3480
- name="${name}"
3481
- ${bindingDirective}
3482
- id="${id}"
3483
- class="${inputClass}"
3484
- ${additionalAttrs}
3485
- ${validationAttrs}
3486
- ${additionalAttrs.includes('placeholder') ? '' : (this.formSettings.placeholders ? `placeholder="${label}"` : '')}>
3487
- </textarea>
3488
- </div>
3489
- `.replace(/^\s*\n/gm, '').trim();
3490
-
3491
- let formattedHtml = formHTML;
3492
-
3493
- // Apply vertical layout to the <textarea> element only
3494
- formattedHtml = formattedHtml.replace(/<textarea\s+([^>]*)>\s*<\/textarea>/, (match, p1) => {
3495
- const attributes = p1.trim().split(/\s+/).map(attr => ` ${attr}`).join('\n');
3496
- return `<textarea\n${attributes}\n></textarea>`;
3497
- });
3498
-
3499
- this.formMarkUp += formattedHtml;
3500
- }
3501
-
3502
-
3369
+ // Radio field rendering
3503
3370
 
3504
3371
  renderRadioField(type, name, label, validate, attributes, options) {
3505
3372
  // Define valid validation attributes for radio fields
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@formique/semantq",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "Formique is a native form builder for the Semantq JS Framework",
5
5
  "main": "formique-semantq.js",
6
6
  "type": "module",