funda-ui 4.7.585 → 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.
@@ -992,6 +992,10 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
992
992
  __nested_webpack_require_993__.r(__webpack_exports__);
993
993
  /* harmony export */
994
994
  __nested_webpack_require_993__.d(__webpack_exports__, {
995
+ /* harmony export */"fixAndParseJSON": function fixAndParseJSON() {
996
+ return (/* binding */_fixAndParseJSON
997
+ );
998
+ },
995
999
  /* harmony export */"isEmail": function isEmail() {
996
1000
  return (/* binding */_isEmail
997
1001
  );
@@ -1036,37 +1040,353 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
1036
1040
  }, _typeof(obj);
1037
1041
  }
1038
1042
  /**
1039
- * Check if a string is a valid number
1040
- * @param str - The string to check
1041
- * @returns boolean indicating if the string is a valid number
1043
+ * Fix And Parse JSON (Support for handling complex escape JSON strings)
1044
+ * @private
1042
1045
  */
1043
- function _isValidNumeric(str) {
1044
- if (typeof str !== "string") return false; // we only process strings!
1045
- if (!isNaN(Number(str)) &&
1046
- // use type coercion to parse the _entirety_ of the string
1047
- !isNaN(parseFloat(str)) // ensure strings of whitespace fail
1048
- ) {
1049
- return true;
1046
+ /*
1047
+ - Always try JSON.parse first;
1048
+ - If parsing fails, unescape \" → ";
1049
+ - Then process the outermost object or array key-by-key, value-by-value;
1050
+ - If a top-level value is an unquoted object or array (e.g. messages: [ {...} ]),
1051
+ recursively treat that value as a new root to repair;
1052
+ - For values wrapped in quotes ('...' or "..."), extract the inner text and
1053
+ re-encode it using JSON.stringify (ensures internal single/double quotes
1054
+ are not corrupted);
1055
+ - Set MAX_DEPTH to prevent infinite recursion.
1056
+ */
1057
+ // fixAndParseJSON - recursively repairs top-level key/value
1058
+ // (when encountering outermost values that are objects/arrays, it recurses)
1059
+
1060
+ /*
1061
+ DEMO:
1062
+
1063
+ // ✅ Valid JSON (contains svg and single-quote content)
1064
+ const okJson = `{
1065
+ "label":"<svg width='16' height='16'><path fill='currentColor' d='M19 13h-6'/></svg> New Session",
1066
+ "value":"new",
1067
+ "onClick":"method.setVal(''); method.clearData();"
1068
+ }`;
1069
+
1070
+ // ❌ Single-quote JSON
1071
+ const badJson = "{'model':'{model}','messages':[{'role':'user','content':'{message}'}],'stream': true}";
1072
+
1073
+ // ❌ Escaped JSON
1074
+ 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();\\\"}";
1075
+
1076
+ 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();\"}";
1077
+
1078
+ 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}]";
1079
+
1080
+
1081
+ console.log('okJson =>', fixAndParseJSON(okJson)); // parses correctly
1082
+ console.log('badJson =>', fixAndParseJSON(badJson)); // repaired and parsed
1083
+ console.log('badJson2 =>', fixAndParseJSON(badJson2)); // repaired and parsed
1084
+ console.log('badJson3 =>', fixAndParseJSON(badJson3)); // repaired and parsed
1085
+ console.log('badJson4 =>', fixAndParseJSON(badJson4)); // repaired and parsed
1086
+ */
1087
+ function _fixAndParseJSON(input) {
1088
+ var MAX_DEPTH = 6;
1089
+
1090
+ // 1. Fast attempt
1091
+ try {
1092
+ return {
1093
+ success: true,
1094
+ data: JSON.parse(input)
1095
+ };
1096
+ } catch (e) {
1097
+ // continue to repair
1098
+ }
1099
+
1100
+ // 2. Simple unescape of \" (common when copied from JS literals)
1101
+ var s = input;
1102
+ if (s.includes('\\"')) s = s.replace(/\\"/g, '"');
1103
+ s = s.trim();
1104
+ try {
1105
+ if (s.startsWith('{')) {
1106
+ s = processTopObject(s, 0, MAX_DEPTH);
1107
+ } else if (s.startsWith('[')) {
1108
+ s = processTopArray(s, 0, MAX_DEPTH);
1109
+ } else {
1110
+ throw new Error('Input is not an object or array');
1111
+ }
1112
+ return {
1113
+ success: true,
1114
+ data: JSON.parse(s)
1115
+ };
1116
+ } catch (err) {
1117
+ return {
1118
+ success: false,
1119
+ error: 'Invalid JSON format',
1120
+ details: err instanceof Error ? err.message : String(err)
1121
+ };
1050
1122
  }
1051
- return false;
1123
+ }
1124
+
1125
+ /* ---------- Helper (recursive) functions ---------- */
1126
+
1127
+ function processTopObject(str, depth, MAX_DEPTH) {
1128
+ if (depth > MAX_DEPTH) return str;
1129
+ str = str.trim();
1130
+ // Ensure it is wrapped in { ... }
1131
+ if (!(str.startsWith('{') && str.endsWith('}'))) {
1132
+ var f = str.indexOf('{');
1133
+ var l = str.lastIndexOf('}');
1134
+ if (f === -1 || l === -1 || l <= f) return str;
1135
+ str = str.slice(f, l + 1);
1136
+ }
1137
+ var inner = str.slice(1, -1);
1138
+ var pairs = splitTopLevel(inner);
1139
+ var repairedPairs = pairs.map(function (pair) {
1140
+ if (!pair || pair.trim() === '') return '';
1141
+ var idx = findTopLevelColon(pair);
1142
+ if (idx === -1) {
1143
+ return pair; // Non key:value fragment, keep as is (rare case)
1144
+ }
1145
+
1146
+ var rawKey = pair.slice(0, idx).trim();
1147
+ var rawVal = pair.slice(idx + 1);
1148
+ var keyContent = extractKeyContent(rawKey);
1149
+ var keyJson = JSON.stringify(keyContent);
1150
+ var repairedValue = repairPossiblyQuotedValue(rawVal, depth + 1, MAX_DEPTH);
1151
+ return keyJson + ':' + repairedValue;
1152
+ });
1153
+ return '{' + repairedPairs.join(',') + '}';
1154
+ }
1155
+ function processTopArray(str, depth, MAX_DEPTH) {
1156
+ if (depth > MAX_DEPTH) return str;
1157
+ str = str.trim();
1158
+ if (!(str.startsWith('[') && str.endsWith(']'))) {
1159
+ var f = str.indexOf('[');
1160
+ var l = str.lastIndexOf(']');
1161
+ if (f === -1 || l === -1 || l <= f) return str;
1162
+ str = str.slice(f, l + 1);
1163
+ }
1164
+ var inner = str.slice(1, -1);
1165
+ var elements = splitTopLevel(inner);
1166
+ var processed = elements.map(function (el) {
1167
+ var t = el.trim();
1168
+ if (t === '') return '';
1169
+ if (t.startsWith('{')) return processTopObject(t, depth + 1, MAX_DEPTH);
1170
+ if (t.startsWith('[')) return processTopArray(t, depth + 1, MAX_DEPTH);
1171
+ return repairPossiblyQuotedValue(t, depth + 1, MAX_DEPTH);
1172
+ });
1173
+ return '[' + processed.join(',') + ']';
1174
+ }
1175
+
1176
+ // If value is quoted, extract inside and JSON.stringify again (safe escaping)
1177
+ // If value is unquoted object/array literal, recurse treating it as new root
1178
+ // Otherwise return as is (numbers, booleans, null, or raw expressions)
1179
+ function repairPossiblyQuotedValue(rawVal, depth, MAX_DEPTH) {
1180
+ var v = rawVal.trim();
1181
+ if (v === '') return v;
1182
+ if (v[0] === '"' || v[0] === "'") {
1183
+ var quote = v[0];
1184
+ // Find the last unescaped matching quote
1185
+ var lastPos = -1;
1186
+ for (var i = v.length - 1; i >= 0; i--) {
1187
+ if (v[i] === quote) {
1188
+ // check if escaped
1189
+ var bs = 0;
1190
+ var k = i - 1;
1191
+ while (k >= 0 && v[k] === '\\') {
1192
+ bs++;
1193
+ k--;
1194
+ }
1195
+ if (bs % 2 === 0) {
1196
+ lastPos = i;
1197
+ break;
1198
+ }
1199
+ }
1200
+ }
1201
+ var inner = lastPos > 0 ? v.slice(1, lastPos) : v.slice(1);
1202
+ return JSON.stringify(inner); // Generate valid JSON string (auto escape)
1203
+ }
1204
+
1205
+ // If unquoted object/array literal -> recurse
1206
+ if (v.startsWith('{')) {
1207
+ return processTopObject(v, depth, MAX_DEPTH);
1208
+ }
1209
+ if (v.startsWith('[')) {
1210
+ return processTopArray(v, depth, MAX_DEPTH);
1211
+ }
1212
+
1213
+ // Other (number, boolean, null, raw expression): return as is
1214
+ return v;
1215
+ }
1216
+
1217
+ /* --------- Utils: split by top-level commas, find colon, extract key --------- */
1218
+
1219
+ // Split string by top-level commas (ignores commas inside strings/objects/arrays/parentheses)
1220
+ function splitTopLevel(str) {
1221
+ var parts = [];
1222
+ var buf = '';
1223
+ var depthCurly = 0;
1224
+ var depthSquare = 0;
1225
+ var depthParen = 0;
1226
+ var inSingle = false;
1227
+ var inDouble = false;
1228
+ var esc = false;
1229
+ for (var i = 0; i < str.length; i++) {
1230
+ var ch = str[i];
1231
+ if (esc) {
1232
+ buf += ch;
1233
+ esc = false;
1234
+ continue;
1235
+ }
1236
+ if (ch === '\\') {
1237
+ buf += ch;
1238
+ esc = true;
1239
+ continue;
1240
+ }
1241
+ if (ch === "'" && !inDouble) {
1242
+ inSingle = !inSingle;
1243
+ buf += ch;
1244
+ continue;
1245
+ }
1246
+ if (ch === '"' && !inSingle) {
1247
+ inDouble = !inDouble;
1248
+ buf += ch;
1249
+ continue;
1250
+ }
1251
+ if (!inSingle && !inDouble) {
1252
+ if (ch === '{') {
1253
+ depthCurly++;
1254
+ buf += ch;
1255
+ continue;
1256
+ }
1257
+ if (ch === '}') {
1258
+ depthCurly--;
1259
+ buf += ch;
1260
+ continue;
1261
+ }
1262
+ if (ch === '[') {
1263
+ depthSquare++;
1264
+ buf += ch;
1265
+ continue;
1266
+ }
1267
+ if (ch === ']') {
1268
+ depthSquare--;
1269
+ buf += ch;
1270
+ continue;
1271
+ }
1272
+ if (ch === '(') {
1273
+ depthParen++;
1274
+ buf += ch;
1275
+ continue;
1276
+ }
1277
+ if (ch === ')') {
1278
+ depthParen--;
1279
+ buf += ch;
1280
+ continue;
1281
+ }
1282
+ if (ch === ',' && depthCurly === 0 && depthSquare === 0 && depthParen === 0) {
1283
+ parts.push(buf);
1284
+ buf = '';
1285
+ continue;
1286
+ }
1287
+ }
1288
+ buf += ch;
1289
+ }
1290
+ if (buf.trim() !== '') parts.push(buf);
1291
+ return parts;
1292
+ }
1293
+
1294
+ // Find the first top-level colon (ignores strings and nested structures)
1295
+ function findTopLevelColon(str) {
1296
+ var inSingle = false;
1297
+ var inDouble = false;
1298
+ var esc = false;
1299
+ var depthCurly = 0;
1300
+ var depthSquare = 0;
1301
+ var depthParen = 0;
1302
+ for (var i = 0; i < str.length; i++) {
1303
+ var ch = str[i];
1304
+ if (esc) {
1305
+ esc = false;
1306
+ continue;
1307
+ }
1308
+ if (ch === '\\') {
1309
+ esc = true;
1310
+ continue;
1311
+ }
1312
+ if (ch === "'" && !inDouble) {
1313
+ inSingle = !inSingle;
1314
+ continue;
1315
+ }
1316
+ if (ch === '"' && !inSingle) {
1317
+ inDouble = !inDouble;
1318
+ continue;
1319
+ }
1320
+ if (!inSingle && !inDouble) {
1321
+ if (ch === '{') {
1322
+ depthCurly++;
1323
+ continue;
1324
+ }
1325
+ if (ch === '}') {
1326
+ depthCurly--;
1327
+ continue;
1328
+ }
1329
+ if (ch === '[') {
1330
+ depthSquare++;
1331
+ continue;
1332
+ }
1333
+ if (ch === ']') {
1334
+ depthSquare--;
1335
+ continue;
1336
+ }
1337
+ if (ch === '(') {
1338
+ depthParen++;
1339
+ continue;
1340
+ }
1341
+ if (ch === ')') {
1342
+ depthParen--;
1343
+ continue;
1344
+ }
1345
+ if (ch === ':' && depthCurly === 0 && depthSquare === 0 && depthParen === 0) {
1346
+ return i;
1347
+ }
1348
+ }
1349
+ }
1350
+ return -1;
1351
+ }
1352
+
1353
+ // Extract key content (supports "key", 'key', key) → returns pure string key
1354
+ function extractKeyContent(rawKey) {
1355
+ var r = rawKey.trim();
1356
+ if (r.startsWith('"') && r.endsWith('"') || r.startsWith("'") && r.endsWith("'")) {
1357
+ var inner = r.slice(1, -1).replace(/\\"/g, '"').replace(/\\'/g, "'");
1358
+ return inner;
1359
+ }
1360
+ return r;
1052
1361
  }
1053
1362
 
1054
1363
  /**
1055
1364
  * Determine whether it is in JSON format
1056
- * @param str - The value to check
1057
- * @returns boolean indicating if the value is valid JSON
1365
+ * @private
1058
1366
  */
1059
- function _isJSON(str) {
1060
- if (typeof str === 'string' && str.length > 0) {
1061
- if (str.replace(/\"\"/g, '').replace(/\,/g, '') === '[{}]') {
1062
- return false;
1063
- }
1064
- if (/^[\],:{}\s]*$/.test(str.replace(/\\["\\\/bfnrtu]/g, '@').replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']').replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
1367
+ function _isJSON(input) {
1368
+ if (typeof input === 'string' && input.length > 0) {
1369
+ return _fixAndParseJSON(input).success;
1370
+ } else {
1371
+ if (_typeof(input) === 'object' && Object.prototype.toString.call(input) === '[object Object]' && !input.length) {
1065
1372
  return true;
1373
+ } else {
1374
+ return false;
1066
1375
  }
1067
- return false;
1068
1376
  }
1069
- if (_typeof(str) === 'object' && Object.prototype.toString.call(str) === '[object Object]' && !str.length) {
1377
+ }
1378
+
1379
+ /**
1380
+ * Check if a string is a valid number
1381
+ * @param str - The string to check
1382
+ * @returns boolean indicating if the string is a valid number
1383
+ */
1384
+ function _isValidNumeric(str) {
1385
+ if (typeof str !== "string") return false; // we only process strings!
1386
+ if (!isNaN(Number(str)) &&
1387
+ // use type coercion to parse the _entirety_ of the string
1388
+ !isNaN(parseFloat(str)) // ensure strings of whitespace fail
1389
+ ) {
1070
1390
  return true;
1071
1391
  }
1072
1392
  return false;