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