funda-ui 4.7.599 → 4.7.601

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.
@@ -2522,6 +2522,10 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
2522
2522
  __nested_webpack_require_993__.r(__webpack_exports__);
2523
2523
  /* harmony export */
2524
2524
  __nested_webpack_require_993__.d(__webpack_exports__, {
2525
+ /* harmony export */"fixAndParseJSON": function fixAndParseJSON() {
2526
+ return (/* binding */_fixAndParseJSON
2527
+ );
2528
+ },
2525
2529
  /* harmony export */"isEmail": function isEmail() {
2526
2530
  return (/* binding */_isEmail
2527
2531
  );
@@ -2566,37 +2570,353 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
2566
2570
  }, _typeof(obj);
2567
2571
  }
2568
2572
  /**
2569
- * Check if a string is a valid number
2570
- * @param str - The string to check
2571
- * @returns boolean indicating if the string is a valid number
2573
+ * Fix And Parse JSON (Support for handling complex escape JSON strings)
2574
+ * @private
2572
2575
  */
2573
- function _isValidNumeric(str) {
2574
- if (typeof str !== "string") return false; // we only process strings!
2575
- if (!isNaN(Number(str)) &&
2576
- // use type coercion to parse the _entirety_ of the string
2577
- !isNaN(parseFloat(str)) // ensure strings of whitespace fail
2578
- ) {
2579
- return true;
2576
+ /*
2577
+ - Always try JSON.parse first;
2578
+ - If parsing fails, unescape \" → ";
2579
+ - Then process the outermost object or array key-by-key, value-by-value;
2580
+ - If a top-level value is an unquoted object or array (e.g. messages: [ {...} ]),
2581
+ recursively treat that value as a new root to repair;
2582
+ - For values wrapped in quotes ('...' or "..."), extract the inner text and
2583
+ re-encode it using JSON.stringify (ensures internal single/double quotes
2584
+ are not corrupted);
2585
+ - Set MAX_DEPTH to prevent infinite recursion.
2586
+ */
2587
+ // fixAndParseJSON - recursively repairs top-level key/value
2588
+ // (when encountering outermost values that are objects/arrays, it recurses)
2589
+
2590
+ /*
2591
+ DEMO:
2592
+
2593
+ // ✅ Valid JSON (contains svg and single-quote content)
2594
+ const okJson = `{
2595
+ "label":"<svg width='16' height='16'><path fill='currentColor' d='M19 13h-6'/></svg> New Session",
2596
+ "value":"new",
2597
+ "onClick":"method.setVal(''); method.clearData();"
2598
+ }`;
2599
+
2600
+ // ❌ Single-quote JSON
2601
+ const badJson = "{'model':'{model}','messages':[{'role':'user','content':'{message}'}],'stream': true}";
2602
+
2603
+ // ❌ Escaped JSON
2604
+ const badJson2 = "{\\\"label\\\":\\\"<svg width='16' height='16' viewBox='0 0 24 24'><path fill='currentColor' d='M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z'/></svg> New Session\\\",\\\"value\\\":\\\"new\\\",\\\"onClick\\\":\\\"method.setVal(''); method.clearData();\\\"}";
2605
+
2606
+ const badJson3 = "{\"label\":\"<svg width='16' height='16' viewBox='0 0 24 24'><path fill='currentColor' d='M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z'/></svg> New Session\",\"value\":\"new\",\"onClick\":\"method.setVal(''); method.clearData();\"}";
2607
+
2608
+ const badJson4 = "[{\"label\":\"<svg fill='currentColor' width='12' height='12' viewBox='0 0 24 24'><path d='M20.5 9a3.49 3.49 0 0 0-3.45 3h-1.1a2.49 2.49 0 0 0-4.396-1.052L8.878 9.731l3.143-4.225a2.458 2.458 0 0 0 2.98-.019L17.339 8H16v1h3V6h-1v1.243l-2.336-2.512A2.473 2.473 0 0 0 16 3.5a2.5 2.5 0 0 0-5 0 2.474 2.474 0 0 0 .343 1.243L7.947 9.308 4.955 7.947a2.404 2.404 0 0 0-.161-1.438l3.704-1.385-.44 1.371.942.333L10 4 7.172 3l-.334.943 1.01.357-3.659 1.368a2.498 2.498 0 1 0-.682 4.117l2.085 2.688-2.053 2.76a2.5 2.5 0 1 0 .87 3.864l3.484 1.587-1.055.373.334.943L10 21l-1-2.828-.943.333.435 1.354-3.608-1.645A2.471 2.471 0 0 0 5 17.5a2.5 2.5 0 0 0-.058-.527l3.053-1.405 3.476 4.48a2.498 2.498 0 1 0 4.113.075L18 17.707V19h1v-3h-3v1h1.293l-2.416 2.416a2.466 2.466 0 0 0-2.667-.047l-3.283-4.23 2.554-1.176A2.494 2.494 0 0 0 15.95 13h1.1a3.493 3.493 0 1 0 3.45-4zm-7-7A1.5 1.5 0 1 1 12 3.5 1.502 1.502 0 0 1 13.5 2zm0 18a1.5 1.5 0 1 1-1.5 1.5 1.502 1.502 0 0 1 1.5-1.5zM1 7.5a1.5 1.5 0 1 1 2.457 1.145l-.144.112A1.496 1.496 0 0 1 1 7.5zm3.32 1.703a2.507 2.507 0 0 0 .264-.326l2.752 1.251-1.124 1.512zM2.5 19A1.5 1.5 0 1 1 4 17.5 1.502 1.502 0 0 1 2.5 19zm2.037-2.941a2.518 2.518 0 0 0-.193-.234l1.885-2.532 1.136 1.464zm3.76-1.731L6.849 12.46l1.42-1.908L11.1 11.84a2.29 2.29 0 0 0-.033 1.213zM13.5 14a1.5 1.5 0 1 1 1.5-1.5 1.502 1.502 0 0 1-1.5 1.5zm7 1a2.5 2.5 0 1 1 2.5-2.5 2.502 2.502 0 0 1-2.5 2.5zm1.5-2.5a1.5 1.5 0 1 1-1.5-1.5 1.502 1.502 0 0 1 1.5 1.5z'/><path fill='none' d='M0 0h24v24H0z'/></svg> Deep Thought","value":"brief","onClick":"if(isActive){method.executeCustomMethod('changeModel', true)}else{method.executeCustomMethod('changeModel', false)}"},{"label":"<svg fill='currentColor' width='12' height='12' viewBox='0 0 24 24'><path d='M19 2H5c-1.103 0-2 .897-2 2v12c0 1.103.897 2 2 2h3.586L12 21.414 15.414 18H19c1.103 0 2-.897 2-2V4c0-1.103-.897-2-2-2zm0 14h-4.414L12 18.586 9.414 16H5V4h14v12z'/></svg> Concise Answer","value":"brief","onClick":"if(isActive){method.setContextData({systemPrompt:'Please answer concisely, around 150 words, keep reasoning brief',mergedText:method.getContextData().mergedText,analyzeMetrics:method.getContextData().analyzeMetrics});}else{method.setContextData({mergedText:method.getContextData().mergedText,analyzeMetrics:method.getContextData().analyzeMetrics});}"},{"label":"<svg fill='none' width='12' height='12' viewBox='0 0 16 16'><path d='M7 0.0618896V9H15.9381C15.446 12.9463 12.0796 16 8 16C3.58172 16 0 12.4183 0 8C0 3.92038 3.05369 0.553988 7 0.0618896Z' fill='currentColor'/><path d='M9 0.0618897V7H15.9381C15.4869 3.38128 12.6187 0.513137 9 0.0618897Z' fill='currentColor'/></svg> Metrics Analysis","value":"lab","onClick":"return method.executeCustomMethod('getLibList')","isSelect":true,"dynamicOptions":true}]";
2609
+
2610
+
2611
+ console.log('okJson =>', fixAndParseJSON(okJson)); // parses correctly
2612
+ console.log('badJson =>', fixAndParseJSON(badJson)); // repaired and parsed
2613
+ console.log('badJson2 =>', fixAndParseJSON(badJson2)); // repaired and parsed
2614
+ console.log('badJson3 =>', fixAndParseJSON(badJson3)); // repaired and parsed
2615
+ console.log('badJson4 =>', fixAndParseJSON(badJson4)); // repaired and parsed
2616
+ */
2617
+ function _fixAndParseJSON(input) {
2618
+ var MAX_DEPTH = 6;
2619
+
2620
+ // 1. Fast attempt
2621
+ try {
2622
+ return {
2623
+ success: true,
2624
+ data: JSON.parse(input)
2625
+ };
2626
+ } catch (e) {
2627
+ // continue to repair
2628
+ }
2629
+
2630
+ // 2. Simple unescape of \" (common when copied from JS literals)
2631
+ var s = input;
2632
+ if (s.includes('\\"')) s = s.replace(/\\"/g, '"');
2633
+ s = s.trim();
2634
+ try {
2635
+ if (s.startsWith('{')) {
2636
+ s = processTopObject(s, 0, MAX_DEPTH);
2637
+ } else if (s.startsWith('[')) {
2638
+ s = processTopArray(s, 0, MAX_DEPTH);
2639
+ } else {
2640
+ throw new Error('Input is not an object or array');
2641
+ }
2642
+ return {
2643
+ success: true,
2644
+ data: JSON.parse(s)
2645
+ };
2646
+ } catch (err) {
2647
+ return {
2648
+ success: false,
2649
+ error: 'Invalid JSON format',
2650
+ details: err instanceof Error ? err.message : String(err)
2651
+ };
2580
2652
  }
2581
- return false;
2653
+ }
2654
+
2655
+ /* ---------- Helper (recursive) functions ---------- */
2656
+
2657
+ function processTopObject(str, depth, MAX_DEPTH) {
2658
+ if (depth > MAX_DEPTH) return str;
2659
+ str = str.trim();
2660
+ // Ensure it is wrapped in { ... }
2661
+ if (!(str.startsWith('{') && str.endsWith('}'))) {
2662
+ var f = str.indexOf('{');
2663
+ var l = str.lastIndexOf('}');
2664
+ if (f === -1 || l === -1 || l <= f) return str;
2665
+ str = str.slice(f, l + 1);
2666
+ }
2667
+ var inner = str.slice(1, -1);
2668
+ var pairs = splitTopLevel(inner);
2669
+ var repairedPairs = pairs.map(function (pair) {
2670
+ if (!pair || pair.trim() === '') return '';
2671
+ var idx = findTopLevelColon(pair);
2672
+ if (idx === -1) {
2673
+ return pair; // Non key:value fragment, keep as is (rare case)
2674
+ }
2675
+
2676
+ var rawKey = pair.slice(0, idx).trim();
2677
+ var rawVal = pair.slice(idx + 1);
2678
+ var keyContent = extractKeyContent(rawKey);
2679
+ var keyJson = JSON.stringify(keyContent);
2680
+ var repairedValue = repairPossiblyQuotedValue(rawVal, depth + 1, MAX_DEPTH);
2681
+ return keyJson + ':' + repairedValue;
2682
+ });
2683
+ return '{' + repairedPairs.join(',') + '}';
2684
+ }
2685
+ function processTopArray(str, depth, MAX_DEPTH) {
2686
+ if (depth > MAX_DEPTH) return str;
2687
+ str = str.trim();
2688
+ if (!(str.startsWith('[') && str.endsWith(']'))) {
2689
+ var f = str.indexOf('[');
2690
+ var l = str.lastIndexOf(']');
2691
+ if (f === -1 || l === -1 || l <= f) return str;
2692
+ str = str.slice(f, l + 1);
2693
+ }
2694
+ var inner = str.slice(1, -1);
2695
+ var elements = splitTopLevel(inner);
2696
+ var processed = elements.map(function (el) {
2697
+ var t = el.trim();
2698
+ if (t === '') return '';
2699
+ if (t.startsWith('{')) return processTopObject(t, depth + 1, MAX_DEPTH);
2700
+ if (t.startsWith('[')) return processTopArray(t, depth + 1, MAX_DEPTH);
2701
+ return repairPossiblyQuotedValue(t, depth + 1, MAX_DEPTH);
2702
+ });
2703
+ return '[' + processed.join(',') + ']';
2704
+ }
2705
+
2706
+ // If value is quoted, extract inside and JSON.stringify again (safe escaping)
2707
+ // If value is unquoted object/array literal, recurse treating it as new root
2708
+ // Otherwise return as is (numbers, booleans, null, or raw expressions)
2709
+ function repairPossiblyQuotedValue(rawVal, depth, MAX_DEPTH) {
2710
+ var v = rawVal.trim();
2711
+ if (v === '') return v;
2712
+ if (v[0] === '"' || v[0] === "'") {
2713
+ var quote = v[0];
2714
+ // Find the last unescaped matching quote
2715
+ var lastPos = -1;
2716
+ for (var i = v.length - 1; i >= 0; i--) {
2717
+ if (v[i] === quote) {
2718
+ // check if escaped
2719
+ var bs = 0;
2720
+ var k = i - 1;
2721
+ while (k >= 0 && v[k] === '\\') {
2722
+ bs++;
2723
+ k--;
2724
+ }
2725
+ if (bs % 2 === 0) {
2726
+ lastPos = i;
2727
+ break;
2728
+ }
2729
+ }
2730
+ }
2731
+ var inner = lastPos > 0 ? v.slice(1, lastPos) : v.slice(1);
2732
+ return JSON.stringify(inner); // Generate valid JSON string (auto escape)
2733
+ }
2734
+
2735
+ // If unquoted object/array literal -> recurse
2736
+ if (v.startsWith('{')) {
2737
+ return processTopObject(v, depth, MAX_DEPTH);
2738
+ }
2739
+ if (v.startsWith('[')) {
2740
+ return processTopArray(v, depth, MAX_DEPTH);
2741
+ }
2742
+
2743
+ // Other (number, boolean, null, raw expression): return as is
2744
+ return v;
2745
+ }
2746
+
2747
+ /* --------- Utils: split by top-level commas, find colon, extract key --------- */
2748
+
2749
+ // Split string by top-level commas (ignores commas inside strings/objects/arrays/parentheses)
2750
+ function splitTopLevel(str) {
2751
+ var parts = [];
2752
+ var buf = '';
2753
+ var depthCurly = 0;
2754
+ var depthSquare = 0;
2755
+ var depthParen = 0;
2756
+ var inSingle = false;
2757
+ var inDouble = false;
2758
+ var esc = false;
2759
+ for (var i = 0; i < str.length; i++) {
2760
+ var ch = str[i];
2761
+ if (esc) {
2762
+ buf += ch;
2763
+ esc = false;
2764
+ continue;
2765
+ }
2766
+ if (ch === '\\') {
2767
+ buf += ch;
2768
+ esc = true;
2769
+ continue;
2770
+ }
2771
+ if (ch === "'" && !inDouble) {
2772
+ inSingle = !inSingle;
2773
+ buf += ch;
2774
+ continue;
2775
+ }
2776
+ if (ch === '"' && !inSingle) {
2777
+ inDouble = !inDouble;
2778
+ buf += ch;
2779
+ continue;
2780
+ }
2781
+ if (!inSingle && !inDouble) {
2782
+ if (ch === '{') {
2783
+ depthCurly++;
2784
+ buf += ch;
2785
+ continue;
2786
+ }
2787
+ if (ch === '}') {
2788
+ depthCurly--;
2789
+ buf += ch;
2790
+ continue;
2791
+ }
2792
+ if (ch === '[') {
2793
+ depthSquare++;
2794
+ buf += ch;
2795
+ continue;
2796
+ }
2797
+ if (ch === ']') {
2798
+ depthSquare--;
2799
+ buf += ch;
2800
+ continue;
2801
+ }
2802
+ if (ch === '(') {
2803
+ depthParen++;
2804
+ buf += ch;
2805
+ continue;
2806
+ }
2807
+ if (ch === ')') {
2808
+ depthParen--;
2809
+ buf += ch;
2810
+ continue;
2811
+ }
2812
+ if (ch === ',' && depthCurly === 0 && depthSquare === 0 && depthParen === 0) {
2813
+ parts.push(buf);
2814
+ buf = '';
2815
+ continue;
2816
+ }
2817
+ }
2818
+ buf += ch;
2819
+ }
2820
+ if (buf.trim() !== '') parts.push(buf);
2821
+ return parts;
2822
+ }
2823
+
2824
+ // Find the first top-level colon (ignores strings and nested structures)
2825
+ function findTopLevelColon(str) {
2826
+ var inSingle = false;
2827
+ var inDouble = false;
2828
+ var esc = false;
2829
+ var depthCurly = 0;
2830
+ var depthSquare = 0;
2831
+ var depthParen = 0;
2832
+ for (var i = 0; i < str.length; i++) {
2833
+ var ch = str[i];
2834
+ if (esc) {
2835
+ esc = false;
2836
+ continue;
2837
+ }
2838
+ if (ch === '\\') {
2839
+ esc = true;
2840
+ continue;
2841
+ }
2842
+ if (ch === "'" && !inDouble) {
2843
+ inSingle = !inSingle;
2844
+ continue;
2845
+ }
2846
+ if (ch === '"' && !inSingle) {
2847
+ inDouble = !inDouble;
2848
+ continue;
2849
+ }
2850
+ if (!inSingle && !inDouble) {
2851
+ if (ch === '{') {
2852
+ depthCurly++;
2853
+ continue;
2854
+ }
2855
+ if (ch === '}') {
2856
+ depthCurly--;
2857
+ continue;
2858
+ }
2859
+ if (ch === '[') {
2860
+ depthSquare++;
2861
+ continue;
2862
+ }
2863
+ if (ch === ']') {
2864
+ depthSquare--;
2865
+ continue;
2866
+ }
2867
+ if (ch === '(') {
2868
+ depthParen++;
2869
+ continue;
2870
+ }
2871
+ if (ch === ')') {
2872
+ depthParen--;
2873
+ continue;
2874
+ }
2875
+ if (ch === ':' && depthCurly === 0 && depthSquare === 0 && depthParen === 0) {
2876
+ return i;
2877
+ }
2878
+ }
2879
+ }
2880
+ return -1;
2881
+ }
2882
+
2883
+ // Extract key content (supports "key", 'key', key) → returns pure string key
2884
+ function extractKeyContent(rawKey) {
2885
+ var r = rawKey.trim();
2886
+ if (r.startsWith('"') && r.endsWith('"') || r.startsWith("'") && r.endsWith("'")) {
2887
+ var inner = r.slice(1, -1).replace(/\\"/g, '"').replace(/\\'/g, "'");
2888
+ return inner;
2889
+ }
2890
+ return r;
2582
2891
  }
2583
2892
 
2584
2893
  /**
2585
2894
  * Determine whether it is in JSON format
2586
- * @param str - The value to check
2587
- * @returns boolean indicating if the value is valid JSON
2895
+ * @private
2588
2896
  */
2589
- function _isJSON(str) {
2590
- if (typeof str === 'string' && str.length > 0) {
2591
- if (str.replace(/\"\"/g, '').replace(/\,/g, '') === '[{}]') {
2592
- return false;
2593
- }
2594
- if (/^[\],:{}\s]*$/.test(str.replace(/\\["\\\/bfnrtu]/g, '@').replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']').replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
2897
+ function _isJSON(input) {
2898
+ if (typeof input === 'string' && input.length > 0) {
2899
+ return _fixAndParseJSON(input).success;
2900
+ } else {
2901
+ if (_typeof(input) === 'object' && Object.prototype.toString.call(input) === '[object Object]' && !input.length) {
2595
2902
  return true;
2903
+ } else {
2904
+ return false;
2596
2905
  }
2597
- return false;
2598
2906
  }
2599
- if (_typeof(str) === 'object' && Object.prototype.toString.call(str) === '[object Object]' && !str.length) {
2907
+ }
2908
+
2909
+ /**
2910
+ * Check if a string is a valid number
2911
+ * @param str - The string to check
2912
+ * @returns boolean indicating if the string is a valid number
2913
+ */
2914
+ function _isValidNumeric(str) {
2915
+ if (typeof str !== "string") return false; // we only process strings!
2916
+ if (!isNaN(Number(str)) &&
2917
+ // use type coercion to parse the _entirety_ of the string
2918
+ !isNaN(parseFloat(str)) // ensure strings of whitespace fail
2919
+ ) {
2600
2920
  return true;
2601
2921
  }
2602
2922
  return false;