@stoplight/elements-core 9.0.13-alpha-0.5 → 9.0.13-alpha-0.6

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.
@@ -4,12 +4,12 @@ import { JSONSchema7, JSONSchema7Definition } from 'json-schema';
4
4
  export declare type ParameterSpec = Pick<IHttpParam, 'name' | 'schema' | 'required'> & {
5
5
  examples?: (Omit<INodeExample, 'id'> | Omit<INodeExternalExample, 'id'>)[];
6
6
  };
7
- export declare function encodeSafeSelectorValue(value: string | number): string | number;
8
- export declare function decodeSafeSelectorValue(value: string | number): string | number;
9
- export declare function parameterOptions(parameter: ParameterSpec): {
7
+ export declare function parameterOptions(parameter: ParameterSpec): ({
10
8
  value: string | number;
9
+ } | {
11
10
  label: string;
12
- }[] | null;
11
+ value: string;
12
+ })[] | null;
13
13
  export declare const selectExampleOption: {
14
14
  value: string;
15
15
  label: string;
package/index.esm.js CHANGED
@@ -1340,50 +1340,8 @@ const booleanOptions = [
1340
1340
  { label: 'False', value: 'false' },
1341
1341
  { label: 'True', value: 'true' },
1342
1342
  ];
1343
- function encodeSafeSelectorValue(value) {
1344
- if (typeof value === 'number') {
1345
- return value;
1346
- }
1347
- const hasSpecialChars = /["'\[\]\\(){}]/.test(value);
1348
- if (!hasSpecialChars) {
1349
- return value;
1350
- }
1351
- try {
1352
- return 'b64:' + btoa(value);
1353
- }
1354
- catch (e) {
1355
- return 'enc:' + encodeURIComponent(value);
1356
- }
1357
- }
1358
- function decodeSafeSelectorValue(value) {
1359
- if (typeof value === 'number') {
1360
- return value;
1361
- }
1362
- if (value.startsWith('b64:')) {
1363
- try {
1364
- return atob(value.substring(4));
1365
- }
1366
- catch (e) {
1367
- return value;
1368
- }
1369
- }
1370
- if (value.startsWith('enc:')) {
1371
- try {
1372
- return decodeURIComponent(value.substring(4));
1373
- }
1374
- catch (e) {
1375
- return value;
1376
- }
1377
- }
1378
- return value;
1379
- }
1380
1343
  function enumOptions(enumValues, required) {
1381
- const options = map(enumValues, v => {
1382
- var _a;
1383
- const stringValue = typeof v === 'object' && v !== null ? (_a = safeStringify(v)) !== null && _a !== void 0 ? _a : String(v) : typeof v === 'number' ? v : String(v);
1384
- const safeValue = encodeSafeSelectorValue(stringValue);
1385
- return { value: safeValue, label: String(stringValue) };
1386
- });
1344
+ const options = map(enumValues, v => ({ value: typeof v === 'number' ? v : String(v) }));
1387
1345
  return required ? options : [{ label: 'Not Set', value: '' }, ...options];
1388
1346
  }
1389
1347
  function parameterOptions(parameter) {
@@ -1413,16 +1371,15 @@ function parameterSupportsFileUpload(parameter) {
1413
1371
  ((_c = parameter.schema) === null || _c === void 0 ? void 0 : _c.contentMediaType) === 'application/octet-stream'));
1414
1372
  }
1415
1373
  function stringifyValue(value) {
1416
- var _a;
1417
- if (typeof value === 'object' && value !== null) {
1418
- return (_a = safeStringify(value)) !== null && _a !== void 0 ? _a : String(value);
1419
- }
1420
- return String(value);
1374
+ return typeof value === 'object' ? JSON.stringify(value) : escapeQuotes(String(value));
1421
1375
  }
1422
1376
  function exampleValue(example) {
1423
1377
  const value = 'value' in example ? example.value : example.externalValue;
1424
1378
  return stringifyValue(value);
1425
1379
  }
1380
+ function escapeQuotes(value) {
1381
+ return value.replace(/"/g, '\\"');
1382
+ }
1426
1383
  function getPlaceholderForParameter(parameter) {
1427
1384
  var _a, _b;
1428
1385
  const { value: parameterValue, isDefault } = getValueForParameter(parameter);
@@ -1448,14 +1405,14 @@ const getValueForParameter = (parameter) => {
1448
1405
  if (typeof defaultValue !== 'undefined') {
1449
1406
  return { value: stringifyValue(defaultValue), isDefault: true };
1450
1407
  }
1451
- const enums = (_b = (_a = parameter.schema) === null || _a === void 0 ? void 0 : _a.enum) !== null && _b !== void 0 ? _b : [];
1452
- if (enums.length > 0) {
1453
- return { value: stringifyValue(enums[0]) };
1454
- }
1455
- const examples = (_c = parameter.examples) !== null && _c !== void 0 ? _c : [];
1408
+ const examples = (_a = parameter.examples) !== null && _a !== void 0 ? _a : [];
1456
1409
  if (examples.length > 0) {
1457
1410
  return { value: exampleValue(examples[0]) };
1458
1411
  }
1412
+ const enums = (_c = (_b = parameter.schema) === null || _b === void 0 ? void 0 : _b.enum) !== null && _c !== void 0 ? _c : [];
1413
+ if (enums.length > 0) {
1414
+ return { value: stringifyValue(enums[0]) };
1415
+ }
1459
1416
  return { value: '' };
1460
1417
  };
1461
1418
  const getInitialValueForParameter = (parameter) => {
@@ -1511,20 +1468,11 @@ const ParameterEditor = ({ parameter, value, onChange, isOptional, onChangeOptio
1511
1468
  const examples = exampleOptions(parameter);
1512
1469
  const selectedExample = (_a = examples === null || examples === void 0 ? void 0 : examples.find(e => e.value === value)) !== null && _a !== void 0 ? _a : selectExampleOption;
1513
1470
  const parameterDisplayName = `${parameter.name}${parameter.required ? '*' : ''}`;
1514
- console.log("Inside Parameter Editor in APLHA BRANCH");
1515
- const encodedValue = React.useMemo(() => {
1516
- if (!value || !parameterValueOptions)
1517
- return value || '';
1518
- const matchingOption = parameterValueOptions.find(opt => {
1519
- return String(decodeSafeSelectorValue(opt.value)) === value;
1520
- });
1521
- return matchingOption ? String(matchingOption.value) : value;
1522
- }, [value, parameterValueOptions]);
1523
1471
  const requiredButEmpty = validate && parameter.required && !value;
1524
1472
  return (React.createElement(React.Fragment, null,
1525
1473
  React.createElement(Text, { as: "label", "aria-hidden": "true", "data-testid": "param-label", htmlFor: inputId, fontSize: "base" }, parameterDisplayName),
1526
1474
  React.createElement(Text, { mx: 3 }, ":"),
1527
- React.createElement("div", null, parameterValueOptions ? (React.createElement(Select, { flex: 1, "aria-label": parameter.name, options: parameterValueOptions, value: encodedValue, onChange: val => onChange && onChange(String(decodeSafeSelectorValue(val))), placeholder: getPlaceholderForSelectedParameter(parameter) })) : (React.createElement(Flex, { flex: 1 },
1475
+ React.createElement("div", null, parameterValueOptions ? (React.createElement(Select, { flex: 1, "aria-label": parameter.name, options: parameterValueOptions, value: value || '', onChange: onChange, placeholder: getPlaceholderForSelectedParameter(parameter) })) : (React.createElement(Flex, { flex: 1 },
1528
1476
  React.createElement(Input, { id: inputId, "aria-label": parameter.name, appearance: requiredButEmpty ? 'default' : 'minimal', flex: 1, placeholder: getPlaceholderForParameter(parameter), type: ((_b = parameter.schema) === null || _b === void 0 ? void 0 : _b.type) === 'number' ? 'number' : 'text', required: true, intent: requiredButEmpty ? 'danger' : 'default', value: value || '', onChange: e => onChange && onChange(e.currentTarget.value) }),
1529
1477
  examples && (React.createElement(Select, { "aria-label": `${parameter.name}-select`, flex: 1, value: selectedExample.value, options: examples, onChange: onChange }))))),
1530
1478
  canChangeOptional && !parameter.required && (React.createElement(React.Fragment, null,
@@ -2379,17 +2327,10 @@ ServersDropdown.displayName = 'ServersDropdown';
2379
2327
 
2380
2328
  const VariableEditor = ({ variable, value, onChange }) => {
2381
2329
  const inputId = useUniqueId(`id_${variable.name}_`);
2382
- const encodedOptions = React.useMemo(() => (variable.enum ? variable.enum.map(s => ({ value: encodeSafeSelectorValue(s), label: String(s) })) : []), [variable.enum]);
2383
- const encodedValue = React.useMemo(() => {
2384
- if (!value || !variable.enum)
2385
- return value || variable.default;
2386
- const matchingOption = encodedOptions.find(opt => decodeSafeSelectorValue(String(opt.value)) === value);
2387
- return matchingOption ? String(matchingOption.value) : value;
2388
- }, [value, variable.enum, variable.default, encodedOptions]);
2389
2330
  return (React.createElement(React.Fragment, null,
2390
2331
  React.createElement(Text, { as: "label", "aria-hidden": "true", "data-testid": "param-label", htmlFor: inputId, fontSize: "base" }, variable.name),
2391
2332
  React.createElement(Text, { mx: 3 }, ":"),
2392
- React.createElement("div", null, variable.enum ? (React.createElement(Select, { flex: 1, "aria-label": variable.name, options: encodedOptions, value: encodedValue, onChange: val => onChange && onChange(decodeSafeSelectorValue(String(val))) })) : (React.createElement(Flex, { flex: 1 },
2333
+ React.createElement("div", null, variable.enum ? (React.createElement(Select, { flex: 1, "aria-label": variable.name, options: variable.enum.map(s => ({ value: s })), value: value || variable.default, onChange: onChange })) : (React.createElement(Flex, { flex: 1 },
2393
2334
  React.createElement(Input, { id: inputId, "aria-label": variable.name, appearance: 'minimal', flex: 1, placeholder: variable.default, type: "text", required: true, intent: 'default', value: value || '', onChange: e => onChange && onChange(e.currentTarget.value) }))))));
2394
2335
  };
2395
2336
 
@@ -3594,6 +3535,38 @@ const TableOfContents = React.memo(({ tree, activeId, Link, maxDepthOpenByDefaul
3594
3535
  });
3595
3536
  }, []);
3596
3537
  const updatedTree = updateTocTree(tree, '');
3538
+ const findFirstMatchAndIndexMatch = React.useCallback((items, id) => {
3539
+ let firstMatch;
3540
+ let hasAnyLastIndexMatch = false;
3541
+ if (!id)
3542
+ return [firstMatch, hasAnyLastIndexMatch];
3543
+ const walk = (arr, stack) => {
3544
+ for (const itm of arr) {
3545
+ const newStack = stack.concat(itm);
3546
+ const matches = ('slug' in itm && itm.slug === id) || ('id' in itm && itm.id === id);
3547
+ if (matches) {
3548
+ if (!firstMatch)
3549
+ firstMatch = itm;
3550
+ const hasLastIndexMatch = newStack.some(el => 'index' in el && el.index === lastActiveIndex);
3551
+ if (hasLastIndexMatch)
3552
+ hasAnyLastIndexMatch = true;
3553
+ }
3554
+ if ('items' in itm && Array.isArray(itm.items)) {
3555
+ if (walk(itm.items, newStack))
3556
+ return true;
3557
+ }
3558
+ }
3559
+ return false;
3560
+ };
3561
+ walk(items, []);
3562
+ return [firstMatch, hasAnyLastIndexMatch];
3563
+ }, [lastActiveIndex]);
3564
+ const [firstMatchItem, hasAnyLastIndexMatch] = React.useMemo(() => findFirstMatchAndIndexMatch(updatedTree, activeId), [updatedTree, activeId, findFirstMatchAndIndexMatch]);
3565
+ React.useEffect(() => {
3566
+ if (!hasAnyLastIndexMatch && firstMatchItem && 'index' in firstMatchItem && firstMatchItem.index) {
3567
+ setLastActiveIndex(firstMatchItem.index);
3568
+ }
3569
+ }, [firstMatchItem, hasAnyLastIndexMatch]);
3597
3570
  const container = React.useRef(null);
3598
3571
  const child = React.useRef(null);
3599
3572
  const firstRender = useFirstRender();
package/index.js CHANGED
@@ -1361,50 +1361,8 @@ const booleanOptions = [
1361
1361
  { label: 'False', value: 'false' },
1362
1362
  { label: 'True', value: 'true' },
1363
1363
  ];
1364
- function encodeSafeSelectorValue(value) {
1365
- if (typeof value === 'number') {
1366
- return value;
1367
- }
1368
- const hasSpecialChars = /["'\[\]\\(){}]/.test(value);
1369
- if (!hasSpecialChars) {
1370
- return value;
1371
- }
1372
- try {
1373
- return 'b64:' + btoa(value);
1374
- }
1375
- catch (e) {
1376
- return 'enc:' + encodeURIComponent(value);
1377
- }
1378
- }
1379
- function decodeSafeSelectorValue(value) {
1380
- if (typeof value === 'number') {
1381
- return value;
1382
- }
1383
- if (value.startsWith('b64:')) {
1384
- try {
1385
- return atob(value.substring(4));
1386
- }
1387
- catch (e) {
1388
- return value;
1389
- }
1390
- }
1391
- if (value.startsWith('enc:')) {
1392
- try {
1393
- return decodeURIComponent(value.substring(4));
1394
- }
1395
- catch (e) {
1396
- return value;
1397
- }
1398
- }
1399
- return value;
1400
- }
1401
1364
  function enumOptions(enumValues, required) {
1402
- const options = map(enumValues, v => {
1403
- var _a;
1404
- const stringValue = typeof v === 'object' && v !== null ? (_a = json.safeStringify(v)) !== null && _a !== void 0 ? _a : String(v) : typeof v === 'number' ? v : String(v);
1405
- const safeValue = encodeSafeSelectorValue(stringValue);
1406
- return { value: safeValue, label: String(stringValue) };
1407
- });
1365
+ const options = map(enumValues, v => ({ value: typeof v === 'number' ? v : String(v) }));
1408
1366
  return required ? options : [{ label: 'Not Set', value: '' }, ...options];
1409
1367
  }
1410
1368
  function parameterOptions(parameter) {
@@ -1434,16 +1392,15 @@ function parameterSupportsFileUpload(parameter) {
1434
1392
  ((_c = parameter.schema) === null || _c === void 0 ? void 0 : _c.contentMediaType) === 'application/octet-stream'));
1435
1393
  }
1436
1394
  function stringifyValue(value) {
1437
- var _a;
1438
- if (typeof value === 'object' && value !== null) {
1439
- return (_a = json.safeStringify(value)) !== null && _a !== void 0 ? _a : String(value);
1440
- }
1441
- return String(value);
1395
+ return typeof value === 'object' ? JSON.stringify(value) : escapeQuotes(String(value));
1442
1396
  }
1443
1397
  function exampleValue(example) {
1444
1398
  const value = 'value' in example ? example.value : example.externalValue;
1445
1399
  return stringifyValue(value);
1446
1400
  }
1401
+ function escapeQuotes(value) {
1402
+ return value.replace(/"/g, '\\"');
1403
+ }
1447
1404
  function getPlaceholderForParameter(parameter) {
1448
1405
  var _a, _b;
1449
1406
  const { value: parameterValue, isDefault } = getValueForParameter(parameter);
@@ -1469,14 +1426,14 @@ const getValueForParameter = (parameter) => {
1469
1426
  if (typeof defaultValue !== 'undefined') {
1470
1427
  return { value: stringifyValue(defaultValue), isDefault: true };
1471
1428
  }
1472
- const enums = (_b = (_a = parameter.schema) === null || _a === void 0 ? void 0 : _a.enum) !== null && _b !== void 0 ? _b : [];
1473
- if (enums.length > 0) {
1474
- return { value: stringifyValue(enums[0]) };
1475
- }
1476
- const examples = (_c = parameter.examples) !== null && _c !== void 0 ? _c : [];
1429
+ const examples = (_a = parameter.examples) !== null && _a !== void 0 ? _a : [];
1477
1430
  if (examples.length > 0) {
1478
1431
  return { value: exampleValue(examples[0]) };
1479
1432
  }
1433
+ const enums = (_c = (_b = parameter.schema) === null || _b === void 0 ? void 0 : _b.enum) !== null && _c !== void 0 ? _c : [];
1434
+ if (enums.length > 0) {
1435
+ return { value: stringifyValue(enums[0]) };
1436
+ }
1480
1437
  return { value: '' };
1481
1438
  };
1482
1439
  const getInitialValueForParameter = (parameter) => {
@@ -1532,20 +1489,11 @@ const ParameterEditor = ({ parameter, value, onChange, isOptional, onChangeOptio
1532
1489
  const examples = exampleOptions(parameter);
1533
1490
  const selectedExample = (_a = examples === null || examples === void 0 ? void 0 : examples.find(e => e.value === value)) !== null && _a !== void 0 ? _a : selectExampleOption;
1534
1491
  const parameterDisplayName = `${parameter.name}${parameter.required ? '*' : ''}`;
1535
- console.log("Inside Parameter Editor in APLHA BRANCH");
1536
- const encodedValue = React__namespace.useMemo(() => {
1537
- if (!value || !parameterValueOptions)
1538
- return value || '';
1539
- const matchingOption = parameterValueOptions.find(opt => {
1540
- return String(decodeSafeSelectorValue(opt.value)) === value;
1541
- });
1542
- return matchingOption ? String(matchingOption.value) : value;
1543
- }, [value, parameterValueOptions]);
1544
1492
  const requiredButEmpty = validate && parameter.required && !value;
1545
1493
  return (React__namespace.createElement(React__namespace.Fragment, null,
1546
1494
  React__namespace.createElement(mosaic.Text, { as: "label", "aria-hidden": "true", "data-testid": "param-label", htmlFor: inputId, fontSize: "base" }, parameterDisplayName),
1547
1495
  React__namespace.createElement(mosaic.Text, { mx: 3 }, ":"),
1548
- React__namespace.createElement("div", null, parameterValueOptions ? (React__namespace.createElement(mosaic.Select, { flex: 1, "aria-label": parameter.name, options: parameterValueOptions, value: encodedValue, onChange: val => onChange && onChange(String(decodeSafeSelectorValue(val))), placeholder: getPlaceholderForSelectedParameter(parameter) })) : (React__namespace.createElement(mosaic.Flex, { flex: 1 },
1496
+ React__namespace.createElement("div", null, parameterValueOptions ? (React__namespace.createElement(mosaic.Select, { flex: 1, "aria-label": parameter.name, options: parameterValueOptions, value: value || '', onChange: onChange, placeholder: getPlaceholderForSelectedParameter(parameter) })) : (React__namespace.createElement(mosaic.Flex, { flex: 1 },
1549
1497
  React__namespace.createElement(mosaic.Input, { id: inputId, "aria-label": parameter.name, appearance: requiredButEmpty ? 'default' : 'minimal', flex: 1, placeholder: getPlaceholderForParameter(parameter), type: ((_b = parameter.schema) === null || _b === void 0 ? void 0 : _b.type) === 'number' ? 'number' : 'text', required: true, intent: requiredButEmpty ? 'danger' : 'default', value: value || '', onChange: e => onChange && onChange(e.currentTarget.value) }),
1550
1498
  examples && (React__namespace.createElement(mosaic.Select, { "aria-label": `${parameter.name}-select`, flex: 1, value: selectedExample.value, options: examples, onChange: onChange }))))),
1551
1499
  canChangeOptional && !parameter.required && (React__namespace.createElement(React__namespace.Fragment, null,
@@ -2400,17 +2348,10 @@ ServersDropdown.displayName = 'ServersDropdown';
2400
2348
 
2401
2349
  const VariableEditor = ({ variable, value, onChange }) => {
2402
2350
  const inputId = useUniqueId(`id_${variable.name}_`);
2403
- const encodedOptions = React__namespace.useMemo(() => (variable.enum ? variable.enum.map(s => ({ value: encodeSafeSelectorValue(s), label: String(s) })) : []), [variable.enum]);
2404
- const encodedValue = React__namespace.useMemo(() => {
2405
- if (!value || !variable.enum)
2406
- return value || variable.default;
2407
- const matchingOption = encodedOptions.find(opt => decodeSafeSelectorValue(String(opt.value)) === value);
2408
- return matchingOption ? String(matchingOption.value) : value;
2409
- }, [value, variable.enum, variable.default, encodedOptions]);
2410
2351
  return (React__namespace.createElement(React__namespace.Fragment, null,
2411
2352
  React__namespace.createElement(mosaic.Text, { as: "label", "aria-hidden": "true", "data-testid": "param-label", htmlFor: inputId, fontSize: "base" }, variable.name),
2412
2353
  React__namespace.createElement(mosaic.Text, { mx: 3 }, ":"),
2413
- React__namespace.createElement("div", null, variable.enum ? (React__namespace.createElement(mosaic.Select, { flex: 1, "aria-label": variable.name, options: encodedOptions, value: encodedValue, onChange: val => onChange && onChange(decodeSafeSelectorValue(String(val))) })) : (React__namespace.createElement(mosaic.Flex, { flex: 1 },
2354
+ React__namespace.createElement("div", null, variable.enum ? (React__namespace.createElement(mosaic.Select, { flex: 1, "aria-label": variable.name, options: variable.enum.map(s => ({ value: s })), value: value || variable.default, onChange: onChange })) : (React__namespace.createElement(mosaic.Flex, { flex: 1 },
2414
2355
  React__namespace.createElement(mosaic.Input, { id: inputId, "aria-label": variable.name, appearance: 'minimal', flex: 1, placeholder: variable.default, type: "text", required: true, intent: 'default', value: value || '', onChange: e => onChange && onChange(e.currentTarget.value) }))))));
2415
2356
  };
2416
2357
 
@@ -3615,6 +3556,38 @@ const TableOfContents = React__namespace.memo(({ tree, activeId, Link, maxDepthO
3615
3556
  });
3616
3557
  }, []);
3617
3558
  const updatedTree = updateTocTree(tree, '');
3559
+ const findFirstMatchAndIndexMatch = React__namespace.useCallback((items, id) => {
3560
+ let firstMatch;
3561
+ let hasAnyLastIndexMatch = false;
3562
+ if (!id)
3563
+ return [firstMatch, hasAnyLastIndexMatch];
3564
+ const walk = (arr, stack) => {
3565
+ for (const itm of arr) {
3566
+ const newStack = stack.concat(itm);
3567
+ const matches = ('slug' in itm && itm.slug === id) || ('id' in itm && itm.id === id);
3568
+ if (matches) {
3569
+ if (!firstMatch)
3570
+ firstMatch = itm;
3571
+ const hasLastIndexMatch = newStack.some(el => 'index' in el && el.index === lastActiveIndex);
3572
+ if (hasLastIndexMatch)
3573
+ hasAnyLastIndexMatch = true;
3574
+ }
3575
+ if ('items' in itm && Array.isArray(itm.items)) {
3576
+ if (walk(itm.items, newStack))
3577
+ return true;
3578
+ }
3579
+ }
3580
+ return false;
3581
+ };
3582
+ walk(items, []);
3583
+ return [firstMatch, hasAnyLastIndexMatch];
3584
+ }, [lastActiveIndex]);
3585
+ const [firstMatchItem, hasAnyLastIndexMatch] = React__namespace.useMemo(() => findFirstMatchAndIndexMatch(updatedTree, activeId), [updatedTree, activeId, findFirstMatchAndIndexMatch]);
3586
+ React__namespace.useEffect(() => {
3587
+ if (!hasAnyLastIndexMatch && firstMatchItem && 'index' in firstMatchItem && firstMatchItem.index) {
3588
+ setLastActiveIndex(firstMatchItem.index);
3589
+ }
3590
+ }, [firstMatchItem, hasAnyLastIndexMatch]);
3618
3591
  const container = React__namespace.useRef(null);
3619
3592
  const child = React__namespace.useRef(null);
3620
3593
  const firstRender = useFirstRender();
package/index.mjs CHANGED
@@ -1340,50 +1340,8 @@ const booleanOptions = [
1340
1340
  { label: 'False', value: 'false' },
1341
1341
  { label: 'True', value: 'true' },
1342
1342
  ];
1343
- function encodeSafeSelectorValue(value) {
1344
- if (typeof value === 'number') {
1345
- return value;
1346
- }
1347
- const hasSpecialChars = /["'\[\]\\(){}]/.test(value);
1348
- if (!hasSpecialChars) {
1349
- return value;
1350
- }
1351
- try {
1352
- return 'b64:' + btoa(value);
1353
- }
1354
- catch (e) {
1355
- return 'enc:' + encodeURIComponent(value);
1356
- }
1357
- }
1358
- function decodeSafeSelectorValue(value) {
1359
- if (typeof value === 'number') {
1360
- return value;
1361
- }
1362
- if (value.startsWith('b64:')) {
1363
- try {
1364
- return atob(value.substring(4));
1365
- }
1366
- catch (e) {
1367
- return value;
1368
- }
1369
- }
1370
- if (value.startsWith('enc:')) {
1371
- try {
1372
- return decodeURIComponent(value.substring(4));
1373
- }
1374
- catch (e) {
1375
- return value;
1376
- }
1377
- }
1378
- return value;
1379
- }
1380
1343
  function enumOptions(enumValues, required) {
1381
- const options = map(enumValues, v => {
1382
- var _a;
1383
- const stringValue = typeof v === 'object' && v !== null ? (_a = safeStringify(v)) !== null && _a !== void 0 ? _a : String(v) : typeof v === 'number' ? v : String(v);
1384
- const safeValue = encodeSafeSelectorValue(stringValue);
1385
- return { value: safeValue, label: String(stringValue) };
1386
- });
1344
+ const options = map(enumValues, v => ({ value: typeof v === 'number' ? v : String(v) }));
1387
1345
  return required ? options : [{ label: 'Not Set', value: '' }, ...options];
1388
1346
  }
1389
1347
  function parameterOptions(parameter) {
@@ -1413,16 +1371,15 @@ function parameterSupportsFileUpload(parameter) {
1413
1371
  ((_c = parameter.schema) === null || _c === void 0 ? void 0 : _c.contentMediaType) === 'application/octet-stream'));
1414
1372
  }
1415
1373
  function stringifyValue(value) {
1416
- var _a;
1417
- if (typeof value === 'object' && value !== null) {
1418
- return (_a = safeStringify(value)) !== null && _a !== void 0 ? _a : String(value);
1419
- }
1420
- return String(value);
1374
+ return typeof value === 'object' ? JSON.stringify(value) : escapeQuotes(String(value));
1421
1375
  }
1422
1376
  function exampleValue(example) {
1423
1377
  const value = 'value' in example ? example.value : example.externalValue;
1424
1378
  return stringifyValue(value);
1425
1379
  }
1380
+ function escapeQuotes(value) {
1381
+ return value.replace(/"/g, '\\"');
1382
+ }
1426
1383
  function getPlaceholderForParameter(parameter) {
1427
1384
  var _a, _b;
1428
1385
  const { value: parameterValue, isDefault } = getValueForParameter(parameter);
@@ -1448,14 +1405,14 @@ const getValueForParameter = (parameter) => {
1448
1405
  if (typeof defaultValue !== 'undefined') {
1449
1406
  return { value: stringifyValue(defaultValue), isDefault: true };
1450
1407
  }
1451
- const enums = (_b = (_a = parameter.schema) === null || _a === void 0 ? void 0 : _a.enum) !== null && _b !== void 0 ? _b : [];
1452
- if (enums.length > 0) {
1453
- return { value: stringifyValue(enums[0]) };
1454
- }
1455
- const examples = (_c = parameter.examples) !== null && _c !== void 0 ? _c : [];
1408
+ const examples = (_a = parameter.examples) !== null && _a !== void 0 ? _a : [];
1456
1409
  if (examples.length > 0) {
1457
1410
  return { value: exampleValue(examples[0]) };
1458
1411
  }
1412
+ const enums = (_c = (_b = parameter.schema) === null || _b === void 0 ? void 0 : _b.enum) !== null && _c !== void 0 ? _c : [];
1413
+ if (enums.length > 0) {
1414
+ return { value: stringifyValue(enums[0]) };
1415
+ }
1459
1416
  return { value: '' };
1460
1417
  };
1461
1418
  const getInitialValueForParameter = (parameter) => {
@@ -1511,20 +1468,11 @@ const ParameterEditor = ({ parameter, value, onChange, isOptional, onChangeOptio
1511
1468
  const examples = exampleOptions(parameter);
1512
1469
  const selectedExample = (_a = examples === null || examples === void 0 ? void 0 : examples.find(e => e.value === value)) !== null && _a !== void 0 ? _a : selectExampleOption;
1513
1470
  const parameterDisplayName = `${parameter.name}${parameter.required ? '*' : ''}`;
1514
- console.log("Inside Parameter Editor in APLHA BRANCH");
1515
- const encodedValue = React.useMemo(() => {
1516
- if (!value || !parameterValueOptions)
1517
- return value || '';
1518
- const matchingOption = parameterValueOptions.find(opt => {
1519
- return String(decodeSafeSelectorValue(opt.value)) === value;
1520
- });
1521
- return matchingOption ? String(matchingOption.value) : value;
1522
- }, [value, parameterValueOptions]);
1523
1471
  const requiredButEmpty = validate && parameter.required && !value;
1524
1472
  return (React.createElement(React.Fragment, null,
1525
1473
  React.createElement(Text, { as: "label", "aria-hidden": "true", "data-testid": "param-label", htmlFor: inputId, fontSize: "base" }, parameterDisplayName),
1526
1474
  React.createElement(Text, { mx: 3 }, ":"),
1527
- React.createElement("div", null, parameterValueOptions ? (React.createElement(Select, { flex: 1, "aria-label": parameter.name, options: parameterValueOptions, value: encodedValue, onChange: val => onChange && onChange(String(decodeSafeSelectorValue(val))), placeholder: getPlaceholderForSelectedParameter(parameter) })) : (React.createElement(Flex, { flex: 1 },
1475
+ React.createElement("div", null, parameterValueOptions ? (React.createElement(Select, { flex: 1, "aria-label": parameter.name, options: parameterValueOptions, value: value || '', onChange: onChange, placeholder: getPlaceholderForSelectedParameter(parameter) })) : (React.createElement(Flex, { flex: 1 },
1528
1476
  React.createElement(Input, { id: inputId, "aria-label": parameter.name, appearance: requiredButEmpty ? 'default' : 'minimal', flex: 1, placeholder: getPlaceholderForParameter(parameter), type: ((_b = parameter.schema) === null || _b === void 0 ? void 0 : _b.type) === 'number' ? 'number' : 'text', required: true, intent: requiredButEmpty ? 'danger' : 'default', value: value || '', onChange: e => onChange && onChange(e.currentTarget.value) }),
1529
1477
  examples && (React.createElement(Select, { "aria-label": `${parameter.name}-select`, flex: 1, value: selectedExample.value, options: examples, onChange: onChange }))))),
1530
1478
  canChangeOptional && !parameter.required && (React.createElement(React.Fragment, null,
@@ -2379,17 +2327,10 @@ ServersDropdown.displayName = 'ServersDropdown';
2379
2327
 
2380
2328
  const VariableEditor = ({ variable, value, onChange }) => {
2381
2329
  const inputId = useUniqueId(`id_${variable.name}_`);
2382
- const encodedOptions = React.useMemo(() => (variable.enum ? variable.enum.map(s => ({ value: encodeSafeSelectorValue(s), label: String(s) })) : []), [variable.enum]);
2383
- const encodedValue = React.useMemo(() => {
2384
- if (!value || !variable.enum)
2385
- return value || variable.default;
2386
- const matchingOption = encodedOptions.find(opt => decodeSafeSelectorValue(String(opt.value)) === value);
2387
- return matchingOption ? String(matchingOption.value) : value;
2388
- }, [value, variable.enum, variable.default, encodedOptions]);
2389
2330
  return (React.createElement(React.Fragment, null,
2390
2331
  React.createElement(Text, { as: "label", "aria-hidden": "true", "data-testid": "param-label", htmlFor: inputId, fontSize: "base" }, variable.name),
2391
2332
  React.createElement(Text, { mx: 3 }, ":"),
2392
- React.createElement("div", null, variable.enum ? (React.createElement(Select, { flex: 1, "aria-label": variable.name, options: encodedOptions, value: encodedValue, onChange: val => onChange && onChange(decodeSafeSelectorValue(String(val))) })) : (React.createElement(Flex, { flex: 1 },
2333
+ React.createElement("div", null, variable.enum ? (React.createElement(Select, { flex: 1, "aria-label": variable.name, options: variable.enum.map(s => ({ value: s })), value: value || variable.default, onChange: onChange })) : (React.createElement(Flex, { flex: 1 },
2393
2334
  React.createElement(Input, { id: inputId, "aria-label": variable.name, appearance: 'minimal', flex: 1, placeholder: variable.default, type: "text", required: true, intent: 'default', value: value || '', onChange: e => onChange && onChange(e.currentTarget.value) }))))));
2394
2335
  };
2395
2336
 
@@ -3594,6 +3535,38 @@ const TableOfContents = React.memo(({ tree, activeId, Link, maxDepthOpenByDefaul
3594
3535
  });
3595
3536
  }, []);
3596
3537
  const updatedTree = updateTocTree(tree, '');
3538
+ const findFirstMatchAndIndexMatch = React.useCallback((items, id) => {
3539
+ let firstMatch;
3540
+ let hasAnyLastIndexMatch = false;
3541
+ if (!id)
3542
+ return [firstMatch, hasAnyLastIndexMatch];
3543
+ const walk = (arr, stack) => {
3544
+ for (const itm of arr) {
3545
+ const newStack = stack.concat(itm);
3546
+ const matches = ('slug' in itm && itm.slug === id) || ('id' in itm && itm.id === id);
3547
+ if (matches) {
3548
+ if (!firstMatch)
3549
+ firstMatch = itm;
3550
+ const hasLastIndexMatch = newStack.some(el => 'index' in el && el.index === lastActiveIndex);
3551
+ if (hasLastIndexMatch)
3552
+ hasAnyLastIndexMatch = true;
3553
+ }
3554
+ if ('items' in itm && Array.isArray(itm.items)) {
3555
+ if (walk(itm.items, newStack))
3556
+ return true;
3557
+ }
3558
+ }
3559
+ return false;
3560
+ };
3561
+ walk(items, []);
3562
+ return [firstMatch, hasAnyLastIndexMatch];
3563
+ }, [lastActiveIndex]);
3564
+ const [firstMatchItem, hasAnyLastIndexMatch] = React.useMemo(() => findFirstMatchAndIndexMatch(updatedTree, activeId), [updatedTree, activeId, findFirstMatchAndIndexMatch]);
3565
+ React.useEffect(() => {
3566
+ if (!hasAnyLastIndexMatch && firstMatchItem && 'index' in firstMatchItem && firstMatchItem.index) {
3567
+ setLastActiveIndex(firstMatchItem.index);
3568
+ }
3569
+ }, [firstMatchItem, hasAnyLastIndexMatch]);
3597
3570
  const container = React.useRef(null);
3598
3571
  const child = React.useRef(null);
3599
3572
  const firstRender = useFirstRender();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stoplight/elements-core",
3
- "version": "9.0.13-alpha-0.5",
3
+ "version": "9.0.13-alpha-0.6",
4
4
  "main": "./index.js",
5
5
  "sideEffects": [
6
6
  "web-components.min.js",