funda-ui 4.7.599 → 4.7.604

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.
@@ -3180,6 +3180,10 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
3180
3180
  __nested_webpack_require_993__.r(__webpack_exports__);
3181
3181
  /* harmony export */
3182
3182
  __nested_webpack_require_993__.d(__webpack_exports__, {
3183
+ /* harmony export */"fixAndParseJSON": function fixAndParseJSON() {
3184
+ return (/* binding */_fixAndParseJSON
3185
+ );
3186
+ },
3183
3187
  /* harmony export */"isEmail": function isEmail() {
3184
3188
  return (/* binding */_isEmail
3185
3189
  );
@@ -3224,37 +3228,353 @@ var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_
3224
3228
  }, _typeof(obj);
3225
3229
  }
3226
3230
  /**
3227
- * Check if a string is a valid number
3228
- * @param str - The string to check
3229
- * @returns boolean indicating if the string is a valid number
3231
+ * Fix And Parse JSON (Support for handling complex escape JSON strings)
3232
+ * @private
3230
3233
  */
3231
- function _isValidNumeric(str) {
3232
- if (typeof str !== "string") return false; // we only process strings!
3233
- if (!isNaN(Number(str)) &&
3234
- // use type coercion to parse the _entirety_ of the string
3235
- !isNaN(parseFloat(str)) // ensure strings of whitespace fail
3236
- ) {
3237
- return true;
3234
+ /*
3235
+ - Always try JSON.parse first;
3236
+ - If parsing fails, unescape \" → ";
3237
+ - Then process the outermost object or array key-by-key, value-by-value;
3238
+ - If a top-level value is an unquoted object or array (e.g. messages: [ {...} ]),
3239
+ recursively treat that value as a new root to repair;
3240
+ - For values wrapped in quotes ('...' or "..."), extract the inner text and
3241
+ re-encode it using JSON.stringify (ensures internal single/double quotes
3242
+ are not corrupted);
3243
+ - Set MAX_DEPTH to prevent infinite recursion.
3244
+ */
3245
+ // fixAndParseJSON - recursively repairs top-level key/value
3246
+ // (when encountering outermost values that are objects/arrays, it recurses)
3247
+
3248
+ /*
3249
+ DEMO:
3250
+
3251
+ // ✅ Valid JSON (contains svg and single-quote content)
3252
+ const okJson = `{
3253
+ "label":"<svg width='16' height='16'><path fill='currentColor' d='M19 13h-6'/></svg> New Session",
3254
+ "value":"new",
3255
+ "onClick":"method.setVal(''); method.clearData();"
3256
+ }`;
3257
+
3258
+ // ❌ Single-quote JSON
3259
+ const badJson = "{'model':'{model}','messages':[{'role':'user','content':'{message}'}],'stream': true}";
3260
+
3261
+ // ❌ Escaped JSON
3262
+ 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();\\\"}";
3263
+
3264
+ 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();\"}";
3265
+
3266
+ 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}]";
3267
+
3268
+
3269
+ console.log('okJson =>', fixAndParseJSON(okJson)); // parses correctly
3270
+ console.log('badJson =>', fixAndParseJSON(badJson)); // repaired and parsed
3271
+ console.log('badJson2 =>', fixAndParseJSON(badJson2)); // repaired and parsed
3272
+ console.log('badJson3 =>', fixAndParseJSON(badJson3)); // repaired and parsed
3273
+ console.log('badJson4 =>', fixAndParseJSON(badJson4)); // repaired and parsed
3274
+ */
3275
+ function _fixAndParseJSON(input) {
3276
+ var MAX_DEPTH = 6;
3277
+
3278
+ // 1. Fast attempt
3279
+ try {
3280
+ return {
3281
+ success: true,
3282
+ data: JSON.parse(input)
3283
+ };
3284
+ } catch (e) {
3285
+ // continue to repair
3238
3286
  }
3239
- return false;
3287
+
3288
+ // 2. Simple unescape of \" (common when copied from JS literals)
3289
+ var s = input;
3290
+ if (s.includes('\\"')) s = s.replace(/\\"/g, '"');
3291
+ s = s.trim();
3292
+ try {
3293
+ if (s.startsWith('{')) {
3294
+ s = processTopObject(s, 0, MAX_DEPTH);
3295
+ } else if (s.startsWith('[')) {
3296
+ s = processTopArray(s, 0, MAX_DEPTH);
3297
+ } else {
3298
+ throw new Error('Input is not an object or array');
3299
+ }
3300
+ return {
3301
+ success: true,
3302
+ data: JSON.parse(s)
3303
+ };
3304
+ } catch (err) {
3305
+ return {
3306
+ success: false,
3307
+ error: 'Invalid JSON format',
3308
+ details: err instanceof Error ? err.message : String(err)
3309
+ };
3310
+ }
3311
+ }
3312
+
3313
+ /* ---------- Helper (recursive) functions ---------- */
3314
+
3315
+ function processTopObject(str, depth, MAX_DEPTH) {
3316
+ if (depth > MAX_DEPTH) return str;
3317
+ str = str.trim();
3318
+ // Ensure it is wrapped in { ... }
3319
+ if (!(str.startsWith('{') && str.endsWith('}'))) {
3320
+ var f = str.indexOf('{');
3321
+ var l = str.lastIndexOf('}');
3322
+ if (f === -1 || l === -1 || l <= f) return str;
3323
+ str = str.slice(f, l + 1);
3324
+ }
3325
+ var inner = str.slice(1, -1);
3326
+ var pairs = splitTopLevel(inner);
3327
+ var repairedPairs = pairs.map(function (pair) {
3328
+ if (!pair || pair.trim() === '') return '';
3329
+ var idx = findTopLevelColon(pair);
3330
+ if (idx === -1) {
3331
+ return pair; // Non key:value fragment, keep as is (rare case)
3332
+ }
3333
+
3334
+ var rawKey = pair.slice(0, idx).trim();
3335
+ var rawVal = pair.slice(idx + 1);
3336
+ var keyContent = extractKeyContent(rawKey);
3337
+ var keyJson = JSON.stringify(keyContent);
3338
+ var repairedValue = repairPossiblyQuotedValue(rawVal, depth + 1, MAX_DEPTH);
3339
+ return keyJson + ':' + repairedValue;
3340
+ });
3341
+ return '{' + repairedPairs.join(',') + '}';
3342
+ }
3343
+ function processTopArray(str, depth, MAX_DEPTH) {
3344
+ if (depth > MAX_DEPTH) return str;
3345
+ str = str.trim();
3346
+ if (!(str.startsWith('[') && str.endsWith(']'))) {
3347
+ var f = str.indexOf('[');
3348
+ var l = str.lastIndexOf(']');
3349
+ if (f === -1 || l === -1 || l <= f) return str;
3350
+ str = str.slice(f, l + 1);
3351
+ }
3352
+ var inner = str.slice(1, -1);
3353
+ var elements = splitTopLevel(inner);
3354
+ var processed = elements.map(function (el) {
3355
+ var t = el.trim();
3356
+ if (t === '') return '';
3357
+ if (t.startsWith('{')) return processTopObject(t, depth + 1, MAX_DEPTH);
3358
+ if (t.startsWith('[')) return processTopArray(t, depth + 1, MAX_DEPTH);
3359
+ return repairPossiblyQuotedValue(t, depth + 1, MAX_DEPTH);
3360
+ });
3361
+ return '[' + processed.join(',') + ']';
3362
+ }
3363
+
3364
+ // If value is quoted, extract inside and JSON.stringify again (safe escaping)
3365
+ // If value is unquoted object/array literal, recurse treating it as new root
3366
+ // Otherwise return as is (numbers, booleans, null, or raw expressions)
3367
+ function repairPossiblyQuotedValue(rawVal, depth, MAX_DEPTH) {
3368
+ var v = rawVal.trim();
3369
+ if (v === '') return v;
3370
+ if (v[0] === '"' || v[0] === "'") {
3371
+ var quote = v[0];
3372
+ // Find the last unescaped matching quote
3373
+ var lastPos = -1;
3374
+ for (var i = v.length - 1; i >= 0; i--) {
3375
+ if (v[i] === quote) {
3376
+ // check if escaped
3377
+ var bs = 0;
3378
+ var k = i - 1;
3379
+ while (k >= 0 && v[k] === '\\') {
3380
+ bs++;
3381
+ k--;
3382
+ }
3383
+ if (bs % 2 === 0) {
3384
+ lastPos = i;
3385
+ break;
3386
+ }
3387
+ }
3388
+ }
3389
+ var inner = lastPos > 0 ? v.slice(1, lastPos) : v.slice(1);
3390
+ return JSON.stringify(inner); // Generate valid JSON string (auto escape)
3391
+ }
3392
+
3393
+ // If unquoted object/array literal -> recurse
3394
+ if (v.startsWith('{')) {
3395
+ return processTopObject(v, depth, MAX_DEPTH);
3396
+ }
3397
+ if (v.startsWith('[')) {
3398
+ return processTopArray(v, depth, MAX_DEPTH);
3399
+ }
3400
+
3401
+ // Other (number, boolean, null, raw expression): return as is
3402
+ return v;
3403
+ }
3404
+
3405
+ /* --------- Utils: split by top-level commas, find colon, extract key --------- */
3406
+
3407
+ // Split string by top-level commas (ignores commas inside strings/objects/arrays/parentheses)
3408
+ function splitTopLevel(str) {
3409
+ var parts = [];
3410
+ var buf = '';
3411
+ var depthCurly = 0;
3412
+ var depthSquare = 0;
3413
+ var depthParen = 0;
3414
+ var inSingle = false;
3415
+ var inDouble = false;
3416
+ var esc = false;
3417
+ for (var i = 0; i < str.length; i++) {
3418
+ var ch = str[i];
3419
+ if (esc) {
3420
+ buf += ch;
3421
+ esc = false;
3422
+ continue;
3423
+ }
3424
+ if (ch === '\\') {
3425
+ buf += ch;
3426
+ esc = true;
3427
+ continue;
3428
+ }
3429
+ if (ch === "'" && !inDouble) {
3430
+ inSingle = !inSingle;
3431
+ buf += ch;
3432
+ continue;
3433
+ }
3434
+ if (ch === '"' && !inSingle) {
3435
+ inDouble = !inDouble;
3436
+ buf += ch;
3437
+ continue;
3438
+ }
3439
+ if (!inSingle && !inDouble) {
3440
+ if (ch === '{') {
3441
+ depthCurly++;
3442
+ buf += ch;
3443
+ continue;
3444
+ }
3445
+ if (ch === '}') {
3446
+ depthCurly--;
3447
+ buf += ch;
3448
+ continue;
3449
+ }
3450
+ if (ch === '[') {
3451
+ depthSquare++;
3452
+ buf += ch;
3453
+ continue;
3454
+ }
3455
+ if (ch === ']') {
3456
+ depthSquare--;
3457
+ buf += ch;
3458
+ continue;
3459
+ }
3460
+ if (ch === '(') {
3461
+ depthParen++;
3462
+ buf += ch;
3463
+ continue;
3464
+ }
3465
+ if (ch === ')') {
3466
+ depthParen--;
3467
+ buf += ch;
3468
+ continue;
3469
+ }
3470
+ if (ch === ',' && depthCurly === 0 && depthSquare === 0 && depthParen === 0) {
3471
+ parts.push(buf);
3472
+ buf = '';
3473
+ continue;
3474
+ }
3475
+ }
3476
+ buf += ch;
3477
+ }
3478
+ if (buf.trim() !== '') parts.push(buf);
3479
+ return parts;
3480
+ }
3481
+
3482
+ // Find the first top-level colon (ignores strings and nested structures)
3483
+ function findTopLevelColon(str) {
3484
+ var inSingle = false;
3485
+ var inDouble = false;
3486
+ var esc = false;
3487
+ var depthCurly = 0;
3488
+ var depthSquare = 0;
3489
+ var depthParen = 0;
3490
+ for (var i = 0; i < str.length; i++) {
3491
+ var ch = str[i];
3492
+ if (esc) {
3493
+ esc = false;
3494
+ continue;
3495
+ }
3496
+ if (ch === '\\') {
3497
+ esc = true;
3498
+ continue;
3499
+ }
3500
+ if (ch === "'" && !inDouble) {
3501
+ inSingle = !inSingle;
3502
+ continue;
3503
+ }
3504
+ if (ch === '"' && !inSingle) {
3505
+ inDouble = !inDouble;
3506
+ continue;
3507
+ }
3508
+ if (!inSingle && !inDouble) {
3509
+ if (ch === '{') {
3510
+ depthCurly++;
3511
+ continue;
3512
+ }
3513
+ if (ch === '}') {
3514
+ depthCurly--;
3515
+ continue;
3516
+ }
3517
+ if (ch === '[') {
3518
+ depthSquare++;
3519
+ continue;
3520
+ }
3521
+ if (ch === ']') {
3522
+ depthSquare--;
3523
+ continue;
3524
+ }
3525
+ if (ch === '(') {
3526
+ depthParen++;
3527
+ continue;
3528
+ }
3529
+ if (ch === ')') {
3530
+ depthParen--;
3531
+ continue;
3532
+ }
3533
+ if (ch === ':' && depthCurly === 0 && depthSquare === 0 && depthParen === 0) {
3534
+ return i;
3535
+ }
3536
+ }
3537
+ }
3538
+ return -1;
3539
+ }
3540
+
3541
+ // Extract key content (supports "key", 'key', key) → returns pure string key
3542
+ function extractKeyContent(rawKey) {
3543
+ var r = rawKey.trim();
3544
+ if (r.startsWith('"') && r.endsWith('"') || r.startsWith("'") && r.endsWith("'")) {
3545
+ var inner = r.slice(1, -1).replace(/\\"/g, '"').replace(/\\'/g, "'");
3546
+ return inner;
3547
+ }
3548
+ return r;
3240
3549
  }
3241
3550
 
3242
3551
  /**
3243
3552
  * Determine whether it is in JSON format
3244
- * @param str - The value to check
3245
- * @returns boolean indicating if the value is valid JSON
3553
+ * @private
3246
3554
  */
3247
- function _isJSON(str) {
3248
- if (typeof str === 'string' && str.length > 0) {
3249
- if (str.replace(/\"\"/g, '').replace(/\,/g, '') === '[{}]') {
3250
- return false;
3251
- }
3252
- if (/^[\],:{}\s]*$/.test(str.replace(/\\["\\\/bfnrtu]/g, '@').replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']').replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
3555
+ function _isJSON(input) {
3556
+ if (typeof input === 'string' && input.length > 0) {
3557
+ return _fixAndParseJSON(input).success;
3558
+ } else {
3559
+ if (_typeof(input) === 'object' && Object.prototype.toString.call(input) === '[object Object]' && !input.length) {
3253
3560
  return true;
3561
+ } else {
3562
+ return false;
3254
3563
  }
3255
- return false;
3256
3564
  }
3257
- if (_typeof(str) === 'object' && Object.prototype.toString.call(str) === '[object Object]' && !str.length) {
3565
+ }
3566
+
3567
+ /**
3568
+ * Check if a string is a valid number
3569
+ * @param str - The string to check
3570
+ * @returns boolean indicating if the string is a valid number
3571
+ */
3572
+ function _isValidNumeric(str) {
3573
+ if (typeof str !== "string") return false; // we only process strings!
3574
+ if (!isNaN(Number(str)) &&
3575
+ // use type coercion to parse the _entirety_ of the string
3576
+ !isNaN(parseFloat(str)) // ensure strings of whitespace fail
3577
+ ) {
3258
3578
  return true;
3259
3579
  }
3260
3580
  return false;