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.
@@ -2845,6 +2845,10 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
2845
2845
  __nested_webpack_require_993__.r(__webpack_exports__);
2846
2846
  /* harmony export */
2847
2847
  __nested_webpack_require_993__.d(__webpack_exports__, {
2848
+ /* harmony export */"fixAndParseJSON": function fixAndParseJSON() {
2849
+ return (/* binding */_fixAndParseJSON
2850
+ );
2851
+ },
2848
2852
  /* harmony export */"isEmail": function isEmail() {
2849
2853
  return (/* binding */_isEmail
2850
2854
  );
@@ -2889,37 +2893,353 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
2889
2893
  }, _typeof(obj);
2890
2894
  }
2891
2895
  /**
2892
- * Check if a string is a valid number
2893
- * @param str - The string to check
2894
- * @returns boolean indicating if the string is a valid number
2896
+ * Fix And Parse JSON (Support for handling complex escape JSON strings)
2897
+ * @private
2895
2898
  */
2896
- function _isValidNumeric(str) {
2897
- if (typeof str !== "string") return false; // we only process strings!
2898
- if (!isNaN(Number(str)) &&
2899
- // use type coercion to parse the _entirety_ of the string
2900
- !isNaN(parseFloat(str)) // ensure strings of whitespace fail
2901
- ) {
2902
- return true;
2899
+ /*
2900
+ - Always try JSON.parse first;
2901
+ - If parsing fails, unescape \" → ";
2902
+ - Then process the outermost object or array key-by-key, value-by-value;
2903
+ - If a top-level value is an unquoted object or array (e.g. messages: [ {...} ]),
2904
+ recursively treat that value as a new root to repair;
2905
+ - For values wrapped in quotes ('...' or "..."), extract the inner text and
2906
+ re-encode it using JSON.stringify (ensures internal single/double quotes
2907
+ are not corrupted);
2908
+ - Set MAX_DEPTH to prevent infinite recursion.
2909
+ */
2910
+ // fixAndParseJSON - recursively repairs top-level key/value
2911
+ // (when encountering outermost values that are objects/arrays, it recurses)
2912
+
2913
+ /*
2914
+ DEMO:
2915
+
2916
+ // ✅ Valid JSON (contains svg and single-quote content)
2917
+ const okJson = `{
2918
+ "label":"<svg width='16' height='16'><path fill='currentColor' d='M19 13h-6'/></svg> New Session",
2919
+ "value":"new",
2920
+ "onClick":"method.setVal(''); method.clearData();"
2921
+ }`;
2922
+
2923
+ // ❌ Single-quote JSON
2924
+ const badJson = "{'model':'{model}','messages':[{'role':'user','content':'{message}'}],'stream': true}";
2925
+
2926
+ // ❌ Escaped JSON
2927
+ 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();\\\"}";
2928
+
2929
+ 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();\"}";
2930
+
2931
+ 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}]";
2932
+
2933
+
2934
+ console.log('okJson =>', fixAndParseJSON(okJson)); // parses correctly
2935
+ console.log('badJson =>', fixAndParseJSON(badJson)); // repaired and parsed
2936
+ console.log('badJson2 =>', fixAndParseJSON(badJson2)); // repaired and parsed
2937
+ console.log('badJson3 =>', fixAndParseJSON(badJson3)); // repaired and parsed
2938
+ console.log('badJson4 =>', fixAndParseJSON(badJson4)); // repaired and parsed
2939
+ */
2940
+ function _fixAndParseJSON(input) {
2941
+ var MAX_DEPTH = 6;
2942
+
2943
+ // 1. Fast attempt
2944
+ try {
2945
+ return {
2946
+ success: true,
2947
+ data: JSON.parse(input)
2948
+ };
2949
+ } catch (e) {
2950
+ // continue to repair
2903
2951
  }
2904
- return false;
2952
+
2953
+ // 2. Simple unescape of \" (common when copied from JS literals)
2954
+ var s = input;
2955
+ if (s.includes('\\"')) s = s.replace(/\\"/g, '"');
2956
+ s = s.trim();
2957
+ try {
2958
+ if (s.startsWith('{')) {
2959
+ s = processTopObject(s, 0, MAX_DEPTH);
2960
+ } else if (s.startsWith('[')) {
2961
+ s = processTopArray(s, 0, MAX_DEPTH);
2962
+ } else {
2963
+ throw new Error('Input is not an object or array');
2964
+ }
2965
+ return {
2966
+ success: true,
2967
+ data: JSON.parse(s)
2968
+ };
2969
+ } catch (err) {
2970
+ return {
2971
+ success: false,
2972
+ error: 'Invalid JSON format',
2973
+ details: err instanceof Error ? err.message : String(err)
2974
+ };
2975
+ }
2976
+ }
2977
+
2978
+ /* ---------- Helper (recursive) functions ---------- */
2979
+
2980
+ function processTopObject(str, depth, MAX_DEPTH) {
2981
+ if (depth > MAX_DEPTH) return str;
2982
+ str = str.trim();
2983
+ // Ensure it is wrapped in { ... }
2984
+ if (!(str.startsWith('{') && str.endsWith('}'))) {
2985
+ var f = str.indexOf('{');
2986
+ var l = str.lastIndexOf('}');
2987
+ if (f === -1 || l === -1 || l <= f) return str;
2988
+ str = str.slice(f, l + 1);
2989
+ }
2990
+ var inner = str.slice(1, -1);
2991
+ var pairs = splitTopLevel(inner);
2992
+ var repairedPairs = pairs.map(function (pair) {
2993
+ if (!pair || pair.trim() === '') return '';
2994
+ var idx = findTopLevelColon(pair);
2995
+ if (idx === -1) {
2996
+ return pair; // Non key:value fragment, keep as is (rare case)
2997
+ }
2998
+
2999
+ var rawKey = pair.slice(0, idx).trim();
3000
+ var rawVal = pair.slice(idx + 1);
3001
+ var keyContent = extractKeyContent(rawKey);
3002
+ var keyJson = JSON.stringify(keyContent);
3003
+ var repairedValue = repairPossiblyQuotedValue(rawVal, depth + 1, MAX_DEPTH);
3004
+ return keyJson + ':' + repairedValue;
3005
+ });
3006
+ return '{' + repairedPairs.join(',') + '}';
3007
+ }
3008
+ function processTopArray(str, depth, MAX_DEPTH) {
3009
+ if (depth > MAX_DEPTH) return str;
3010
+ str = str.trim();
3011
+ if (!(str.startsWith('[') && str.endsWith(']'))) {
3012
+ var f = str.indexOf('[');
3013
+ var l = str.lastIndexOf(']');
3014
+ if (f === -1 || l === -1 || l <= f) return str;
3015
+ str = str.slice(f, l + 1);
3016
+ }
3017
+ var inner = str.slice(1, -1);
3018
+ var elements = splitTopLevel(inner);
3019
+ var processed = elements.map(function (el) {
3020
+ var t = el.trim();
3021
+ if (t === '') return '';
3022
+ if (t.startsWith('{')) return processTopObject(t, depth + 1, MAX_DEPTH);
3023
+ if (t.startsWith('[')) return processTopArray(t, depth + 1, MAX_DEPTH);
3024
+ return repairPossiblyQuotedValue(t, depth + 1, MAX_DEPTH);
3025
+ });
3026
+ return '[' + processed.join(',') + ']';
3027
+ }
3028
+
3029
+ // If value is quoted, extract inside and JSON.stringify again (safe escaping)
3030
+ // If value is unquoted object/array literal, recurse treating it as new root
3031
+ // Otherwise return as is (numbers, booleans, null, or raw expressions)
3032
+ function repairPossiblyQuotedValue(rawVal, depth, MAX_DEPTH) {
3033
+ var v = rawVal.trim();
3034
+ if (v === '') return v;
3035
+ if (v[0] === '"' || v[0] === "'") {
3036
+ var quote = v[0];
3037
+ // Find the last unescaped matching quote
3038
+ var lastPos = -1;
3039
+ for (var i = v.length - 1; i >= 0; i--) {
3040
+ if (v[i] === quote) {
3041
+ // check if escaped
3042
+ var bs = 0;
3043
+ var k = i - 1;
3044
+ while (k >= 0 && v[k] === '\\') {
3045
+ bs++;
3046
+ k--;
3047
+ }
3048
+ if (bs % 2 === 0) {
3049
+ lastPos = i;
3050
+ break;
3051
+ }
3052
+ }
3053
+ }
3054
+ var inner = lastPos > 0 ? v.slice(1, lastPos) : v.slice(1);
3055
+ return JSON.stringify(inner); // Generate valid JSON string (auto escape)
3056
+ }
3057
+
3058
+ // If unquoted object/array literal -> recurse
3059
+ if (v.startsWith('{')) {
3060
+ return processTopObject(v, depth, MAX_DEPTH);
3061
+ }
3062
+ if (v.startsWith('[')) {
3063
+ return processTopArray(v, depth, MAX_DEPTH);
3064
+ }
3065
+
3066
+ // Other (number, boolean, null, raw expression): return as is
3067
+ return v;
3068
+ }
3069
+
3070
+ /* --------- Utils: split by top-level commas, find colon, extract key --------- */
3071
+
3072
+ // Split string by top-level commas (ignores commas inside strings/objects/arrays/parentheses)
3073
+ function splitTopLevel(str) {
3074
+ var parts = [];
3075
+ var buf = '';
3076
+ var depthCurly = 0;
3077
+ var depthSquare = 0;
3078
+ var depthParen = 0;
3079
+ var inSingle = false;
3080
+ var inDouble = false;
3081
+ var esc = false;
3082
+ for (var i = 0; i < str.length; i++) {
3083
+ var ch = str[i];
3084
+ if (esc) {
3085
+ buf += ch;
3086
+ esc = false;
3087
+ continue;
3088
+ }
3089
+ if (ch === '\\') {
3090
+ buf += ch;
3091
+ esc = true;
3092
+ continue;
3093
+ }
3094
+ if (ch === "'" && !inDouble) {
3095
+ inSingle = !inSingle;
3096
+ buf += ch;
3097
+ continue;
3098
+ }
3099
+ if (ch === '"' && !inSingle) {
3100
+ inDouble = !inDouble;
3101
+ buf += ch;
3102
+ continue;
3103
+ }
3104
+ if (!inSingle && !inDouble) {
3105
+ if (ch === '{') {
3106
+ depthCurly++;
3107
+ buf += ch;
3108
+ continue;
3109
+ }
3110
+ if (ch === '}') {
3111
+ depthCurly--;
3112
+ buf += ch;
3113
+ continue;
3114
+ }
3115
+ if (ch === '[') {
3116
+ depthSquare++;
3117
+ buf += ch;
3118
+ continue;
3119
+ }
3120
+ if (ch === ']') {
3121
+ depthSquare--;
3122
+ buf += ch;
3123
+ continue;
3124
+ }
3125
+ if (ch === '(') {
3126
+ depthParen++;
3127
+ buf += ch;
3128
+ continue;
3129
+ }
3130
+ if (ch === ')') {
3131
+ depthParen--;
3132
+ buf += ch;
3133
+ continue;
3134
+ }
3135
+ if (ch === ',' && depthCurly === 0 && depthSquare === 0 && depthParen === 0) {
3136
+ parts.push(buf);
3137
+ buf = '';
3138
+ continue;
3139
+ }
3140
+ }
3141
+ buf += ch;
3142
+ }
3143
+ if (buf.trim() !== '') parts.push(buf);
3144
+ return parts;
3145
+ }
3146
+
3147
+ // Find the first top-level colon (ignores strings and nested structures)
3148
+ function findTopLevelColon(str) {
3149
+ var inSingle = false;
3150
+ var inDouble = false;
3151
+ var esc = false;
3152
+ var depthCurly = 0;
3153
+ var depthSquare = 0;
3154
+ var depthParen = 0;
3155
+ for (var i = 0; i < str.length; i++) {
3156
+ var ch = str[i];
3157
+ if (esc) {
3158
+ esc = false;
3159
+ continue;
3160
+ }
3161
+ if (ch === '\\') {
3162
+ esc = true;
3163
+ continue;
3164
+ }
3165
+ if (ch === "'" && !inDouble) {
3166
+ inSingle = !inSingle;
3167
+ continue;
3168
+ }
3169
+ if (ch === '"' && !inSingle) {
3170
+ inDouble = !inDouble;
3171
+ continue;
3172
+ }
3173
+ if (!inSingle && !inDouble) {
3174
+ if (ch === '{') {
3175
+ depthCurly++;
3176
+ continue;
3177
+ }
3178
+ if (ch === '}') {
3179
+ depthCurly--;
3180
+ continue;
3181
+ }
3182
+ if (ch === '[') {
3183
+ depthSquare++;
3184
+ continue;
3185
+ }
3186
+ if (ch === ']') {
3187
+ depthSquare--;
3188
+ continue;
3189
+ }
3190
+ if (ch === '(') {
3191
+ depthParen++;
3192
+ continue;
3193
+ }
3194
+ if (ch === ')') {
3195
+ depthParen--;
3196
+ continue;
3197
+ }
3198
+ if (ch === ':' && depthCurly === 0 && depthSquare === 0 && depthParen === 0) {
3199
+ return i;
3200
+ }
3201
+ }
3202
+ }
3203
+ return -1;
3204
+ }
3205
+
3206
+ // Extract key content (supports "key", 'key', key) → returns pure string key
3207
+ function extractKeyContent(rawKey) {
3208
+ var r = rawKey.trim();
3209
+ if (r.startsWith('"') && r.endsWith('"') || r.startsWith("'") && r.endsWith("'")) {
3210
+ var inner = r.slice(1, -1).replace(/\\"/g, '"').replace(/\\'/g, "'");
3211
+ return inner;
3212
+ }
3213
+ return r;
2905
3214
  }
2906
3215
 
2907
3216
  /**
2908
3217
  * Determine whether it is in JSON format
2909
- * @param str - The value to check
2910
- * @returns boolean indicating if the value is valid JSON
3218
+ * @private
2911
3219
  */
2912
- function _isJSON(str) {
2913
- if (typeof str === 'string' && str.length > 0) {
2914
- if (str.replace(/\"\"/g, '').replace(/\,/g, '') === '[{}]') {
2915
- return false;
2916
- }
2917
- if (/^[\],:{}\s]*$/.test(str.replace(/\\["\\\/bfnrtu]/g, '@').replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']').replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
3220
+ function _isJSON(input) {
3221
+ if (typeof input === 'string' && input.length > 0) {
3222
+ return _fixAndParseJSON(input).success;
3223
+ } else {
3224
+ if (_typeof(input) === 'object' && Object.prototype.toString.call(input) === '[object Object]' && !input.length) {
2918
3225
  return true;
3226
+ } else {
3227
+ return false;
2919
3228
  }
2920
- return false;
2921
3229
  }
2922
- if (_typeof(str) === 'object' && Object.prototype.toString.call(str) === '[object Object]' && !str.length) {
3230
+ }
3231
+
3232
+ /**
3233
+ * Check if a string is a valid number
3234
+ * @param str - The string to check
3235
+ * @returns boolean indicating if the string is a valid number
3236
+ */
3237
+ function _isValidNumeric(str) {
3238
+ if (typeof str !== "string") return false; // we only process strings!
3239
+ if (!isNaN(Number(str)) &&
3240
+ // use type coercion to parse the _entirety_ of the string
3241
+ !isNaN(parseFloat(str)) // ensure strings of whitespace fail
3242
+ ) {
2923
3243
  return true;
2924
3244
  }
2925
3245
  return false;