pgo-ui 1.1.2 → 1.1.8

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pgo-ui",
3
- "version": "1.1.2",
3
+ "version": "1.1.8",
4
4
  "description": "A Vue 3 component library with PGO design system",
5
5
  "private": false,
6
6
  "type": "module",
@@ -42,7 +42,7 @@
42
42
  "build": "vite build",
43
43
  "preview": "vite preview",
44
44
  "postinstall": "node ./src/copy-assets.cjs",
45
- "release": "npm version patch --no-git-tag-version && npm run build && npm --//registry.npmjs.org/:_authToken=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 publish"
45
+ "release": "npm version patch --no-git-tag-version && npm run build && npm publish --access public"
46
46
  },
47
47
  "dependencies": {
48
48
  "@heroicons/vue": "^2.2.0",
@@ -342,25 +342,32 @@ const initializeFormData = () => {
342
342
 
343
343
  const initializeAllFunctions = () => {
344
344
  if (props.form.functions) {
345
- // Create context that the functions will have access to
346
- const functionContext = {
347
- formData,
348
- formVariables,
349
- snackbar,
350
- api,
351
- emit,
352
- props,
353
- console,
354
- variables: formVariables,
355
- setFieldValue,
356
- getFieldValue,
357
- this: {
358
- variables: formVariables
359
- }
360
- };
345
+ Object.entries(props.form.functions).forEach(([name, functionBody]) => {
346
+ try {
347
+ compiledFunctions.value[name] = (...args) => {
348
+ const context = createEvaluationContext()
349
+
350
+ // Add common function-specific arguments
351
+ if (args[0] !== undefined) context.response = args[0]
352
+ if (args[1] !== undefined) context.item = args[1]
353
+ if (args[2] !== undefined) context.event = args[2]
361
354
 
362
- // Use the global initializeFunctions helper
363
- compiledFunctions.value = initializeFunctions(props.form.functions, functionContext);
355
+ // Add all positional args as 'arg0', 'arg1', etc.
356
+ args.forEach((arg, index) => {
357
+ context[`arg${index}`] = arg
358
+ })
359
+
360
+ try {
361
+ return safeEval(functionBody, context)
362
+ } catch (error) {
363
+ console.warn(`Error executing function "${name}":`, error.message)
364
+ return null
365
+ }
366
+ }
367
+ } catch (error) {
368
+ console.warn(`Error compiling function "${name}":`, error.message)
369
+ }
370
+ })
364
371
  }
365
372
  };
366
373
 
@@ -368,303 +375,18 @@ const initializeFormData = () => {
368
375
  const executeFunction = (functionName, ...args) => {
369
376
  if (compiledFunctions.value[functionName]) {
370
377
  try {
371
- return compiledFunctions.value[functionName](...args);
378
+ return compiledFunctions.value[functionName](...args)
372
379
  } catch (error) {
373
- console.error(`Error executing function ${functionName}:`, error);
374
- snackbar?.show({
375
- message: `Function ${functionName} execution failed`,
376
- variant: 'error'
377
- });
380
+ console.warn(`Error executing function "${functionName}":`, error.message)
381
+ return null
378
382
  }
379
383
  } else {
380
- console.warn(`Function ${functionName} not found`);
381
- }
382
- };
383
-
384
- // Function to get fields by group name
385
- const getFieldsByGroup = (groupName) => {
386
- if (!props.form.fields || !Array.isArray(props.form.fields)) {
387
- return [];
388
- }
389
- return props.form.fields.filter(field => field && field.group === groupName);
390
- };
391
-
392
- const shouldShowGroup = (group) => {
393
- if (!group) return false
394
- if (!group.condition) return true
395
-
396
- try {
397
- let expression = group.condition.trim()
398
- const context = createEvaluationContext()
399
-
400
- const evaluateCondition = (expr) => {
401
- // Pattern 1: Simple variable check
402
- if (/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(expr)) {
403
- return !!context[expr]
404
- }
405
-
406
- // Pattern 2: Negation "!variableName"
407
- if (/^!/.test(expr)) {
408
- const variableName = expr.substring(1).trim()
409
- if (/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(variableName)) {
410
- return !context[variableName]
411
- }
412
- }
413
-
414
- // Pattern 3: Complex expressions
415
- const varDeclarations = Object.keys(context)
416
- .filter(key => /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(key))
417
- .map(key => {
418
- const value = context[key]
419
- if (typeof value === 'function') return ''
420
- if (value === null || value === undefined) return `var ${key} = null;`
421
- if (typeof value === 'object') {
422
- try {
423
- return `var ${key} = ${JSON.stringify(value)};`
424
- } catch {
425
- return `var ${key} = null;`
426
- }
427
- }
428
- if (typeof value === 'string') return `var ${key} = ${JSON.stringify(value)};`
429
- return `var ${key} = ${value};`
430
- })
431
- .filter(Boolean)
432
- .join('\n')
433
-
434
- const fn = new Function(varDeclarations + `\nreturn (${expr});`)
435
- return fn()
436
- }
437
-
438
- return !!evaluateCondition(expression)
439
- } catch (error) {
440
- console.warn(`Error evaluating group condition "${group.condition}":`, error.message)
441
- return true
442
- }
443
- }
444
-
445
- // Function to get ungrouped fields
446
- const getUngroupedFields = () => {
447
- if (!props.form.fields || !Array.isArray(props.form.fields)) {
448
- return [];
449
- }
450
- return props.form.fields.filter(field => field && !field.group);
451
- };
452
-
453
- // Function to check if field should be shown based on condition
454
- const shouldShowField = (field) => {
455
- if (!field) {
456
- return false;
457
- }
458
-
459
- if (field.hidden === true) {
460
- return false;
461
- }
462
-
463
- if (!field.condition) {
464
- return true;
465
- }
466
-
467
- try {
468
- let expression = field.condition.trim();
469
- const context = createEvaluationContext();
470
-
471
- const evaluateCondition = (expr) => {
472
- // Pattern 1: Simple field check
473
- if (/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(expr)) {
474
- return !!context[expr];
475
- }
476
-
477
- // Pattern 2: Negation
478
- if (/^!/.test(expr)) {
479
- const fieldName = expr.substring(1).trim();
480
- if (/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(fieldName)) {
481
- return !context[fieldName];
482
- }
483
- }
484
-
485
- // Pattern 3: Complex expression
486
- const varDeclarations = Object.keys(context)
487
- .filter(key => /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(key))
488
- .map(key => {
489
- const value = context[key];
490
- if (typeof value === 'function') return '';
491
- if (value === null || value === undefined) return `var ${key} = null;`;
492
- if (typeof value === 'object') {
493
- try {
494
- return `var ${key} = ${JSON.stringify(value)};`;
495
- } catch {
496
- return `var ${key} = null;`;
497
- }
498
- }
499
- if (typeof value === 'string') return `var ${key} = ${JSON.stringify(value)};`;
500
- if (typeof value === 'boolean') return `var ${key} = ${value};`;
501
- if (typeof value === 'number') return `var ${key} = ${value};`;
502
- return `var ${key} = ${JSON.stringify(value)};`;
503
- })
504
- .filter(Boolean)
505
- .join('\n');
506
-
507
- const fn = new Function(varDeclarations + `\nreturn (${expr});`);
508
- return fn();
509
- };
510
-
511
- return !!evaluateCondition(expression);
512
- } catch (error) {
513
- console.warn(`Error evaluating condition "${field.condition}":`, error.message);
514
- const simpleField = field.condition.trim().replace(/^!/, '');
515
- if (/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(simpleField)) {
516
- const context = createEvaluationContext();
517
- const value = context[simpleField];
518
- return field.condition.trim().startsWith('!') ? !value : !!value;
519
- }
520
- return true;
521
- }
522
- };
523
-
524
- const componentMap = computed(() => {
525
- const map = {}
526
- const usedTypes = new Set(props.form.fields.map(f => f.inputType?.toLowerCase()))
527
-
528
- if (usedTypes.has('search') || usedTypes.has('inputsearch')) {
529
- map['search'] = defineAsyncComponent(() => import('../SearchBox.vue'))
530
- map['searchbox'] = defineAsyncComponent(() => import('../SearchBox.vue'))
531
- }
532
-
533
- if (usedTypes.has('select')) {
534
- map['select'] = defineAsyncComponent(() => import('../inputs/Select.vue'))
535
- }
536
- if (usedTypes.has('textarea')) {
537
- map['textarea'] = defineAsyncComponent(() => import('../inputs/Textarea.vue'))
538
- }
539
-
540
- if (usedTypes.has('textfield') || usedTypes.has('text') || usedTypes.has('string')) {
541
- map['textfield'] = defineAsyncComponent(() => import('../inputs/TextField.vue'))
542
- map['text'] = defineAsyncComponent(() => import('../inputs/TextField.vue'))
543
- map['string'] = defineAsyncComponent(() => import('../inputs/TextField.vue'))
544
- }
545
-
546
- if (usedTypes.has('datepicker') || usedTypes.has('date')) {
547
- map['datepicker'] = defineAsyncComponent(() => import('../inputs/DatePicker.vue'))
548
- map['date'] = defineAsyncComponent(() => import('../inputs/DatePicker.vue'))
549
- }
550
-
551
- if (usedTypes.has('chipgroup')) {
552
- map['chipgroup'] = defineAsyncComponent(() => import('../buttons/ChipGroup.vue'))
553
- }
554
-
555
- if (usedTypes.has('checkbox')) {
556
- map['checkbox'] = defineAsyncComponent(() => import('../inputs/Checkbox.vue'))
557
- }
558
-
559
- if (usedTypes.has('radio')) {
560
- map['radio'] = defineAsyncComponent(() => import('../inputs/Radio.vue'))
561
- }
562
-
563
- if (usedTypes.has('numberfield') || usedTypes.has('number')) {
564
- map['numberfield'] = defineAsyncComponent(() => import('../inputs/NumberField.vue'))
565
- map['number'] = defineAsyncComponent(() => import('../inputs/NumberField.vue'))
566
- }
567
- if (usedTypes.has('file') || usedTypes.has('filefield')) {
568
- map['file'] = defineAsyncComponent(() => import('../inputs/FileUpload.vue'))
569
- map['filefield'] = defineAsyncComponent(() => import('../inputs/FileUpload.vue'))
570
- }
571
- if (usedTypes.has('label') || usedTypes.has('labelfield')) {
572
- map['label'] = defineAsyncComponent(() => import('../inputs/LabelField.vue'))
573
- map['labelfield'] = defineAsyncComponent(() => import('../inputs/LabelField.vue'))
574
- }
575
-
576
- return map
577
- })
578
-
579
- const getFieldComponent = (type) => {
580
- const normalizedType = type?.toLowerCase() || 'textfield'
581
- return componentMap.value[normalizedType] || componentMap.value['textfield']
582
- }
583
-
584
- // Helper function to evaluate JavaScript expressions with context
585
- const evaluateExpression = (expression, context) => {
586
- if (typeof expression !== 'string') {
587
- return expression; // Return as-is if not a string
588
- }
589
-
590
- // If it's a simple variable name, return the context value
591
- if (/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(expression)) {
592
- return context[expression];
593
- }
594
-
595
- try {
596
- // Build safe variable declarations instead of using function parameters
597
- const functionKeys = []
598
- const functionValues = []
599
- const varDeclarations = []
600
-
601
- Object.keys(context)
602
- .filter(key => /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(key))
603
- .forEach(key => {
604
- const value = context[key]
605
-
606
- if (typeof value === 'function') {
607
- // Pass functions as parameters
608
- functionKeys.push(key)
609
- functionValues.push(value)
610
- } else if (value === null || value === undefined) {
611
- varDeclarations.push(`var ${key} = null;`)
612
- } else if (typeof value === 'object') {
613
- try {
614
- varDeclarations.push(`var ${key} = ${JSON.stringify(value)};`)
615
- } catch {
616
- varDeclarations.push(`var ${key} = null;`)
617
- }
618
- } else if (typeof value === 'string') {
619
- varDeclarations.push(`var ${key} = ${JSON.stringify(value)};`)
620
- } else {
621
- varDeclarations.push(`var ${key} = ${value};`)
622
- }
623
- })
624
-
625
- const body = varDeclarations.join('\n') + `\nreturn (${expression});`
626
- const fn = new Function(...functionKeys, body)
627
- return fn(...functionValues)
628
- } catch (error) {
629
- console.warn('Error evaluating expression:', expression, error.message)
630
- return false
384
+ console.warn(`Function "${functionName}" not found in compiled functions`)
385
+ return null
631
386
  }
632
387
  };
633
388
 
634
- const safeEval = (expression, context) => {
635
- const functionKeys = []
636
- const functionValues = []
637
- const varDeclarations = []
638
-
639
- Object.keys(context)
640
- .filter(key => /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(key))
641
- .forEach(key => {
642
- const value = context[key]
643
-
644
- if (typeof value === 'function') {
645
- functionKeys.push(key)
646
- functionValues.push(value)
647
- } else if (value === null || value === undefined) {
648
- varDeclarations.push(`var ${key} = null;`)
649
- } else if (typeof value === 'object') {
650
- try {
651
- varDeclarations.push(`var ${key} = ${JSON.stringify(value)};`)
652
- } catch {
653
- varDeclarations.push(`var ${key} = null;`)
654
- }
655
- } else if (typeof value === 'string') {
656
- varDeclarations.push(`var ${key} = ${JSON.stringify(value)};`)
657
- } else {
658
- varDeclarations.push(`var ${key} = ${value};`)
659
- }
660
- })
661
-
662
- const body = varDeclarations.join('\n') + `\n${expression}`
663
- const fn = new Function(...functionKeys, body)
664
- return fn(...functionValues)
665
- }
666
-
667
- // Simplified getFieldProps function
389
+ // Simplified getFieldProps function - evaluate disabled expressions
668
390
  const getFieldProps = (field) => {
669
391
  if (!field) {
670
392
  return {};
@@ -683,128 +405,33 @@ const initializeFormData = () => {
683
405
  group,
684
406
  events,
685
407
  hidden,
686
- disabled,
687
- reaonly,
688
- value,
689
- default: defaultValue,
408
+ default: defaultValue,
690
409
  ...restProps
691
410
  } = field;
692
411
 
693
- // Skip hidden fields
694
- if (hidden) {
695
- return {};
696
- }
412
+ const cleanProps = { ...restProps }
697
413
 
698
- // Start with fieldKey
699
- const cleanProps = {
700
- fieldKey: key
701
- };
414
+ // Evaluate disabled if it's a string expression
415
+ if (typeof field.disabled === 'string') {
416
+ try {
417
+ cleanProps.disabled = !!safeEval(`return (${field.disabled});`, context)
418
+ } catch (error) {
419
+ console.warn(`Error evaluating disabled for field "${field.key}":`, error.message)
420
+ cleanProps.disabled = false
421
+ }
422
+ } else if (typeof field.disabled === 'boolean') {
423
+ cleanProps.disabled = field.disabled
424
+ }
702
425
 
703
426
  // Add relationId for file upload components
704
427
  if (field.inputType === 'file' || field.inputType === 'filefield') {
705
428
  cleanProps.relationId = relationId.value;
706
- // cleanProps.onuploadSuccess = fetchData();
707
- // cleanProps.onviewPdf = emit('view-pdf');
708
- // cleanProps.fileList = FormDataList.value?.[ field.dataKey ?? field.key ];
709
-
710
- // cleanProps.relationId = formId.value || props.editItemId;
711
429
  cleanProps['onUploadSuccess'] = () => handleUploadSuccess();
712
430
  cleanProps['onView-pdf'] = (pdfData) => emit('view-pdf', pdfData);
713
- cleanProps.fileList = FormDataList.value?.[ field.dataKey ?? field.key ];
714
- // cleanProps.fileList = fileList.value;
715
- }
716
-
717
- // Add all other props directly (assuming they're clean from backend)
718
- // Add all other props and evaluate expressions
719
- Object.entries(restProps).forEach(([propKey, value]) => {
720
- // Skip empty/null/undefined values
721
- if (value === '' || value === null || value === undefined) {
722
- return;
723
- }
724
-
725
- // Filter out any event-like properties that are strings
726
- if (propKey.startsWith('on') && typeof value === 'string') {
727
- console.warn(`Filtering out string event handler: ${propKey}`);
728
- return;
729
- }
730
-
731
- // Evaluate expressions for specific props
732
- if (typeof value === 'string' && (
733
- propKey === 'disabled' ||
734
- propKey === 'readonly' ||
735
- propKey === 'required' ||
736
- propKey === 'visible' ||
737
- propKey === 'hidden'
738
- )) {
739
- // Check if it looks like a JavaScript expression
740
- if (value.includes('===') || value.includes('!==') ||
741
- value.includes('==') || value.includes('!=') ||
742
- value.includes('&&') || value.includes('||') ||
743
- value.includes('?') || value.includes(':')) {
744
- cleanProps[propKey] = evaluateExpression(value, context);
745
- } else if (context.hasOwnProperty(value)) {
746
- // Simple variable reference
747
- cleanProps[propKey] = context[value];
748
- } else {
749
- cleanProps[propKey] = value;
750
- }
751
- } else {
752
- cleanProps[propKey] = value;
753
- }
754
- });
755
-
756
- if (disabled !== undefined) {
757
- if (typeof disabled === 'string') {
758
- cleanProps.disabled = evaluateExpression(disabled, context);
759
- } else {
760
- cleanProps.disabled = disabled;
761
- }
762
- }
763
-
764
- // Dynamically handle events configuration
765
- if (events && typeof events === 'object') {
766
- Object.keys(events).forEach(eventName => {
767
- const functionName = events[eventName];
768
-
769
- // Convert event name to Vue prop format (onEventName)
770
- let vueEventName;
771
-
772
- if (eventName.includes(':')) {
773
- vueEventName = 'on' + eventName
774
- .split(':')
775
- .map(part => part.charAt(0).toUpperCase() + part.slice(1))
776
- .join('');
777
- } else if (eventName.includes('-')) {
778
- vueEventName = 'on' + eventName
779
- .split('-')
780
- .map(part => part.charAt(0).toUpperCase() + part.slice(1))
781
- .join('');
782
- } else {
783
- vueEventName = 'on' + eventName.charAt(0).toUpperCase() + eventName.slice(1);
784
- }
785
-
786
- // Create the event handler
787
- cleanProps[vueEventName] = (data) => {
788
- executeFunction(functionName, data);
789
- };
790
- });
791
- }
792
-
793
- // Handle item-text, item-value, item-title transformations
794
- if (cleanProps.itemText) {
795
- cleanProps['item-text'] = cleanProps.itemText;
796
- delete cleanProps.itemText;
797
- }
798
- if (cleanProps.itemValue) {
799
- cleanProps['item-value'] = cleanProps.itemValue;
800
- delete cleanProps.itemValue;
801
- }
802
- if (cleanProps.itemTitle) {
803
- cleanProps['item-title'] = cleanProps.itemTitle;
804
- delete cleanProps.itemTitle;
431
+ cleanProps.fileList = FormDataList.value?.[field.dataKey ?? field.key];
805
432
  }
806
433
 
807
- return cleanProps;
434
+ return cleanProps
808
435
  };
809
436
 
810
437
  const parseRules = (rulesString) => {
@@ -1,4 +0,0 @@
1
- import { _ as f } from "./index-DADicZve.js";
2
- export {
3
- f as default
4
- };