@stoplight/elements-core 9.0.12-beta-0.4 → 9.0.13-alpha-0.1
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.
- package/components/Docs/Docs.d.ts +1 -14
- package/components/Docs/HttpOperation/Body.d.ts +1 -9
- package/components/Docs/HttpOperation/HttpOperation.d.ts +2 -6
- package/components/Docs/HttpOperation/Request.d.ts +0 -6
- package/components/Docs/HttpOperation/Responses.d.ts +1 -12
- package/components/TableOfContents/types.d.ts +7 -0
- package/components/TryIt/Parameters/parameter-utils.d.ts +4 -4
- package/index.esm.js +156 -538
- package/index.js +156 -538
- package/index.mjs +156 -538
- package/package.json +1 -1
- package/components/Docs/HttpOperation/LazySchemaTreePreviewer.d.ts +0 -34
package/index.esm.js
CHANGED
|
@@ -113,8 +113,6 @@ const isResolvedObjectProxy = (someObject) => {
|
|
|
113
113
|
return !!someObject[originalObjectSymbol];
|
|
114
114
|
};
|
|
115
115
|
const getOriginalObject = (resolvedObject) => {
|
|
116
|
-
if (!resolvedObject)
|
|
117
|
-
return resolvedObject;
|
|
118
116
|
const originalObject = resolvedObject[originalObjectSymbol] || resolvedObject;
|
|
119
117
|
if (!originalObject) {
|
|
120
118
|
return resolvedObject;
|
|
@@ -1342,8 +1340,50 @@ const booleanOptions = [
|
|
|
1342
1340
|
{ label: 'False', value: 'false' },
|
|
1343
1341
|
{ label: 'True', value: 'true' },
|
|
1344
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
|
+
}
|
|
1345
1380
|
function enumOptions(enumValues, required) {
|
|
1346
|
-
const options = map(enumValues, v =>
|
|
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
|
+
});
|
|
1347
1387
|
return required ? options : [{ label: 'Not Set', value: '' }, ...options];
|
|
1348
1388
|
}
|
|
1349
1389
|
function parameterOptions(parameter) {
|
|
@@ -1373,15 +1413,16 @@ function parameterSupportsFileUpload(parameter) {
|
|
|
1373
1413
|
((_c = parameter.schema) === null || _c === void 0 ? void 0 : _c.contentMediaType) === 'application/octet-stream'));
|
|
1374
1414
|
}
|
|
1375
1415
|
function stringifyValue(value) {
|
|
1376
|
-
|
|
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);
|
|
1377
1421
|
}
|
|
1378
1422
|
function exampleValue(example) {
|
|
1379
1423
|
const value = 'value' in example ? example.value : example.externalValue;
|
|
1380
1424
|
return stringifyValue(value);
|
|
1381
1425
|
}
|
|
1382
|
-
function escapeQuotes(value) {
|
|
1383
|
-
return value.replace(/"/g, '\\"');
|
|
1384
|
-
}
|
|
1385
1426
|
function getPlaceholderForParameter(parameter) {
|
|
1386
1427
|
var _a, _b;
|
|
1387
1428
|
const { value: parameterValue, isDefault } = getValueForParameter(parameter);
|
|
@@ -1407,14 +1448,14 @@ const getValueForParameter = (parameter) => {
|
|
|
1407
1448
|
if (typeof defaultValue !== 'undefined') {
|
|
1408
1449
|
return { value: stringifyValue(defaultValue), isDefault: true };
|
|
1409
1450
|
}
|
|
1410
|
-
const
|
|
1411
|
-
if (examples.length > 0) {
|
|
1412
|
-
return { value: exampleValue(examples[0]) };
|
|
1413
|
-
}
|
|
1414
|
-
const enums = (_c = (_b = parameter.schema) === null || _b === void 0 ? void 0 : _b.enum) !== null && _c !== void 0 ? _c : [];
|
|
1451
|
+
const enums = (_b = (_a = parameter.schema) === null || _a === void 0 ? void 0 : _a.enum) !== null && _b !== void 0 ? _b : [];
|
|
1415
1452
|
if (enums.length > 0) {
|
|
1416
1453
|
return { value: stringifyValue(enums[0]) };
|
|
1417
1454
|
}
|
|
1455
|
+
const examples = (_c = parameter.examples) !== null && _c !== void 0 ? _c : [];
|
|
1456
|
+
if (examples.length > 0) {
|
|
1457
|
+
return { value: exampleValue(examples[0]) };
|
|
1458
|
+
}
|
|
1418
1459
|
return { value: '' };
|
|
1419
1460
|
};
|
|
1420
1461
|
const getInitialValueForParameter = (parameter) => {
|
|
@@ -1470,11 +1511,19 @@ const ParameterEditor = ({ parameter, value, onChange, isOptional, onChangeOptio
|
|
|
1470
1511
|
const examples = exampleOptions(parameter);
|
|
1471
1512
|
const selectedExample = (_a = examples === null || examples === void 0 ? void 0 : examples.find(e => e.value === value)) !== null && _a !== void 0 ? _a : selectExampleOption;
|
|
1472
1513
|
const parameterDisplayName = `${parameter.name}${parameter.required ? '*' : ''}`;
|
|
1514
|
+
const encodedValue = React.useMemo(() => {
|
|
1515
|
+
if (!value || !parameterValueOptions)
|
|
1516
|
+
return value || '';
|
|
1517
|
+
const matchingOption = parameterValueOptions.find(opt => {
|
|
1518
|
+
return String(decodeSafeSelectorValue(opt.value)) === value;
|
|
1519
|
+
});
|
|
1520
|
+
return matchingOption ? String(matchingOption.value) : value;
|
|
1521
|
+
}, [value, parameterValueOptions]);
|
|
1473
1522
|
const requiredButEmpty = validate && parameter.required && !value;
|
|
1474
1523
|
return (React.createElement(React.Fragment, null,
|
|
1475
1524
|
React.createElement(Text, { as: "label", "aria-hidden": "true", "data-testid": "param-label", htmlFor: inputId, fontSize: "base" }, parameterDisplayName),
|
|
1476
1525
|
React.createElement(Text, { mx: 3 }, ":"),
|
|
1477
|
-
React.createElement("div", null, parameterValueOptions ? (React.createElement(Select, { flex: 1, "aria-label": parameter.name, options: parameterValueOptions, value:
|
|
1526
|
+
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 },
|
|
1478
1527
|
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) }),
|
|
1479
1528
|
examples && (React.createElement(Select, { "aria-label": `${parameter.name}-select`, flex: 1, value: selectedExample.value, options: examples, onChange: onChange }))))),
|
|
1480
1529
|
canChangeOptional && !parameter.required && (React.createElement(React.Fragment, null,
|
|
@@ -2329,10 +2378,17 @@ ServersDropdown.displayName = 'ServersDropdown';
|
|
|
2329
2378
|
|
|
2330
2379
|
const VariableEditor = ({ variable, value, onChange }) => {
|
|
2331
2380
|
const inputId = useUniqueId(`id_${variable.name}_`);
|
|
2381
|
+
const encodedOptions = React.useMemo(() => (variable.enum ? variable.enum.map(s => ({ value: encodeSafeSelectorValue(s), label: String(s) })) : []), [variable.enum]);
|
|
2382
|
+
const encodedValue = React.useMemo(() => {
|
|
2383
|
+
if (!value || !variable.enum)
|
|
2384
|
+
return value || variable.default;
|
|
2385
|
+
const matchingOption = encodedOptions.find(opt => decodeSafeSelectorValue(String(opt.value)) === value);
|
|
2386
|
+
return matchingOption ? String(matchingOption.value) : value;
|
|
2387
|
+
}, [value, variable.enum, variable.default, encodedOptions]);
|
|
2332
2388
|
return (React.createElement(React.Fragment, null,
|
|
2333
2389
|
React.createElement(Text, { as: "label", "aria-hidden": "true", "data-testid": "param-label", htmlFor: inputId, fontSize: "base" }, variable.name),
|
|
2334
2390
|
React.createElement(Text, { mx: 3 }, ":"),
|
|
2335
|
-
React.createElement("div", null, variable.enum ? (React.createElement(Select, { flex: 1, "aria-label": variable.name, options:
|
|
2391
|
+
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 },
|
|
2336
2392
|
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) }))))));
|
|
2337
2393
|
};
|
|
2338
2394
|
|
|
@@ -2740,417 +2796,13 @@ const PanelContent = ({ schemes }) => {
|
|
|
2740
2796
|
})));
|
|
2741
2797
|
};
|
|
2742
2798
|
|
|
2743
|
-
const TYPES = ['string', 'integer', 'boolean', 'any', 'number'];
|
|
2744
|
-
function resolvePointer(obj, pointer) {
|
|
2745
|
-
const parts = pointer.replace(/^#\//, '').split('/');
|
|
2746
|
-
return parts.reduce((acc, key) => acc && acc[key], obj);
|
|
2747
|
-
}
|
|
2748
|
-
function detectCircularPath(path) {
|
|
2749
|
-
const ignored = ['properties', 'items'];
|
|
2750
|
-
const parts = path.split('/').filter(part => !ignored.includes(part));
|
|
2751
|
-
for (let i = 0; i < parts.length - 1; i++) {
|
|
2752
|
-
const current = parts[i];
|
|
2753
|
-
const rest = parts.slice(i + 1);
|
|
2754
|
-
if (rest.includes(current)) {
|
|
2755
|
-
return true;
|
|
2756
|
-
}
|
|
2757
|
-
}
|
|
2758
|
-
return false;
|
|
2759
|
-
}
|
|
2760
|
-
function dereference(node, root, visited = new WeakSet(), depth = 0, maxDepth = 10) {
|
|
2761
|
-
if (!node || typeof node !== 'object')
|
|
2762
|
-
return node;
|
|
2763
|
-
if (depth > maxDepth)
|
|
2764
|
-
return node;
|
|
2765
|
-
if (node.$ref || node['x-iata-$ref']) {
|
|
2766
|
-
let refPath = node.$ref || node['x-iata-$ref'];
|
|
2767
|
-
if (refPath.includes('#/%24defs')) {
|
|
2768
|
-
refPath = refPath.replace('#/%24defs', '$defs');
|
|
2769
|
-
}
|
|
2770
|
-
else {
|
|
2771
|
-
refPath = refPath.replace('__bundled__', 'definitions');
|
|
2772
|
-
}
|
|
2773
|
-
if (visited.has(node))
|
|
2774
|
-
return { circular: true, $ref: refPath, title: node.title, type: 'any', description: node.description };
|
|
2775
|
-
visited.add(node);
|
|
2776
|
-
const target = resolvePointer(root, refPath);
|
|
2777
|
-
if (!target)
|
|
2778
|
-
return node;
|
|
2779
|
-
const result = Object.assign({}, target);
|
|
2780
|
-
if ('description' in node)
|
|
2781
|
-
result.description = node.description;
|
|
2782
|
-
if ('title' in node)
|
|
2783
|
-
result.title = node.title;
|
|
2784
|
-
return dereference(result, root, visited, depth + 1, maxDepth);
|
|
2785
|
-
}
|
|
2786
|
-
if (Array.isArray(node)) {
|
|
2787
|
-
return node.map(item => dereference(item, root, visited, depth + 1, maxDepth));
|
|
2788
|
-
}
|
|
2789
|
-
const result = {};
|
|
2790
|
-
for (const key in node) {
|
|
2791
|
-
result[key] = dereference(node[key], root, visited, depth + 1, maxDepth);
|
|
2792
|
-
}
|
|
2793
|
-
return result;
|
|
2794
|
-
}
|
|
2795
|
-
const trimSlashes = (str) => {
|
|
2796
|
-
return str.replace(/^\/|\/$/g, '');
|
|
2797
|
-
};
|
|
2798
|
-
function isPropertiesAllHidden(path, hideData) {
|
|
2799
|
-
const current = trimSlashes(path);
|
|
2800
|
-
const parts = current.split('/');
|
|
2801
|
-
for (let i = parts.length; i >= 2; i--) {
|
|
2802
|
-
if (parts[i - 1] === 'properties') {
|
|
2803
|
-
const ancestorPropPath = parts.slice(0, i).join('/');
|
|
2804
|
-
const block = hideData.find(h => trimSlashes(h.path) === ancestorPropPath && ancestorPropPath.endsWith('/properties'));
|
|
2805
|
-
if (block && block.required === undefined) {
|
|
2806
|
-
return true;
|
|
2807
|
-
}
|
|
2808
|
-
}
|
|
2809
|
-
}
|
|
2810
|
-
return false;
|
|
2811
|
-
}
|
|
2812
|
-
function isRequiredOverride(path, hideData) {
|
|
2813
|
-
const entry = hideData.find(h => trimSlashes(h.path) === trimSlashes(path));
|
|
2814
|
-
return entry && typeof entry.required === 'boolean' ? entry.required : undefined;
|
|
2815
|
-
}
|
|
2816
|
-
function isPathHidden(path, hideData, complexData) {
|
|
2817
|
-
const isComplex = checkIfIsComplex(path, complexData);
|
|
2818
|
-
if (isComplex === null) {
|
|
2819
|
-
return false;
|
|
2820
|
-
}
|
|
2821
|
-
else if (isComplex) {
|
|
2822
|
-
const normalizedPath = trimSlashes(path);
|
|
2823
|
-
const direct = hideData.find(h => trimSlashes(h.path) === normalizedPath);
|
|
2824
|
-
if (direct && direct.required === undefined)
|
|
2825
|
-
return true;
|
|
2826
|
-
if (isPropertiesAllHidden(path, hideData))
|
|
2827
|
-
return true;
|
|
2828
|
-
for (const h of hideData) {
|
|
2829
|
-
const hPath = trimSlashes(h.path);
|
|
2830
|
-
if (h.required !== undefined)
|
|
2831
|
-
continue;
|
|
2832
|
-
if (normalizedPath.length > hPath.length &&
|
|
2833
|
-
normalizedPath.startsWith(hPath) &&
|
|
2834
|
-
(hPath.endsWith('/items') || (hPath.match(/\/items\/[^\/]+$/) && normalizedPath.startsWith(hPath + '/')))) {
|
|
2835
|
-
return true;
|
|
2836
|
-
}
|
|
2837
|
-
}
|
|
2838
|
-
return false;
|
|
2839
|
-
}
|
|
2840
|
-
else {
|
|
2841
|
-
return !hideData.some(h => h.path === path || h.path.startsWith(path + '/'));
|
|
2842
|
-
}
|
|
2843
|
-
}
|
|
2844
|
-
const checkIfIsComplex = (path, complexData) => {
|
|
2845
|
-
let isComplex = null;
|
|
2846
|
-
for (const complex of complexData) {
|
|
2847
|
-
if (path.startsWith(complex.location)) {
|
|
2848
|
-
isComplex = complex === null || complex === void 0 ? void 0 : complex.isComplex;
|
|
2849
|
-
break;
|
|
2850
|
-
}
|
|
2851
|
-
}
|
|
2852
|
-
return isComplex;
|
|
2853
|
-
};
|
|
2854
|
-
const LazySchemaTreePreviewer = ({ schema, root = schema, title, level = 1, path = '', hideData = [], complexData = [], parentRequired, propertyKey, _subType, }) => {
|
|
2855
|
-
var _a, _b, _c, _d;
|
|
2856
|
-
const [expanded, setExpanded] = useState(false);
|
|
2857
|
-
const [selectedSchemaIndex, setSelectedSchemaIndex] = useState(0);
|
|
2858
|
-
const [showSchemaDropdown, setShowSchemaDropdown] = useState(false);
|
|
2859
|
-
const [isHoveringSelector, setIsHoveringSelector] = useState(false);
|
|
2860
|
-
const isRoot = level === 1 && (title === undefined || path === '');
|
|
2861
|
-
console.log("In LazySchemaTreePreviewer Beta 0.2:", { schema, path, isRoot });
|
|
2862
|
-
useEffect(() => {
|
|
2863
|
-
setSelectedSchemaIndex(0);
|
|
2864
|
-
}, [schema === null || schema === void 0 ? void 0 : schema.anyOf, schema === null || schema === void 0 ? void 0 : schema.oneOf]);
|
|
2865
|
-
const thisNodeRequiredOverride = isRequiredOverride(path, hideData);
|
|
2866
|
-
const shouldHideAllChildren = (isRoot && hideData.some(h => trimSlashes(h.path) === 'properties' && h.required === undefined)) ||
|
|
2867
|
-
(!isRoot && isPropertiesAllHidden(path, hideData));
|
|
2868
|
-
const hasExpandableChildren = useMemo(() => {
|
|
2869
|
-
var _a;
|
|
2870
|
-
if (shouldHideAllChildren)
|
|
2871
|
-
return false;
|
|
2872
|
-
if ((schema === null || schema === void 0 ? void 0 : schema.type) === 'object' && ((schema === null || schema === void 0 ? void 0 : schema.properties) || (schema === null || schema === void 0 ? void 0 : schema.allOf) || (schema === null || schema === void 0 ? void 0 : schema.anyOf) || (schema === null || schema === void 0 ? void 0 : schema.oneOf))) {
|
|
2873
|
-
let props = schema === null || schema === void 0 ? void 0 : schema.properties;
|
|
2874
|
-
if (schema === null || schema === void 0 ? void 0 : schema.allOf) {
|
|
2875
|
-
schema === null || schema === void 0 ? void 0 : schema.allOf.forEach((item) => {
|
|
2876
|
-
props = Object.assign(Object.assign({}, props), item.properties);
|
|
2877
|
-
});
|
|
2878
|
-
}
|
|
2879
|
-
if ((schema === null || schema === void 0 ? void 0 : schema.anyOf) && (schema === null || schema === void 0 ? void 0 : schema.anyOf.length) > 0) {
|
|
2880
|
-
const selectedSchema = (schema === null || schema === void 0 ? void 0 : schema.anyOf[selectedSchemaIndex]) || (schema === null || schema === void 0 ? void 0 : schema.anyOf[0]);
|
|
2881
|
-
props = Object.assign(Object.assign({}, props), selectedSchema.properties);
|
|
2882
|
-
}
|
|
2883
|
-
if ((schema === null || schema === void 0 ? void 0 : schema.oneOf) && (schema === null || schema === void 0 ? void 0 : schema.oneOf.length) > 0) {
|
|
2884
|
-
const selectedSchema = (schema === null || schema === void 0 ? void 0 : schema.oneOf[selectedSchemaIndex]) || (schema === null || schema === void 0 ? void 0 : schema.oneOf[0]);
|
|
2885
|
-
props = Object.assign(Object.assign({}, props), selectedSchema.properties);
|
|
2886
|
-
}
|
|
2887
|
-
if (props && Object.keys(props).length > 0) {
|
|
2888
|
-
for (const [key] of Object.entries(props)) {
|
|
2889
|
-
const childPath = `${path}/properties/${key}`;
|
|
2890
|
-
const childRequiredOverride = isRequiredOverride(childPath, hideData);
|
|
2891
|
-
const shouldHideChild = isPathHidden(childPath, hideData, complexData) && childRequiredOverride === undefined;
|
|
2892
|
-
if (!shouldHideChild)
|
|
2893
|
-
return true;
|
|
2894
|
-
}
|
|
2895
|
-
}
|
|
2896
|
-
}
|
|
2897
|
-
if ((schema === null || schema === void 0 ? void 0 : schema.type) === 'array' &&
|
|
2898
|
-
(schema === null || schema === void 0 ? void 0 : schema.items) &&
|
|
2899
|
-
Object.keys(schema === null || schema === void 0 ? void 0 : schema.items).length > 0 &&
|
|
2900
|
-
!((_a = schema === null || schema === void 0 ? void 0 : schema.items) === null || _a === void 0 ? void 0 : _a.circular)) {
|
|
2901
|
-
const resolvedItems = dereference(schema === null || schema === void 0 ? void 0 : schema.items, root);
|
|
2902
|
-
const itemsPath = `${path}/items`;
|
|
2903
|
-
if (resolvedItems && resolvedItems.type === 'object' && resolvedItems.properties) {
|
|
2904
|
-
for (const [key] of Object.entries(resolvedItems.properties)) {
|
|
2905
|
-
const childPath = `${itemsPath}/properties/${key}`;
|
|
2906
|
-
const childRequiredOverride = isRequiredOverride(childPath, hideData);
|
|
2907
|
-
const shouldHideChild = isPathHidden(childPath, hideData, complexData) && childRequiredOverride === undefined;
|
|
2908
|
-
if (!shouldHideChild)
|
|
2909
|
-
return true;
|
|
2910
|
-
}
|
|
2911
|
-
}
|
|
2912
|
-
else if (resolvedItems &&
|
|
2913
|
-
resolvedItems.type === 'array' &&
|
|
2914
|
-
resolvedItems.items &&
|
|
2915
|
-
resolvedItems.items.length > 0) {
|
|
2916
|
-
const childPath = `${path}/items`;
|
|
2917
|
-
const childRequiredOverride = isRequiredOverride(childPath, hideData);
|
|
2918
|
-
const shouldHideChild = isPathHidden(childPath, hideData, complexData) && childRequiredOverride === undefined;
|
|
2919
|
-
if (!shouldHideChild)
|
|
2920
|
-
return true;
|
|
2921
|
-
}
|
|
2922
|
-
}
|
|
2923
|
-
return false;
|
|
2924
|
-
}, [schema, path, hideData, complexData, shouldHideAllChildren, root, selectedSchemaIndex]);
|
|
2925
|
-
const shouldHideNode = useMemo(() => {
|
|
2926
|
-
if (isRoot)
|
|
2927
|
-
return false;
|
|
2928
|
-
if (isPathHidden(path, hideData, complexData) && thisNodeRequiredOverride === undefined)
|
|
2929
|
-
return true;
|
|
2930
|
-
return false;
|
|
2931
|
-
}, [path, hideData, isRoot, thisNodeRequiredOverride, complexData]);
|
|
2932
|
-
if (!schema || shouldHideNode) {
|
|
2933
|
-
return null;
|
|
2934
|
-
}
|
|
2935
|
-
const displayTitle = level === 1 && (title === undefined || path === '') ? '' : (_a = title !== null && title !== void 0 ? title : schema === null || schema === void 0 ? void 0 : schema.title) !== null && _a !== void 0 ? _a : 'Node';
|
|
2936
|
-
const handleToggle = () => {
|
|
2937
|
-
const circular = detectCircularPath(path);
|
|
2938
|
-
if (!circular) {
|
|
2939
|
-
setExpanded(prev => !prev);
|
|
2940
|
-
}
|
|
2941
|
-
};
|
|
2942
|
-
const renderChildren = () => {
|
|
2943
|
-
var _a, _b, _c, _d;
|
|
2944
|
-
if (shouldHideAllChildren)
|
|
2945
|
-
return null;
|
|
2946
|
-
if (!expanded && !isRoot)
|
|
2947
|
-
return null;
|
|
2948
|
-
const children = [];
|
|
2949
|
-
if ((schema === null || schema === void 0 ? void 0 : schema.type) === 'object' && ((schema === null || schema === void 0 ? void 0 : schema.properties) || (schema === null || schema === void 0 ? void 0 : schema.allOf) || (schema === null || schema === void 0 ? void 0 : schema.anyOf) || (schema === null || schema === void 0 ? void 0 : schema.oneOf))) {
|
|
2950
|
-
let props = schema === null || schema === void 0 ? void 0 : schema.properties;
|
|
2951
|
-
if (schema === null || schema === void 0 ? void 0 : schema.allOf) {
|
|
2952
|
-
schema === null || schema === void 0 ? void 0 : schema.allOf.forEach((item) => {
|
|
2953
|
-
props = Object.assign(Object.assign({}, props), item.properties);
|
|
2954
|
-
});
|
|
2955
|
-
}
|
|
2956
|
-
if ((schema === null || schema === void 0 ? void 0 : schema.anyOf) && (schema === null || schema === void 0 ? void 0 : schema.anyOf.length) > 0) {
|
|
2957
|
-
const selectedSchema = (schema === null || schema === void 0 ? void 0 : schema.anyOf[selectedSchemaIndex]) || (schema === null || schema === void 0 ? void 0 : schema.anyOf[0]);
|
|
2958
|
-
props = Object.assign(Object.assign({}, props), selectedSchema.properties);
|
|
2959
|
-
}
|
|
2960
|
-
if ((schema === null || schema === void 0 ? void 0 : schema.oneOf) && (schema === null || schema === void 0 ? void 0 : schema.oneOf.length) > 0) {
|
|
2961
|
-
const selectedSchema = (schema === null || schema === void 0 ? void 0 : schema.oneOf[selectedSchemaIndex]) || (schema === null || schema === void 0 ? void 0 : schema.oneOf[0]);
|
|
2962
|
-
props = Object.assign(Object.assign({}, props), selectedSchema.properties);
|
|
2963
|
-
}
|
|
2964
|
-
for (const [key, child] of Object.entries(props || {})) {
|
|
2965
|
-
const childPath = `${path}/properties/${key}`;
|
|
2966
|
-
const childRequiredOverride = isRequiredOverride(childPath, hideData);
|
|
2967
|
-
const shouldHideChild = isPathHidden(childPath, hideData, complexData) && childRequiredOverride === undefined;
|
|
2968
|
-
const resolved = dereference(child, root);
|
|
2969
|
-
if (!shouldHideChild) {
|
|
2970
|
-
children.push(React__default.createElement("li", { key: key },
|
|
2971
|
-
React__default.createElement(LazySchemaTreePreviewer, { schema: resolved, root: root, title: key, level: level + 1, path: childPath, hideData: hideData, complexData: complexData, parentRequired: schema === null || schema === void 0 ? void 0 : schema.required, propertyKey: key, _subType: (_a = resolved === null || resolved === void 0 ? void 0 : resolved.items) === null || _a === void 0 ? void 0 : _a.type })));
|
|
2972
|
-
}
|
|
2973
|
-
}
|
|
2974
|
-
}
|
|
2975
|
-
else if ((schema === null || schema === void 0 ? void 0 : schema.type) === 'array' &&
|
|
2976
|
-
(schema === null || schema === void 0 ? void 0 : schema.items) &&
|
|
2977
|
-
Object.keys(schema === null || schema === void 0 ? void 0 : schema.items).length > 0 &&
|
|
2978
|
-
!((_b = schema === null || schema === void 0 ? void 0 : schema.items) === null || _b === void 0 ? void 0 : _b.circular)) {
|
|
2979
|
-
const resolvedItems = dereference(schema === null || schema === void 0 ? void 0 : schema.items, root);
|
|
2980
|
-
const itemsPath = `${path}/items`;
|
|
2981
|
-
if (resolvedItems && resolvedItems.type === 'object' && resolvedItems.properties) {
|
|
2982
|
-
for (const [key, child] of Object.entries(resolvedItems.properties)) {
|
|
2983
|
-
const childPath = `${itemsPath}/properties/${key}`;
|
|
2984
|
-
const childRequiredOverride = isRequiredOverride(childPath, hideData);
|
|
2985
|
-
const shouldHideChild = isPathHidden(childPath, hideData, complexData) && childRequiredOverride === undefined;
|
|
2986
|
-
const resolved = dereference(child, root);
|
|
2987
|
-
if (!shouldHideChild) {
|
|
2988
|
-
children.push(React__default.createElement("li", { key: key },
|
|
2989
|
-
React__default.createElement(LazySchemaTreePreviewer, { schema: resolved, root: root, title: key, level: level + 2, path: childPath, hideData: hideData, complexData: complexData, parentRequired: resolvedItems.required, propertyKey: key, _subType: (_c = resolvedItems === null || resolvedItems === void 0 ? void 0 : resolvedItems.items) === null || _c === void 0 ? void 0 : _c.type })));
|
|
2990
|
-
}
|
|
2991
|
-
}
|
|
2992
|
-
}
|
|
2993
|
-
else if (resolvedItems && resolvedItems.type === 'array' && resolvedItems.items.length > 0) {
|
|
2994
|
-
const childPath = `${path}/items`;
|
|
2995
|
-
const childRequiredOverride = isRequiredOverride(childPath, hideData);
|
|
2996
|
-
const shouldHideChild = isPathHidden(childPath, hideData, complexData) && childRequiredOverride === undefined;
|
|
2997
|
-
if (!shouldHideChild) {
|
|
2998
|
-
children.push(React__default.createElement("li", { key: "items" },
|
|
2999
|
-
React__default.createElement(LazySchemaTreePreviewer, { schema: resolvedItems, root: root, title: "items", level: level + 1, path: childPath, hideData: hideData, complexData: complexData, parentRequired: schema === null || schema === void 0 ? void 0 : schema.required, propertyKey: "items", _subType: (_d = resolvedItems === null || resolvedItems === void 0 ? void 0 : resolvedItems.items) === null || _d === void 0 ? void 0 : _d.type })));
|
|
3000
|
-
}
|
|
3001
|
-
}
|
|
3002
|
-
}
|
|
3003
|
-
return children.length > 0 ? React__default.createElement("ul", { className: "ml-6 border-l border-gray-200 pl-2" }, children) : null;
|
|
3004
|
-
};
|
|
3005
|
-
const combinedSchemaSelector = () => {
|
|
3006
|
-
var _a;
|
|
3007
|
-
return (React__default.createElement(React__default.Fragment, null,
|
|
3008
|
-
React__default.createElement(Box, { pos: "fixed", top: 0, left: 0, right: 0, bottom: 0, bg: "transparent", style: { zIndex: 999 }, onClick: () => setShowSchemaDropdown(false) }),
|
|
3009
|
-
React__default.createElement(Box, { pos: "absolute", bg: "canvas", rounded: true, boxShadow: "md", style: {
|
|
3010
|
-
zIndex: 1000,
|
|
3011
|
-
top: '100%',
|
|
3012
|
-
left: 0,
|
|
3013
|
-
minWidth: '150px',
|
|
3014
|
-
maxWidth: '200px',
|
|
3015
|
-
marginTop: '2px',
|
|
3016
|
-
border: '1px solid rgba(0, 0, 0, 0.1)',
|
|
3017
|
-
}, fontSize: "sm", onClick: (e) => e.stopPropagation() }, (_a = ((schema === null || schema === void 0 ? void 0 : schema.anyOf) || (schema === null || schema === void 0 ? void 0 : schema.oneOf))) === null || _a === void 0 ? void 0 : _a.map((schemaOption, index) => (React__default.createElement(Box, { key: index, px: 3, py: 2, cursor: "pointer", bg: selectedSchemaIndex === index ? 'primary-tint' : 'canvas', fontSize: "xs", display: "flex", alignItems: "center", style: {
|
|
3018
|
-
borderBottom: index < ((schema === null || schema === void 0 ? void 0 : schema.anyOf) || (schema === null || schema === void 0 ? void 0 : schema.oneOf)).length - 1 ? '1px solid rgba(0, 0, 0, 0.1)' : 'none',
|
|
3019
|
-
gap: '8px',
|
|
3020
|
-
}, onMouseEnter: (e) => {
|
|
3021
|
-
if (selectedSchemaIndex !== index) {
|
|
3022
|
-
e.currentTarget.style.backgroundColor = 'var(--sl-color-canvas-tint)';
|
|
3023
|
-
}
|
|
3024
|
-
}, onMouseLeave: (e) => {
|
|
3025
|
-
if (selectedSchemaIndex !== index) {
|
|
3026
|
-
e.currentTarget.style.backgroundColor = 'var(--sl-color-canvas)';
|
|
3027
|
-
}
|
|
3028
|
-
}, onClick: () => {
|
|
3029
|
-
setSelectedSchemaIndex(index);
|
|
3030
|
-
setShowSchemaDropdown(false);
|
|
3031
|
-
} },
|
|
3032
|
-
React__default.createElement(Box, { flex: 1, color: "body" }, schemaOption.type || 'object'),
|
|
3033
|
-
selectedSchemaIndex === index && (React__default.createElement(Box, { color: "primary", fontSize: "xs" }, "\u2713"))))))));
|
|
3034
|
-
};
|
|
3035
|
-
const renderMinEnums = (schema) => {
|
|
3036
|
-
if (!schema || typeof schema !== 'object')
|
|
3037
|
-
return null;
|
|
3038
|
-
const boxStyle = {
|
|
3039
|
-
background: 'rgba(245, 247, 250, 0.5)',
|
|
3040
|
-
border: '1px solid #a0aec0',
|
|
3041
|
-
borderRadius: '4px',
|
|
3042
|
-
padding: '0px 2px',
|
|
3043
|
-
display: 'inline-block',
|
|
3044
|
-
overflowWrap: 'break-word',
|
|
3045
|
-
textAlign: 'left',
|
|
3046
|
-
maxWidth: 'fit-content',
|
|
3047
|
-
maxHeight: 'fit-content',
|
|
3048
|
-
};
|
|
3049
|
-
if ('minItems' in schema) {
|
|
3050
|
-
const schemaWithMinItems = schema;
|
|
3051
|
-
if (typeof schemaWithMinItems.minItems === 'number') {
|
|
3052
|
-
return (React__default.createElement(Box, { className: "sl-text-muted", fontFamily: "ui", fontWeight: "normal", mr: 2, style: boxStyle }, `>=${schemaWithMinItems.minItems} items`));
|
|
3053
|
-
}
|
|
3054
|
-
}
|
|
3055
|
-
if ('enum' in schema && Array.isArray(schema.enum)) {
|
|
3056
|
-
return (React__default.createElement("div", null,
|
|
3057
|
-
"Allowed values:",
|
|
3058
|
-
' ',
|
|
3059
|
-
schema.enum.map((val, idx) => (React__default.createElement(Box, { key: idx, className: "sl-text-muted", fontFamily: "ui", fontWeight: "normal", mr: 2, style: boxStyle }, val)))));
|
|
3060
|
-
}
|
|
3061
|
-
return null;
|
|
3062
|
-
};
|
|
3063
|
-
const isRequired = parentRequired && propertyKey && parentRequired.includes(propertyKey);
|
|
3064
|
-
let showRequiredLabel = false;
|
|
3065
|
-
const hideDataEntry = hideData.find(hideEntry => trimSlashes(hideEntry.path) === trimSlashes(path));
|
|
3066
|
-
if ((hideDataEntry === null || hideDataEntry === void 0 ? void 0 : hideDataEntry.required) === true || ((hideDataEntry === null || hideDataEntry === void 0 ? void 0 : hideDataEntry.required) === undefined && isRequired)) {
|
|
3067
|
-
showRequiredLabel = true;
|
|
3068
|
-
}
|
|
3069
|
-
if (schema === null || schema === void 0 ? void 0 : schema.$ref) {
|
|
3070
|
-
schema = dereference(schema, root);
|
|
3071
|
-
}
|
|
3072
|
-
return (React__default.createElement("div", { className: "mb-1" },
|
|
3073
|
-
React__default.createElement(Flex, { maxW: "full", pl: 3, py: 2, "data-test": "schema-row", pos: "relative" },
|
|
3074
|
-
React__default.createElement(VStack, { spacing: 1, maxW: "full", className: "w-full" },
|
|
3075
|
-
React__default.createElement(Flex, { onClick: !isRoot ? handleToggle : undefined, className: `w-full ${isRoot ? '' : 'cursor-pointer'}` },
|
|
3076
|
-
!isRoot ? (React__default.createElement(Box, { mr: 2, className: "sl-font-mono sl-font-semibold sl-mr-2" },
|
|
3077
|
-
hasExpandableChildren &&
|
|
3078
|
-
!TYPES.includes(schema === null || schema === void 0 ? void 0 : schema.type) &&
|
|
3079
|
-
!detectCircularPath(path) &&
|
|
3080
|
-
!((_b = schema === null || schema === void 0 ? void 0 : schema.items) === null || _b === void 0 ? void 0 : _b.circular) &&
|
|
3081
|
-
!(schema === null || schema === void 0 ? void 0 : schema.circular) ? (React__default.createElement("i", { role: "img", "aria-hidden": "true", className: `sl-icon fal ${expanded ? 'fa-chevron-down' : 'fa-chevron-right'} fa-fw fa-sm` })) : (React__default.createElement("span", { className: "sl-icon fal fa-fw fa-sm", "aria-hidden": "true" })),
|
|
3082
|
-
' ' + displayTitle)) : null,
|
|
3083
|
-
!isRoot ? (React__default.createElement(Box, { mr: 2, pos: "relative" },
|
|
3084
|
-
React__default.createElement(Box, { display: "inline-flex", alignItems: "center", onMouseEnter: () => {
|
|
3085
|
-
if ((schema === null || schema === void 0 ? void 0 : schema.anyOf) || (schema === null || schema === void 0 ? void 0 : schema.oneOf)) {
|
|
3086
|
-
setIsHoveringSelector(true);
|
|
3087
|
-
}
|
|
3088
|
-
}, onMouseLeave: () => {
|
|
3089
|
-
if (!showSchemaDropdown) {
|
|
3090
|
-
setIsHoveringSelector(false);
|
|
3091
|
-
}
|
|
3092
|
-
}, onClick: (e) => {
|
|
3093
|
-
if ((schema === null || schema === void 0 ? void 0 : schema.anyOf) || (schema === null || schema === void 0 ? void 0 : schema.oneOf)) {
|
|
3094
|
-
e.stopPropagation();
|
|
3095
|
-
setShowSchemaDropdown(prev => !prev);
|
|
3096
|
-
}
|
|
3097
|
-
}, style: {
|
|
3098
|
-
cursor: (schema === null || schema === void 0 ? void 0 : schema.anyOf) || (schema === null || schema === void 0 ? void 0 : schema.oneOf) ? 'pointer' : 'default',
|
|
3099
|
-
} },
|
|
3100
|
-
React__default.createElement("span", { className: "sl-truncate sl-text-muted" },
|
|
3101
|
-
(() => {
|
|
3102
|
-
let typeDisplay = (schema === null || schema === void 0 ? void 0 : schema.type) === 'object' && (schema === null || schema === void 0 ? void 0 : schema.title) ? schema === null || schema === void 0 ? void 0 : schema.title : (schema === null || schema === void 0 ? void 0 : schema.type) || (root === null || root === void 0 ? void 0 : root.title);
|
|
3103
|
-
if ((schema === null || schema === void 0 ? void 0 : schema.anyOf) && (schema === null || schema === void 0 ? void 0 : schema.anyOf.length) > 0) {
|
|
3104
|
-
return `any of ${typeDisplay}`;
|
|
3105
|
-
}
|
|
3106
|
-
else if ((schema === null || schema === void 0 ? void 0 : schema.oneOf) && (schema === null || schema === void 0 ? void 0 : schema.oneOf.length) > 0) {
|
|
3107
|
-
return `one of ${typeDisplay}`;
|
|
3108
|
-
}
|
|
3109
|
-
return typeDisplay;
|
|
3110
|
-
})(),
|
|
3111
|
-
(schema === null || schema === void 0 ? void 0 : schema.items) && ((_c = schema === null || schema === void 0 ? void 0 : schema.items) === null || _c === void 0 ? void 0 : _c.title) !== undefined ? ` [${(_d = schema === null || schema === void 0 ? void 0 : schema.items) === null || _d === void 0 ? void 0 : _d.title}] ` : null),
|
|
3112
|
-
((schema === null || schema === void 0 ? void 0 : schema.anyOf) || (schema === null || schema === void 0 ? void 0 : schema.oneOf)) && (React__default.createElement(Box, { display: "inline-flex", alignItems: "center", ml: 1, style: {
|
|
3113
|
-
opacity: isHoveringSelector ? 1 : 0.6,
|
|
3114
|
-
transition: 'opacity 0.2s',
|
|
3115
|
-
} },
|
|
3116
|
-
React__default.createElement("i", { className: "sl-icon fas fa-chevron-down", style: {
|
|
3117
|
-
fontSize: '10px',
|
|
3118
|
-
opacity: 0.6,
|
|
3119
|
-
} })))),
|
|
3120
|
-
React__default.createElement("span", { className: "text-gray-500" }, (schema === null || schema === void 0 ? void 0 : schema.format) !== undefined ? `<${schema === null || schema === void 0 ? void 0 : schema.format}>` : null),
|
|
3121
|
-
((schema === null || schema === void 0 ? void 0 : schema.anyOf) || (schema === null || schema === void 0 ? void 0 : schema.oneOf)) && showSchemaDropdown && combinedSchemaSelector())) : null),
|
|
3122
|
-
React__default.createElement(Flex, { pl: 1, w: "full", align: "start", direction: "col", style: { overflow: 'visible', paddingLeft: '20px' } },
|
|
3123
|
-
(schema === null || schema === void 0 ? void 0 : schema.description) && (React__default.createElement(Box, { fontFamily: "ui", fontWeight: "light" },
|
|
3124
|
-
React__default.createElement("span", { className: "sl-prose sl-markdown-viewer", style: { fontSize: '12px' } }, schema === null || schema === void 0 ? void 0 : schema.description))),
|
|
3125
|
-
!isRoot && (schema === null || schema === void 0 ? void 0 : schema.examples) !== undefined && (React__default.createElement(Flex, { align: "center", mb: 1, style: { flexWrap: 'wrap' } },
|
|
3126
|
-
React__default.createElement("span", { className: "text-gray-500", style: { marginRight: 8, flexShrink: 0 } }, "Example"),
|
|
3127
|
-
React__default.createElement(Box, { className: "sl-text-muted", fontFamily: "ui", fontWeight: "normal", mr: 2, style: {
|
|
3128
|
-
background: 'rgba(245, 247, 250, 0.5)',
|
|
3129
|
-
border: '1px solid #a0aec0',
|
|
3130
|
-
borderRadius: '4px',
|
|
3131
|
-
padding: '4px 8px',
|
|
3132
|
-
display: 'inline-block',
|
|
3133
|
-
overflowWrap: 'break-word',
|
|
3134
|
-
textAlign: 'left',
|
|
3135
|
-
maxWidth: '530px',
|
|
3136
|
-
} }, JSON.stringify(schema === null || schema === void 0 ? void 0 : schema.examples))))),
|
|
3137
|
-
React__default.createElement(Flex, { pl: 1, w: "full", align: "start", direction: "col", style: { overflow: 'visible', paddingLeft: '20px' } }, schema &&
|
|
3138
|
-
typeof schema === 'object' &&
|
|
3139
|
-
('minItems' in schema || 'enum' in schema) &&
|
|
3140
|
-
renderMinEnums(schema))),
|
|
3141
|
-
!isRoot && (React__default.createElement("label", { className: "inline-flex items-top ml-2" },
|
|
3142
|
-
React__default.createElement(Box, { mr: 2, fontFamily: "ui", fontWeight: "normal" }, showRequiredLabel && (React__default.createElement("div", { className: "sl-ml-2 sl-text-warning" },
|
|
3143
|
-
React__default.createElement("span", { style: { marginLeft: '10px' } }, "required"))))))),
|
|
3144
|
-
renderChildren()));
|
|
3145
|
-
};
|
|
3146
|
-
|
|
3147
2799
|
const isBodyEmpty = (body) => {
|
|
3148
2800
|
if (!body)
|
|
3149
2801
|
return true;
|
|
3150
2802
|
const { contents = [], description } = body;
|
|
3151
2803
|
return contents.length === 0 && !(description === null || description === void 0 ? void 0 : description.trim());
|
|
3152
2804
|
};
|
|
3153
|
-
const Body = ({ body, onChange, isHttpWebhookOperation = false
|
|
2805
|
+
const Body = ({ body, onChange, isHttpWebhookOperation = false }) => {
|
|
3154
2806
|
var _a;
|
|
3155
2807
|
const [refResolver, maxRefDepth] = useSchemaInlineRefResolver();
|
|
3156
2808
|
const [chosenContent, setChosenContent] = React.useState(0);
|
|
@@ -3163,36 +2815,13 @@ const Body = ({ body, onChange, isHttpWebhookOperation = false, disableProps })
|
|
|
3163
2815
|
const { contents = [], description } = body;
|
|
3164
2816
|
const schema = (_a = contents[chosenContent]) === null || _a === void 0 ? void 0 : _a.schema;
|
|
3165
2817
|
const descriptionChanged = nodeHasChanged === null || nodeHasChanged === void 0 ? void 0 : nodeHasChanged({ nodeId: body.id, attr: 'description' });
|
|
3166
|
-
const getMaskProperties = () => {
|
|
3167
|
-
const disablePropsConfig = disableProps || [];
|
|
3168
|
-
const absolutePathsToHide = [];
|
|
3169
|
-
disablePropsConfig.forEach(configEntry => {
|
|
3170
|
-
const { location, paths, isComplex } = configEntry;
|
|
3171
|
-
if (paths.length === 0 && !isComplex) {
|
|
3172
|
-
absolutePathsToHide.push({ path: location });
|
|
3173
|
-
}
|
|
3174
|
-
else {
|
|
3175
|
-
paths.forEach((item) => {
|
|
3176
|
-
const fullPath = location === '#' ? item === null || item === void 0 ? void 0 : item.path : `${location}/${item.path}`;
|
|
3177
|
-
let object = { path: fullPath };
|
|
3178
|
-
if (item.hasOwnProperty('required')) {
|
|
3179
|
-
object = Object.assign(Object.assign({}, object), { required: item === null || item === void 0 ? void 0 : item.required });
|
|
3180
|
-
}
|
|
3181
|
-
absolutePathsToHide.push(object);
|
|
3182
|
-
});
|
|
3183
|
-
}
|
|
3184
|
-
});
|
|
3185
|
-
return absolutePathsToHide;
|
|
3186
|
-
};
|
|
3187
|
-
const shouldUseLazySchema = disableProps === null || disableProps === void 0 ? void 0 : disableProps.some(entry => entry.isComplex === true);
|
|
3188
|
-
console.log('!!!!! shouldUseLazySchema body!!!!', shouldUseLazySchema);
|
|
3189
2818
|
return (React.createElement(VStack, { spacing: 6 },
|
|
3190
2819
|
React.createElement(SectionSubtitle, { title: "Body", id: "request-body" }, contents.length > 0 && (React.createElement(Flex, { flex: 1, justify: "end" },
|
|
3191
2820
|
React.createElement(Select, { "aria-label": "Request Body Content Type", value: String(chosenContent), onChange: value => setChosenContent(parseInt(String(value), 10)), options: contents.map((content, index) => ({ label: content.mediaType, value: index })), size: "sm" })))),
|
|
3192
2821
|
description && (React.createElement(Box, { pos: "relative" },
|
|
3193
2822
|
React.createElement(MarkdownViewer, { markdown: description }),
|
|
3194
2823
|
React.createElement(NodeAnnotation, { change: descriptionChanged }))),
|
|
3195
|
-
|
|
2824
|
+
isJSONSchema(schema) && (React.createElement(JsonSchemaViewer, { resolveRef: refResolver, maxRefDepth: maxRefDepth, schema: getOriginalObject(schema), viewMode: isHttpWebhookOperation ? 'standalone' : 'write', renderRootTreeLines: true, nodeHasChanged: nodeHasChanged, renderExtensionAddon: renderExtensionAddon }))));
|
|
3196
2825
|
};
|
|
3197
2826
|
Body.displayName = 'HttpOperation.Body';
|
|
3198
2827
|
|
|
@@ -3259,7 +2888,7 @@ const httpOperationParamsToSchema = ({ parameters, parameterType }) => {
|
|
|
3259
2888
|
return schema;
|
|
3260
2889
|
};
|
|
3261
2890
|
|
|
3262
|
-
const Request = ({ operation: { request, request: { path: pathParams = [], headers: headerParams = [], cookie: cookieParams = [], body, query: queryParams = [], } = {}, security, }, hideSecurityInfo, onChange, isHttpWebhookOperation = false,
|
|
2891
|
+
const Request = ({ operation: { request, request: { path: pathParams = [], headers: headerParams = [], cookie: cookieParams = [], body, query: queryParams = [], } = {}, security, }, hideSecurityInfo, onChange, isHttpWebhookOperation = false, }) => {
|
|
3263
2892
|
if (!request || typeof request !== 'object')
|
|
3264
2893
|
return null;
|
|
3265
2894
|
const bodyIsEmpty = isBodyEmpty(body);
|
|
@@ -3287,7 +2916,7 @@ const Request = ({ operation: { request, request: { path: pathParams = [], heade
|
|
|
3287
2916
|
cookieParams.length > 0 && (React.createElement(VStack, { spacing: 5 },
|
|
3288
2917
|
React.createElement(SectionSubtitle, { title: "Cookies", id: "request-cookies" }),
|
|
3289
2918
|
React.createElement(Parameters, { parameterType: "cookie", parameters: cookieParams }))),
|
|
3290
|
-
body &&
|
|
2919
|
+
body && React.createElement(Body, { onChange: onChange, body: body, isHttpWebhookOperation: isHttpWebhookOperation })));
|
|
3291
2920
|
};
|
|
3292
2921
|
Request.displayName = 'HttpOperation.Request';
|
|
3293
2922
|
const schemeExpandedState = atomWithStorage('HttpOperation_security_expanded', {});
|
|
@@ -3318,7 +2947,7 @@ const OptionalMessage$1 = () => {
|
|
|
3318
2947
|
return React.createElement(Callout, { appearance: "outline" }, OptionalSecurityMessage);
|
|
3319
2948
|
};
|
|
3320
2949
|
|
|
3321
|
-
const Responses = ({ responses: unsortedResponses, onStatusCodeChange, onMediaTypeChange, isCompact,
|
|
2950
|
+
const Responses = ({ responses: unsortedResponses, onStatusCodeChange, onMediaTypeChange, isCompact, }) => {
|
|
3322
2951
|
var _a, _b;
|
|
3323
2952
|
const responses = sortBy(uniqBy(unsortedResponses, r => r.code), r => r.code);
|
|
3324
2953
|
const [activeResponseId, setActiveResponseId] = React.useState((_b = (_a = responses[0]) === null || _a === void 0 ? void 0 : _a.code) !== null && _b !== void 0 ? _b : '');
|
|
@@ -3351,12 +2980,11 @@ const Responses = ({ responses: unsortedResponses, onStatusCodeChange, onMediaTy
|
|
|
3351
2980
|
const tabResponses = (React.createElement(TabList, { density: "compact" }, responses.map(({ code }) => (React.createElement(Tab, { key: code, id: code, intent: codeToIntentVal(code) }, code)))));
|
|
3352
2981
|
return (React.createElement(VStack, { spacing: 8, as: Tabs, selectedId: activeResponseId, onChange: setActiveResponseId, appearance: "pill" },
|
|
3353
2982
|
React.createElement(SectionTitle, { title: "Responses", isCompact: isCompact }, isCompact ? compactResponses : tabResponses),
|
|
3354
|
-
isCompact ? (React.createElement(Response, { response: response, onMediaTypeChange: onMediaTypeChange
|
|
3355
|
-
React.createElement(Response, { response: response, onMediaTypeChange: onMediaTypeChange
|
|
2983
|
+
isCompact ? (React.createElement(Response, { response: response, onMediaTypeChange: onMediaTypeChange })) : (React.createElement(TabPanels, { p: 0 }, responses.map(response => (React.createElement(TabPanel, { key: response.code, id: response.code },
|
|
2984
|
+
React.createElement(Response, { response: response, onMediaTypeChange: onMediaTypeChange }))))))));
|
|
3356
2985
|
};
|
|
3357
2986
|
Responses.displayName = 'HttpOperation.Responses';
|
|
3358
|
-
const Response = ({ response, onMediaTypeChange
|
|
3359
|
-
var _a, _b;
|
|
2987
|
+
const Response = ({ response, onMediaTypeChange }) => {
|
|
3360
2988
|
const { contents = [], headers = [], description } = response;
|
|
3361
2989
|
const [chosenContent, setChosenContent] = React.useState(0);
|
|
3362
2990
|
const [refResolver, maxRefDepth] = useSchemaInlineRefResolver();
|
|
@@ -3367,29 +2995,6 @@ const Response = ({ response, onMediaTypeChange, disableProps, statusCode }) =>
|
|
|
3367
2995
|
responseContent && (onMediaTypeChange === null || onMediaTypeChange === void 0 ? void 0 : onMediaTypeChange(responseContent.mediaType));
|
|
3368
2996
|
}, [responseContent]);
|
|
3369
2997
|
const descriptionChanged = nodeHasChanged === null || nodeHasChanged === void 0 ? void 0 : nodeHasChanged({ nodeId: response.id, attr: 'description' });
|
|
3370
|
-
const getMaskProperties = () => {
|
|
3371
|
-
if (!disableProps || !statusCode)
|
|
3372
|
-
return [];
|
|
3373
|
-
const configEntries = disableProps[statusCode] || [];
|
|
3374
|
-
const absolutePathsToHide = [];
|
|
3375
|
-
configEntries.forEach(({ location, paths, isComplex }) => {
|
|
3376
|
-
if (paths.length === 0 && !isComplex) {
|
|
3377
|
-
absolutePathsToHide.push({ path: location });
|
|
3378
|
-
}
|
|
3379
|
-
else {
|
|
3380
|
-
paths.forEach((item) => {
|
|
3381
|
-
const fullPath = location === '#' ? item === null || item === void 0 ? void 0 : item.path : `${location}/${item.path}`;
|
|
3382
|
-
let object = { path: fullPath };
|
|
3383
|
-
if (item.hasOwnProperty('required')) {
|
|
3384
|
-
object = Object.assign(Object.assign({}, object), { required: item === null || item === void 0 ? void 0 : item.required });
|
|
3385
|
-
}
|
|
3386
|
-
absolutePathsToHide.push(object);
|
|
3387
|
-
});
|
|
3388
|
-
}
|
|
3389
|
-
});
|
|
3390
|
-
return absolutePathsToHide;
|
|
3391
|
-
};
|
|
3392
|
-
const shouldUseLazySchema = (_b = (statusCode && ((_a = disableProps === null || disableProps === void 0 ? void 0 : disableProps[statusCode]) === null || _a === void 0 ? void 0 : _a.some(entry => entry.isComplex)))) !== null && _b !== void 0 ? _b : false;
|
|
3393
2998
|
return (React.createElement(VStack, { spacing: 8, pt: 8 },
|
|
3394
2999
|
description && (React.createElement(Box, { pos: "relative" },
|
|
3395
3000
|
React.createElement(MarkdownViewer, { markdown: description }),
|
|
@@ -3401,7 +3006,7 @@ const Response = ({ response, onMediaTypeChange, disableProps, statusCode }) =>
|
|
|
3401
3006
|
React.createElement(SectionSubtitle, { title: "Body", id: "response-body" },
|
|
3402
3007
|
React.createElement(Flex, { flex: 1, justify: "end" },
|
|
3403
3008
|
React.createElement(Select, { "aria-label": "Response Body Content Type", value: String(chosenContent), onChange: value => setChosenContent(parseInt(String(value), 10)), options: contents.map((content, index) => ({ label: content.mediaType, value: index })), size: "sm" }))),
|
|
3404
|
-
schema &&
|
|
3009
|
+
schema && (React.createElement(JsonSchemaViewer, { schema: getOriginalObject(schema), resolveRef: refResolver, maxRefDepth: maxRefDepth, viewMode: "read", parentCrumbs: ['responses', response.code], renderRootTreeLines: true, nodeHasChanged: nodeHasChanged, renderExtensionAddon: renderExtensionAddon }))))));
|
|
3405
3010
|
};
|
|
3406
3011
|
Response.displayName = 'HttpOperation.Response';
|
|
3407
3012
|
const codeToIntentVal = (code) => {
|
|
@@ -3450,7 +3055,7 @@ const Callback = ({ data, isCompact }) => {
|
|
|
3450
3055
|
};
|
|
3451
3056
|
Callbacks.displayName = 'HttpOperation.Callback';
|
|
3452
3057
|
|
|
3453
|
-
const HttpOperationComponent = React.memo(({ className, data: unresolvedData, layoutOptions, tryItCredentialsPolicy, tryItCorsProxy
|
|
3058
|
+
const HttpOperationComponent = React.memo(({ className, data: unresolvedData, layoutOptions, tryItCredentialsPolicy, tryItCorsProxy }) => {
|
|
3454
3059
|
var _a;
|
|
3455
3060
|
const { nodeHasChanged } = useOptionsCtx();
|
|
3456
3061
|
const data = useResolvedObject(unresolvedData);
|
|
@@ -3481,11 +3086,11 @@ const HttpOperationComponent = React.memo(({ className, data: unresolvedData, la
|
|
|
3481
3086
|
React.createElement(MarkdownViewer, { className: "HttpOperation__Description", markdown: data.description }),
|
|
3482
3087
|
React.createElement(NodeAnnotation, { change: descriptionChanged }))),
|
|
3483
3088
|
React.createElement(NodeVendorExtensions, { data: data }),
|
|
3484
|
-
React.createElement(Request, { onChange: setTextRequestBodyIndex, operation: data, hideSecurityInfo: layoutOptions === null || layoutOptions === void 0 ? void 0 : layoutOptions.hideSecurityInfo, isHttpWebhookOperation: isHttpWebhookOperation(data)
|
|
3485
|
-
data.responses && (React.createElement(Responses, { responses: data.responses, onMediaTypeChange: setResponseMediaType, onStatusCodeChange: setResponseStatusCode, isCompact: isCompact
|
|
3089
|
+
React.createElement(Request, { onChange: setTextRequestBodyIndex, operation: data, hideSecurityInfo: layoutOptions === null || layoutOptions === void 0 ? void 0 : layoutOptions.hideSecurityInfo, isHttpWebhookOperation: isHttpWebhookOperation(data) }),
|
|
3090
|
+
data.responses && (React.createElement(Responses, { responses: data.responses, onMediaTypeChange: setResponseMediaType, onStatusCodeChange: setResponseStatusCode, isCompact: isCompact })),
|
|
3486
3091
|
((_a = data.callbacks) === null || _a === void 0 ? void 0 : _a.length) ? React.createElement(Callbacks, { callbacks: data.callbacks, isCompact: isCompact }) : null,
|
|
3487
3092
|
isCompact && tryItPanel));
|
|
3488
|
-
return (React.createElement(TwoColumnLayout, { ref: layoutRef, className: cn('HttpOperation', className), header: header, left: description, right: !
|
|
3093
|
+
return (React.createElement(TwoColumnLayout, { ref: layoutRef, className: cn('HttpOperation', className), header: header, left: description, right: !isCompact && tryItPanel }));
|
|
3489
3094
|
});
|
|
3490
3095
|
HttpOperationComponent.displayName = 'HttpOperation.Component';
|
|
3491
3096
|
const HttpOperation = withErrorBoundary(HttpOperationComponent, {
|
|
@@ -3736,7 +3341,7 @@ const HttpServiceComponent = React.memo(({ data: unresolvedData, location = {},
|
|
|
3736
3341
|
HttpServiceComponent.displayName = 'HttpService.Component';
|
|
3737
3342
|
const HttpService = withErrorBoundary(HttpServiceComponent, { recoverableProps: ['data'] });
|
|
3738
3343
|
|
|
3739
|
-
const ModelComponent = ({ data: unresolvedData, className, nodeTitle, layoutOptions, exportProps,
|
|
3344
|
+
const ModelComponent = ({ data: unresolvedData, className, nodeTitle, layoutOptions, exportProps, }) => {
|
|
3740
3345
|
var _a, _b;
|
|
3741
3346
|
const [resolveRef, maxRefDepth] = useSchemaInlineRefResolver();
|
|
3742
3347
|
const data = useResolvedObject(unresolvedData);
|
|
@@ -3759,40 +3364,14 @@ const ModelComponent = ({ data: unresolvedData, className, nodeTitle, layoutOpti
|
|
|
3759
3364
|
exportProps && !(layoutOptions === null || layoutOptions === void 0 ? void 0 : layoutOptions.hideExport) && !isCompact && React.createElement(ExportButton, Object.assign({}, exportProps))));
|
|
3760
3365
|
const modelExamples = !(layoutOptions === null || layoutOptions === void 0 ? void 0 : layoutOptions.hideModelExamples) && React.createElement(ModelExamples, { data: data, isCollapsible: isCompact });
|
|
3761
3366
|
const descriptionChanged = nodeHasChanged === null || nodeHasChanged === void 0 ? void 0 : nodeHasChanged({ nodeId, attr: 'description' });
|
|
3762
|
-
const getMaskProperties = () => {
|
|
3763
|
-
const disablePropsConfig = disableProps === null || disableProps === void 0 ? void 0 : disableProps.models;
|
|
3764
|
-
const absolutePathsToHide = [];
|
|
3765
|
-
if (disableProps === null || disableProps === void 0 ? void 0 : disableProps.models) {
|
|
3766
|
-
disablePropsConfig.forEach((configEntry) => {
|
|
3767
|
-
const { location, paths, isComplex } = configEntry;
|
|
3768
|
-
if (paths.length === 0 && !isComplex) {
|
|
3769
|
-
absolutePathsToHide.push({ path: location });
|
|
3770
|
-
}
|
|
3771
|
-
else {
|
|
3772
|
-
paths.forEach((item) => {
|
|
3773
|
-
const fullPath = location === '#' ? item === null || item === void 0 ? void 0 : item.path : `${location}/${item.path}`;
|
|
3774
|
-
let object = { path: fullPath };
|
|
3775
|
-
if (item.hasOwnProperty('required')) {
|
|
3776
|
-
object = Object.assign(Object.assign({}, object), { required: item === null || item === void 0 ? void 0 : item.required });
|
|
3777
|
-
}
|
|
3778
|
-
absolutePathsToHide.push(object);
|
|
3779
|
-
});
|
|
3780
|
-
}
|
|
3781
|
-
});
|
|
3782
|
-
}
|
|
3783
|
-
return absolutePathsToHide;
|
|
3784
|
-
};
|
|
3785
|
-
const shouldUseLazySchema = disableProps && (disableProps === null || disableProps === void 0 ? void 0 : disableProps.models)
|
|
3786
|
-
? disableProps.models.some((entry) => entry.isComplex === true)
|
|
3787
|
-
: false;
|
|
3788
3367
|
const description = (React.createElement(VStack, { spacing: 10 },
|
|
3789
3368
|
data.description && data.type === 'object' && (React.createElement(Box, { pos: "relative" },
|
|
3790
3369
|
React.createElement(MarkdownViewer, { role: "textbox", markdown: data.description }),
|
|
3791
3370
|
React.createElement(NodeAnnotation, { change: descriptionChanged }))),
|
|
3792
3371
|
React.createElement(NodeVendorExtensions, { data: data }),
|
|
3793
|
-
|
|
3794
|
-
|
|
3795
|
-
return (React.createElement(TwoColumnLayout, { ref: layoutRef, className: cn('Model', className), header: header, left: description, right: !
|
|
3372
|
+
isCompact && modelExamples,
|
|
3373
|
+
React.createElement(JsonSchemaViewer, { resolveRef: resolveRef, maxRefDepth: maxRefDepth, schema: getOriginalObject(data), nodeHasChanged: nodeHasChanged, renderExtensionAddon: renderExtensionAddon, skipTopLevelDescription: true })));
|
|
3374
|
+
return (React.createElement(TwoColumnLayout, { ref: layoutRef, className: cn('Model', className), header: header, left: description, right: !isCompact && modelExamples }));
|
|
3796
3375
|
};
|
|
3797
3376
|
const ModelExamples = React.memo(({ data, isCollapsible = false }) => {
|
|
3798
3377
|
var _a;
|
|
@@ -3814,41 +3393,30 @@ const Model = withErrorBoundary(ModelComponent, { recoverableProps: ['data'] });
|
|
|
3814
3393
|
|
|
3815
3394
|
const Docs = React.memo((_a) => {
|
|
3816
3395
|
var _b;
|
|
3817
|
-
var { nodeType, nodeData,
|
|
3396
|
+
var { nodeType, nodeData, useNodeForRefResolving = false, refResolver, maxRefDepth, nodeHasChanged, renderExtensionAddon } = _a, commonProps = __rest(_a, ["nodeType", "nodeData", "useNodeForRefResolving", "refResolver", "maxRefDepth", "nodeHasChanged", "renderExtensionAddon"]);
|
|
3818
3397
|
const parsedNode = useParsedData(nodeType, nodeData);
|
|
3819
3398
|
if (!parsedNode) {
|
|
3820
3399
|
(_b = commonProps.nodeUnsupported) === null || _b === void 0 ? void 0 : _b.call(commonProps, 'dataEmpty');
|
|
3821
3400
|
return null;
|
|
3822
3401
|
}
|
|
3823
|
-
let elem = React.createElement(ParsedDocs, Object.assign({ node: parsedNode
|
|
3402
|
+
let elem = React.createElement(ParsedDocs, Object.assign({ node: parsedNode }, commonProps));
|
|
3824
3403
|
if (useNodeForRefResolving) {
|
|
3825
3404
|
elem = (React.createElement(InlineRefResolverProvider, { document: parsedNode.data, resolver: refResolver, maxRefDepth: maxRefDepth }, elem));
|
|
3826
3405
|
}
|
|
3827
3406
|
return (React.createElement(ElementsOptionsProvider, { nodeHasChanged: nodeHasChanged, renderExtensionAddon: renderExtensionAddon }, elem));
|
|
3828
3407
|
});
|
|
3829
|
-
const getTryItVisibility = (disableProps) => {
|
|
3830
|
-
var _a, _b, _c, _d;
|
|
3831
|
-
if (!disableProps)
|
|
3832
|
-
return { hideOperationTryIt: false, hideModelTryIt: false };
|
|
3833
|
-
const requestHasComplex = (_b = (_a = disableProps.request) === null || _a === void 0 ? void 0 : _a.some(item => item.isComplex)) !== null && _b !== void 0 ? _b : false;
|
|
3834
|
-
const responseHasComplex = Object.values(disableProps.response || {}).some(arr => arr.some(item => item.isComplex));
|
|
3835
|
-
const hideOperationTryIt = requestHasComplex || responseHasComplex;
|
|
3836
|
-
const hideModelTryIt = (_d = (_c = disableProps.models) === null || _c === void 0 ? void 0 : _c.some(item => item.isComplex)) !== null && _d !== void 0 ? _d : false;
|
|
3837
|
-
return { hideOperationTryIt, hideModelTryIt };
|
|
3838
|
-
};
|
|
3839
3408
|
const ParsedDocs = (_a) => {
|
|
3840
|
-
var { node, nodeUnsupported
|
|
3841
|
-
const { hideOperationTryIt, hideModelTryIt } = getTryItVisibility(disableProps);
|
|
3409
|
+
var { node, nodeUnsupported } = _a, commonProps = __rest(_a, ["node", "nodeUnsupported"]);
|
|
3842
3410
|
switch (node.type) {
|
|
3843
3411
|
case 'article':
|
|
3844
3412
|
return React.createElement(Article, Object.assign({ data: node.data }, commonProps));
|
|
3845
3413
|
case 'http_operation':
|
|
3846
3414
|
case 'http_webhook':
|
|
3847
|
-
return React.createElement(HttpOperation, Object.assign({ data: node.data
|
|
3415
|
+
return React.createElement(HttpOperation, Object.assign({ data: node.data }, commonProps));
|
|
3848
3416
|
case 'http_service':
|
|
3849
3417
|
return React.createElement(HttpService, Object.assign({ data: node.data }, commonProps));
|
|
3850
3418
|
case 'model':
|
|
3851
|
-
return React.createElement(Model, Object.assign({ data: node.data
|
|
3419
|
+
return React.createElement(Model, Object.assign({ data: node.data }, commonProps));
|
|
3852
3420
|
default:
|
|
3853
3421
|
nodeUnsupported === null || nodeUnsupported === void 0 ? void 0 : nodeUnsupported('invalidType');
|
|
3854
3422
|
return null;
|
|
@@ -3986,7 +3554,7 @@ function findFirstNode(items) {
|
|
|
3986
3554
|
return;
|
|
3987
3555
|
}
|
|
3988
3556
|
function isDivider(item) {
|
|
3989
|
-
return Object.keys(item).length ===
|
|
3557
|
+
return Object.keys(item).length === 2 && 'title' in item && 'index' in item;
|
|
3990
3558
|
}
|
|
3991
3559
|
function isGroup(item) {
|
|
3992
3560
|
return Object.keys(item).length >= 2 && 'title' in item && 'items' in item;
|
|
@@ -3998,13 +3566,33 @@ function isNode(item) {
|
|
|
3998
3566
|
return 'title' in item && 'slug' in item && 'id' in item && 'meta' in item && 'type' in item;
|
|
3999
3567
|
}
|
|
4000
3568
|
function isExternalLink(item) {
|
|
4001
|
-
return Object.keys(item).length ===
|
|
3569
|
+
return Object.keys(item).length === 3 && 'title' in item && 'url' in item && 'index' in item;
|
|
4002
3570
|
}
|
|
4003
3571
|
|
|
4004
|
-
const
|
|
3572
|
+
const ActiveItemContext = React.createContext({
|
|
3573
|
+
activeId: undefined,
|
|
3574
|
+
lastActiveIndex: '',
|
|
3575
|
+
setLastActiveIndex: () => { },
|
|
3576
|
+
});
|
|
4005
3577
|
const LinkContext = React.createContext(undefined);
|
|
4006
3578
|
LinkContext.displayName = 'LinkContext';
|
|
4007
3579
|
const TableOfContents = React.memo(({ tree, activeId, Link, maxDepthOpenByDefault, externalScrollbar = false, isInResponsiveMode = false, onLinkClick, }) => {
|
|
3580
|
+
const [lastActiveIndex, setLastActiveIndex] = useState('');
|
|
3581
|
+
const value = React.useMemo(() => ({
|
|
3582
|
+
lastActiveIndex,
|
|
3583
|
+
setLastActiveIndex,
|
|
3584
|
+
activeId,
|
|
3585
|
+
}), [lastActiveIndex, activeId]);
|
|
3586
|
+
const updateTocTree = React.useCallback((arr, parentId) => {
|
|
3587
|
+
return arr.map((item, key) => {
|
|
3588
|
+
let newItem = Object.assign(Object.assign({}, item), { index: parentId + key + '-' });
|
|
3589
|
+
if (isGroup(item) || isNodeGroup(item)) {
|
|
3590
|
+
newItem.items = updateTocTree(item.items, parentId + key + '-');
|
|
3591
|
+
}
|
|
3592
|
+
return newItem;
|
|
3593
|
+
});
|
|
3594
|
+
}, []);
|
|
3595
|
+
const updatedTree = updateTocTree(tree, '');
|
|
4008
3596
|
const container = React.useRef(null);
|
|
4009
3597
|
const child = React.useRef(null);
|
|
4010
3598
|
const firstRender = useFirstRender();
|
|
@@ -4024,18 +3612,30 @@ const TableOfContents = React.memo(({ tree, activeId, Link, maxDepthOpenByDefaul
|
|
|
4024
3612
|
return (React.createElement(Box, { ref: container, w: "full", bg: isInResponsiveMode ? 'canvas' : 'canvas-100', overflowY: "auto" },
|
|
4025
3613
|
React.createElement(Box, { ref: child, my: 3 },
|
|
4026
3614
|
React.createElement(LinkContext.Provider, { value: Link },
|
|
4027
|
-
React.createElement(
|
|
4028
|
-
|
|
4029
|
-
|
|
4030
|
-
|
|
4031
|
-
|
|
4032
|
-
|
|
3615
|
+
React.createElement(ActiveItemContext.Provider, { value: value },
|
|
3616
|
+
React.createElement(TOCContainer, { updatedTree: updatedTree }, updatedTree.map((item, key) => {
|
|
3617
|
+
if (isDivider(item)) {
|
|
3618
|
+
return React.createElement(Divider, { key: key, item: item, isInResponsiveMode: isInResponsiveMode });
|
|
3619
|
+
}
|
|
3620
|
+
return (React.createElement(GroupItem, { key: key, item: item, depth: 0, maxDepthOpenByDefault: maxDepthOpenByDefault, onLinkClick: onLinkClick, isInResponsiveMode: isInResponsiveMode }));
|
|
3621
|
+
})))))));
|
|
4033
3622
|
});
|
|
4034
3623
|
TableOfContents.displayName = 'TableOfContents';
|
|
4035
3624
|
const Divider = React.memo(({ item, isInResponsiveMode = false }) => {
|
|
4036
3625
|
return (React.createElement(Box, { pl: 4, mb: 2, mt: 6, textTransform: "uppercase", fontSize: isInResponsiveMode ? 'lg' : 'sm', lineHeight: "relaxed", letterSpacing: "wide", fontWeight: "bold" }, item.title));
|
|
4037
3626
|
});
|
|
4038
3627
|
Divider.displayName = 'Divider';
|
|
3628
|
+
const TOCContainer = React.memo(({ children, updatedTree }) => {
|
|
3629
|
+
const { setLastActiveIndex } = React.useContext(ActiveItemContext);
|
|
3630
|
+
React.useEffect(() => {
|
|
3631
|
+
const firstNode = findFirstNode(updatedTree);
|
|
3632
|
+
if (firstNode) {
|
|
3633
|
+
setLastActiveIndex(firstNode.index);
|
|
3634
|
+
}
|
|
3635
|
+
}, []);
|
|
3636
|
+
return React.createElement(Box, null, children);
|
|
3637
|
+
});
|
|
3638
|
+
TOCContainer.displayName = 'TOCContainer';
|
|
4039
3639
|
const GroupItem = React.memo(({ item, depth, maxDepthOpenByDefault, isInResponsiveMode, onLinkClick }) => {
|
|
4040
3640
|
if (isExternalLink(item)) {
|
|
4041
3641
|
return (React.createElement(Box, { as: "a", href: item.url, target: "_blank", rel: "noopener noreferrer", display: "block" },
|
|
@@ -4053,9 +3653,24 @@ const GroupItem = React.memo(({ item, depth, maxDepthOpenByDefault, isInResponsi
|
|
|
4053
3653
|
});
|
|
4054
3654
|
GroupItem.displayName = 'GroupItem';
|
|
4055
3655
|
const Group = React.memo(({ depth, item, maxDepthOpenByDefault, isInResponsiveMode, onLinkClick = () => { } }) => {
|
|
4056
|
-
const activeId = React.useContext(
|
|
3656
|
+
const { activeId, lastActiveIndex } = React.useContext(ActiveItemContext);
|
|
4057
3657
|
const [isOpen, setIsOpen] = React.useState(() => isGroupOpenByDefault(depth, item, activeId, maxDepthOpenByDefault));
|
|
4058
|
-
const
|
|
3658
|
+
const isActiveGroup = React.useCallback((items, activeId, contextIndex) => {
|
|
3659
|
+
return items.some(element => {
|
|
3660
|
+
const hasSlugOrId = 'slug' in element || 'id' in element;
|
|
3661
|
+
const hasItems = 'items' in element && Array.isArray(element.items);
|
|
3662
|
+
if (!hasSlugOrId && !hasItems)
|
|
3663
|
+
return false;
|
|
3664
|
+
if (activeId &&
|
|
3665
|
+
'index' in element &&
|
|
3666
|
+
(element.slug === activeId || element.id === activeId) &&
|
|
3667
|
+
element.index === contextIndex) {
|
|
3668
|
+
return true;
|
|
3669
|
+
}
|
|
3670
|
+
return hasItems ? isActiveGroup(element.items, activeId, contextIndex) : false;
|
|
3671
|
+
});
|
|
3672
|
+
}, []);
|
|
3673
|
+
const hasActive = isActiveGroup(item.items, activeId, lastActiveIndex);
|
|
4059
3674
|
React.useEffect(() => {
|
|
4060
3675
|
const openByDefault = isGroupOpenByDefault(depth, item, activeId, maxDepthOpenByDefault);
|
|
4061
3676
|
if (isOpen !== openByDefault) {
|
|
@@ -4105,8 +3720,10 @@ const Item = React.memo(({ depth, isActive, id, title, meta, icon, isInResponsiv
|
|
|
4105
3720
|
});
|
|
4106
3721
|
Item.displayName = 'Item';
|
|
4107
3722
|
const Node = React.memo(({ item, depth, meta, showAsActive, isInResponsiveMode, onClick, onLinkClick = () => { } }) => {
|
|
4108
|
-
const activeId = React.useContext(
|
|
4109
|
-
const
|
|
3723
|
+
const { activeId, lastActiveIndex, setLastActiveIndex } = React.useContext(ActiveItemContext);
|
|
3724
|
+
const { index } = item;
|
|
3725
|
+
const isSlugMatched = activeId === item.slug || activeId === item.id;
|
|
3726
|
+
const isActive = lastActiveIndex === index && isSlugMatched;
|
|
4110
3727
|
const LinkComponent = React.useContext(LinkContext);
|
|
4111
3728
|
const handleClick = (e) => {
|
|
4112
3729
|
if (isActive) {
|
|
@@ -4114,6 +3731,7 @@ const Node = React.memo(({ item, depth, meta, showAsActive, isInResponsiveMode,
|
|
|
4114
3731
|
e.preventDefault();
|
|
4115
3732
|
}
|
|
4116
3733
|
else {
|
|
3734
|
+
setLastActiveIndex(index);
|
|
4117
3735
|
onLinkClick();
|
|
4118
3736
|
}
|
|
4119
3737
|
if (onClick) {
|
|
@@ -4121,7 +3739,7 @@ const Node = React.memo(({ item, depth, meta, showAsActive, isInResponsiveMode,
|
|
|
4121
3739
|
}
|
|
4122
3740
|
};
|
|
4123
3741
|
return (React.createElement(Box, { as: LinkComponent, to: resolveRelativeLink(item.slug), display: "block", textDecoration: "no-underline", className: "ElementsTableOfContentsItem" },
|
|
4124
|
-
React.createElement(Item, { id: getHtmlIdFromItemId(item.slug || item.id), isActive: isActive || showAsActive, depth: depth, title: item.title, icon: NODE_TYPE_TITLE_ICON[item.type] && (React.createElement(Box, { as: Icon, color: NODE_TYPE_ICON_COLOR[item.type], icon: NODE_TYPE_TITLE_ICON[item.type] })), meta: meta, isInResponsiveMode: isInResponsiveMode, onClick: handleClick })));
|
|
3742
|
+
React.createElement(Item, { id: getHtmlIdFromItemId(item.slug || item.id), isActive: isActive || showAsActive, depth: depth, title: item.title, icon: NODE_TYPE_TITLE_ICON[item.type] && (React.createElement(Box, { as: Icon, color: NODE_TYPE_ICON_COLOR[item.type], icon: NODE_TYPE_TITLE_ICON[item.type] })), meta: meta, isInResponsiveMode: isInResponsiveMode, onClick: e => handleClick(e) })));
|
|
4125
3743
|
});
|
|
4126
3744
|
Node.displayName = 'Node';
|
|
4127
3745
|
const Version = ({ value }) => {
|