lexgui 0.7.12 → 0.7.14

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,4 +1,4 @@
1
- // This is a generated file. Do not edit.
1
+ // This is a generated file. Do not edit.
2
2
  // Lexgui.js @jxarco
3
3
 
4
4
  /**
@@ -7,7 +7,7 @@
7
7
  */
8
8
 
9
9
  const LX = {
10
- version: "0.7.12",
10
+ version: "0.7.14",
11
11
  ready: false,
12
12
  extensions: [], // Store extensions used
13
13
  signals: {}, // Events and triggers
@@ -4570,8 +4570,8 @@ Element.prototype.ignore = function( eventName, callbackName ) {
4570
4570
  callbackName = callbackName ?? ( "_on" + eventName );
4571
4571
  const callback = this[ callbackName ];
4572
4572
  this.removeEventListener( eventName, callback );
4573
- };
4574
-
4573
+ };
4574
+
4575
4575
  // icons.js @jxarco
4576
4576
 
4577
4577
  const RAW_ICONS = {
@@ -4752,8 +4752,8 @@ LX.LucideIconAlias = {
4752
4752
  "RotateRight": "RotateCw",
4753
4753
  "RotateBack": "RotateCcw",
4754
4754
  "RotateLeft": "RotateCcw",
4755
- };
4756
-
4755
+ };
4756
+
4757
4757
  // utils.js @jxarco
4758
4758
 
4759
4759
  function clamp( num, min, max ) { return Math.min( Math.max( num, min ), max ); }
@@ -5322,11 +5322,12 @@ LX.guidGenerator = guidGenerator;
5322
5322
  function buildTextPattern( options = {} )
5323
5323
  {
5324
5324
  let patterns = [];
5325
- if ( options.lowercase ) patterns.push("(?=.*[a-z])");
5326
- if ( options.uppercase ) patterns.push("(?=.*[A-Z])");
5327
- if ( options.digit ) patterns.push("(?=.*\\d)");
5328
- if ( options.specialChar ) patterns.push("(?=.*[@#$%^&+=!])");
5329
- if ( options.noSpaces ) patterns.push("(?!.*\\s)");
5325
+ if( options.lowercase ) patterns.push("(?=.*[a-z])");
5326
+ if( options.uppercase ) patterns.push("(?=.*[A-Z])");
5327
+ if( options.digit ) patterns.push("(?=.*\\d)");
5328
+ if( options.specialChar ) patterns.push("(?=.*[@#$%^&+=!])");
5329
+ if( options.noSpaces ) patterns.push("(?!.*\\s)");
5330
+ if( options.email ) patterns.push("(^[^\s@]+@[^\s@]+\.[^\s@]+$)");
5330
5331
 
5331
5332
  let minLength = options.minLength || 0;
5332
5333
  let maxLength = options.maxLength || ""; // Empty means no max length restriction
@@ -5337,6 +5338,45 @@ function buildTextPattern( options = {} )
5337
5338
 
5338
5339
  LX.buildTextPattern = buildTextPattern;
5339
5340
 
5341
+ /**
5342
+ * Checks a value against a set of pattern requirements and returns an array
5343
+ * of specific error messages for all criteria that failed.
5344
+ * @param { String } value The string to validate.
5345
+ * @param { Object } pattern The pattern options
5346
+ * @returns { Array } An array of error messages for failed criteria.
5347
+ */
5348
+ function validateValueAtPattern( value, pattern = {}, ...args )
5349
+ {
5350
+ const errors = [];
5351
+ const minLength = pattern.minLength || 0;
5352
+ const maxLength = pattern.maxLength; // undefined means no max limit
5353
+
5354
+ // Length requirements
5355
+ if( value.length < minLength ) errors.push(`Must be at least ${ minLength } characters long.`);
5356
+ else if( maxLength !== undefined && value.length > maxLength ) errors.push(`Must be no more than ${ maxLength } characters long.`);
5357
+
5358
+ // Check for Lowercase, Uppercase, Digits
5359
+ if( pattern.lowercase && !/[a-z]/.test( value ) ) errors.push( "Must contain at least one lowercase letter (a-z)." );
5360
+ if( pattern.uppercase && !/[A-Z]/.test( value ) ) errors.push( "Must contain at least one uppercase letter (A-Z)." );
5361
+ if( pattern.digit && !/\d/.test( value ) ) errors.push( "Must contain at least one number (0-9)." );
5362
+
5363
+ // Check for No Spaces (The original regex was (?!.*\s), meaning 'not followed by any character and a space')
5364
+ if( pattern.noSpaces && /\s/.test(value)) errors.push("Must NOT contain any spaces.");
5365
+
5366
+ // Check for Special Character (using the same set as buildTextPattern)
5367
+ if( pattern.specialChar && !/[@#$%^&+=!]/.test( value ) ) errors.push("Must contain at least one special character (e.g., @, #, $, %, ^, &, +, =, !).");
5368
+
5369
+ // Check email formatting
5370
+ if( pattern.email && !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test( value ) ) errors.push("Must have a valid email format.");
5371
+
5372
+ // Check match to any other text word
5373
+ if( pattern.fieldMatchName && value !== ( args[ 0 ] ) ) errors.push(`Must match ${ pattern.fieldMatchName } field.`);
5374
+
5375
+ return errors;
5376
+ }
5377
+
5378
+ LX.validateValueAtPattern = validateValueAtPattern;
5379
+
5340
5380
  /**
5341
5381
  * @method makeDraggable
5342
5382
  * @description Allows an element to be dragged
@@ -6736,8 +6776,8 @@ function drawSpline( ctx, pts, t )
6736
6776
  ctx.restore();
6737
6777
  }
6738
6778
 
6739
- LX.drawSpline = drawSpline;
6740
-
6779
+ LX.drawSpline = drawSpline;
6780
+
6741
6781
  // area.js @jxarco
6742
6782
 
6743
6783
  class AreaOverlayButtons {
@@ -7887,8 +7927,8 @@ class Area {
7887
7927
  }
7888
7928
  }
7889
7929
  }
7890
- LX.Area = Area;
7891
-
7930
+ LX.Area = Area;
7931
+
7892
7932
  // base_component.js @jxarco
7893
7933
 
7894
7934
  /**
@@ -9055,7 +9095,14 @@ class TextInput extends BaseComponent
9055
9095
 
9056
9096
  this.onSetValue = ( newValue, skipCallback, event ) => {
9057
9097
 
9058
- if( !this.valid( newValue ) || ( this._lastValueTriggered == newValue ) )
9098
+ let skipTrigger = ( this._lastValueTriggered == newValue );
9099
+
9100
+ if( !options.ignoreValidation )
9101
+ {
9102
+ skipTrigger |= ( !this.valid( newValue ) );
9103
+ }
9104
+
9105
+ if( skipTrigger )
9059
9106
  {
9060
9107
  return;
9061
9108
  }
@@ -9075,11 +9122,11 @@ class TextInput extends BaseComponent
9075
9122
  container.style.width = options.inputWidth ?? `calc( 100% - ${ realNameWidth })`;
9076
9123
  };
9077
9124
 
9078
- this.valid = ( v ) => {
9125
+ this.valid = ( v, matchField ) => {
9079
9126
  v = v ?? this.value();
9080
- if( ( wValue.pattern ?? "" ) == "" ) return true;
9081
- const regexp = new RegExp( wValue.pattern );
9082
- return regexp.test( v );
9127
+ if( !options.pattern ) return true;
9128
+ const errs = LX.validateValueAtPattern( v, options.pattern, matchField );
9129
+ return ( errs.length == 0 );
9083
9130
  };
9084
9131
 
9085
9132
  let container = document.createElement( 'div' );
@@ -9108,7 +9155,7 @@ class TextInput extends BaseComponent
9108
9155
 
9109
9156
  if( options.pattern )
9110
9157
  {
9111
- wValue.setAttribute( "pattern", options.pattern );
9158
+ wValue.setAttribute( "pattern", LX.buildTextPattern( options.pattern ) );
9112
9159
  }
9113
9160
 
9114
9161
  const trigger = options.trigger ?? "default";
@@ -9778,13 +9825,14 @@ class Form extends BaseComponent
9778
9825
 
9779
9826
  if( entryData.constructor != Object )
9780
9827
  {
9781
- const oldValue = JSON.parse( JSON.stringify( entryData ) );
9828
+ const oldValue = LX.deepCopy( entryData );
9782
9829
  entryData = { value: oldValue };
9783
9830
  data[ entry ] = entryData;
9784
9831
  }
9785
9832
 
9786
- entryData.placeholder = entryData.placeholder ?? ( entryData.label ?? `Enter ${ entry }` );
9787
9833
  entryData.width = "100%";
9834
+ entryData.placeholder = entryData.placeholder ?? ( entryData.label ?? `Enter ${ entry }` );
9835
+ entryData.ignoreValidation = true;
9788
9836
 
9789
9837
  if( !( options.skipLabels ?? false ) )
9790
9838
  {
@@ -9800,14 +9848,14 @@ class Form extends BaseComponent
9800
9848
  container.formData[ entry ] = entryData.constructor == Object ? entryData.value : entryData;
9801
9849
  }
9802
9850
 
9803
- const buttonContainer = LX.makeContainer( ["100%", "auto"], "flex flex-row", "", container );
9851
+ const buttonContainer = LX.makeContainer( ["100%", "auto"], "flex flex-row mt-2", "", container );
9804
9852
 
9805
9853
  if( options.secondaryActionName || options.secondaryActionCallback )
9806
9854
  {
9807
9855
  const secondaryButton = new LX.Button( null, options.secondaryActionName ?? "Cancel", ( value, event ) => {
9808
- if( callback )
9856
+ if( options.secondaryActionCallback )
9809
9857
  {
9810
- callback( container.formData, event );
9858
+ options.secondaryActionCallback( container.formData, event );
9811
9859
  }
9812
9860
  }, { width: "100%", minWidth: "0", buttonClass: options.secondaryButtonClass ?? "primary" } );
9813
9861
 
@@ -9822,9 +9870,22 @@ class Form extends BaseComponent
9822
9870
  {
9823
9871
  let entryData = data[ entry ];
9824
9872
 
9825
- if( !entryData.textComponent.valid() )
9873
+ const pattern = entryData.pattern;
9874
+ const matchField = pattern?.fieldMatchName ? container.formData[ pattern.fieldMatchName ] : undefined;
9875
+
9876
+ if( !entryData.textComponent.valid( undefined, matchField ) )
9826
9877
  {
9827
- errors.push( { type: "input_not_valid", entry } );
9878
+ const err = { entry, type: "input_not_valid" };
9879
+ err.messages = [];
9880
+ if( pattern )
9881
+ {
9882
+ err.messages = LX.validateValueAtPattern(
9883
+ container.formData[ entry ],
9884
+ pattern,
9885
+ matchField
9886
+ );
9887
+ }
9888
+ errors.push( err );
9828
9889
  }
9829
9890
  }
9830
9891
 
@@ -13728,8 +13789,8 @@ class Rate extends BaseComponent
13728
13789
  }
13729
13790
  }
13730
13791
 
13731
- LX.Rate = Rate;
13732
-
13792
+ LX.Rate = Rate;
13793
+
13733
13794
  // panel.js @jxarco
13734
13795
 
13735
13796
  /**
@@ -14928,8 +14989,8 @@ class Panel {
14928
14989
  }
14929
14990
  }
14930
14991
 
14931
- LX.Panel = Panel;
14932
-
14992
+ LX.Panel = Panel;
14993
+
14933
14994
  // branch.js @jxarco
14934
14995
 
14935
14996
  /**
@@ -15153,8 +15214,8 @@ class Branch {
15153
15214
  }
15154
15215
  }
15155
15216
  }
15156
- LX.Branch = Branch;
15157
-
15217
+ LX.Branch = Branch;
15218
+
15158
15219
  // menubar.js @jxarco
15159
15220
 
15160
15221
  /**
@@ -15486,8 +15547,8 @@ class Menubar {
15486
15547
  }
15487
15548
  }
15488
15549
  }
15489
- LX.Menubar = Menubar;
15490
-
15550
+ LX.Menubar = Menubar;
15551
+
15491
15552
  // sidebar.js @jxarco
15492
15553
 
15493
15554
  /**
@@ -16211,8 +16272,8 @@ class Sidebar {
16211
16272
  }
16212
16273
  }
16213
16274
  }
16214
- LX.Sidebar = Sidebar;
16215
-
16275
+ LX.Sidebar = Sidebar;
16276
+
16216
16277
  // asset_view.js @jxarco
16217
16278
 
16218
16279
  class AssetViewEvent {
@@ -17164,8 +17225,8 @@ class AssetView {
17164
17225
  }
17165
17226
  }
17166
17227
 
17167
- LX.AssetView = AssetView;
17168
-
17228
+ LX.AssetView = AssetView;
17229
+
17169
17230
  // tour.js @jxarco
17170
17231
 
17171
17232
  class Tour {
@@ -17463,6 +17524,6 @@ class Tour {
17463
17524
  } );
17464
17525
  }
17465
17526
  }
17466
- LX.Tour = Tour;
17467
-
17468
- export { ADD_CUSTOM_COMPONENT, Area, AssetView, AssetViewEvent, BaseComponent, Branch, LX, Menubar, Panel, Sidebar, Tour };
17527
+ LX.Tour = Tour;
17528
+
17529
+ export { ADD_CUSTOM_COMPONENT, Area, AssetView, AssetViewEvent, BaseComponent, Branch, LX, Menubar, Panel, Sidebar, Tour };