@stoplight/elements-core 9.0.12-beta-0.4 → 9.0.13-alpha.0
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 +2 -4
- package/index.esm.js +102 -537
- package/index.js +102 -537
- package/index.mjs +102 -537
- package/package.json +1 -1
- package/components/Docs/HttpOperation/LazySchemaTreePreviewer.d.ts +0 -34
package/index.js
CHANGED
|
@@ -134,8 +134,6 @@ const isResolvedObjectProxy = (someObject) => {
|
|
|
134
134
|
return !!someObject[originalObjectSymbol];
|
|
135
135
|
};
|
|
136
136
|
const getOriginalObject = (resolvedObject) => {
|
|
137
|
-
if (!resolvedObject)
|
|
138
|
-
return resolvedObject;
|
|
139
137
|
const originalObject = resolvedObject[originalObjectSymbol] || resolvedObject;
|
|
140
138
|
if (!originalObject) {
|
|
141
139
|
return resolvedObject;
|
|
@@ -1364,7 +1362,11 @@ const booleanOptions = [
|
|
|
1364
1362
|
{ label: 'True', value: 'true' },
|
|
1365
1363
|
];
|
|
1366
1364
|
function enumOptions(enumValues, required) {
|
|
1367
|
-
const options = map(enumValues, v =>
|
|
1365
|
+
const options = map(enumValues, v => {
|
|
1366
|
+
var _a;
|
|
1367
|
+
const value = typeof v === 'object' && v !== null ? (_a = json.safeStringify(v)) !== null && _a !== void 0 ? _a : String(v) : typeof v === 'number' ? v : String(v);
|
|
1368
|
+
return { value, label: String(value) };
|
|
1369
|
+
});
|
|
1368
1370
|
return required ? options : [{ label: 'Not Set', value: '' }, ...options];
|
|
1369
1371
|
}
|
|
1370
1372
|
function parameterOptions(parameter) {
|
|
@@ -1394,15 +1396,16 @@ function parameterSupportsFileUpload(parameter) {
|
|
|
1394
1396
|
((_c = parameter.schema) === null || _c === void 0 ? void 0 : _c.contentMediaType) === 'application/octet-stream'));
|
|
1395
1397
|
}
|
|
1396
1398
|
function stringifyValue(value) {
|
|
1397
|
-
|
|
1399
|
+
var _a;
|
|
1400
|
+
if (typeof value === 'object' && value !== null) {
|
|
1401
|
+
return (_a = json.safeStringify(value)) !== null && _a !== void 0 ? _a : String(value);
|
|
1402
|
+
}
|
|
1403
|
+
return String(value);
|
|
1398
1404
|
}
|
|
1399
1405
|
function exampleValue(example) {
|
|
1400
1406
|
const value = 'value' in example ? example.value : example.externalValue;
|
|
1401
1407
|
return stringifyValue(value);
|
|
1402
1408
|
}
|
|
1403
|
-
function escapeQuotes(value) {
|
|
1404
|
-
return value.replace(/"/g, '\\"');
|
|
1405
|
-
}
|
|
1406
1409
|
function getPlaceholderForParameter(parameter) {
|
|
1407
1410
|
var _a, _b;
|
|
1408
1411
|
const { value: parameterValue, isDefault } = getValueForParameter(parameter);
|
|
@@ -1428,14 +1431,14 @@ const getValueForParameter = (parameter) => {
|
|
|
1428
1431
|
if (typeof defaultValue !== 'undefined') {
|
|
1429
1432
|
return { value: stringifyValue(defaultValue), isDefault: true };
|
|
1430
1433
|
}
|
|
1431
|
-
const
|
|
1432
|
-
if (examples.length > 0) {
|
|
1433
|
-
return { value: exampleValue(examples[0]) };
|
|
1434
|
-
}
|
|
1435
|
-
const enums = (_c = (_b = parameter.schema) === null || _b === void 0 ? void 0 : _b.enum) !== null && _c !== void 0 ? _c : [];
|
|
1434
|
+
const enums = (_b = (_a = parameter.schema) === null || _a === void 0 ? void 0 : _a.enum) !== null && _b !== void 0 ? _b : [];
|
|
1436
1435
|
if (enums.length > 0) {
|
|
1437
1436
|
return { value: stringifyValue(enums[0]) };
|
|
1438
1437
|
}
|
|
1438
|
+
const examples = (_c = parameter.examples) !== null && _c !== void 0 ? _c : [];
|
|
1439
|
+
if (examples.length > 0) {
|
|
1440
|
+
return { value: exampleValue(examples[0]) };
|
|
1441
|
+
}
|
|
1439
1442
|
return { value: '' };
|
|
1440
1443
|
};
|
|
1441
1444
|
const getInitialValueForParameter = (parameter) => {
|
|
@@ -2353,7 +2356,7 @@ const VariableEditor = ({ variable, value, onChange }) => {
|
|
|
2353
2356
|
return (React__namespace.createElement(React__namespace.Fragment, null,
|
|
2354
2357
|
React__namespace.createElement(mosaic.Text, { as: "label", "aria-hidden": "true", "data-testid": "param-label", htmlFor: inputId, fontSize: "base" }, variable.name),
|
|
2355
2358
|
React__namespace.createElement(mosaic.Text, { mx: 3 }, ":"),
|
|
2356
|
-
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 },
|
|
2359
|
+
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, label: String(s) })), value: value || variable.default, onChange: onChange })) : (React__namespace.createElement(mosaic.Flex, { flex: 1 },
|
|
2357
2360
|
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) }))))));
|
|
2358
2361
|
};
|
|
2359
2362
|
|
|
@@ -2761,417 +2764,13 @@ const PanelContent = ({ schemes }) => {
|
|
|
2761
2764
|
})));
|
|
2762
2765
|
};
|
|
2763
2766
|
|
|
2764
|
-
const TYPES = ['string', 'integer', 'boolean', 'any', 'number'];
|
|
2765
|
-
function resolvePointer(obj, pointer) {
|
|
2766
|
-
const parts = pointer.replace(/^#\//, '').split('/');
|
|
2767
|
-
return parts.reduce((acc, key) => acc && acc[key], obj);
|
|
2768
|
-
}
|
|
2769
|
-
function detectCircularPath(path) {
|
|
2770
|
-
const ignored = ['properties', 'items'];
|
|
2771
|
-
const parts = path.split('/').filter(part => !ignored.includes(part));
|
|
2772
|
-
for (let i = 0; i < parts.length - 1; i++) {
|
|
2773
|
-
const current = parts[i];
|
|
2774
|
-
const rest = parts.slice(i + 1);
|
|
2775
|
-
if (rest.includes(current)) {
|
|
2776
|
-
return true;
|
|
2777
|
-
}
|
|
2778
|
-
}
|
|
2779
|
-
return false;
|
|
2780
|
-
}
|
|
2781
|
-
function dereference(node, root, visited = new WeakSet(), depth = 0, maxDepth = 10) {
|
|
2782
|
-
if (!node || typeof node !== 'object')
|
|
2783
|
-
return node;
|
|
2784
|
-
if (depth > maxDepth)
|
|
2785
|
-
return node;
|
|
2786
|
-
if (node.$ref || node['x-iata-$ref']) {
|
|
2787
|
-
let refPath = node.$ref || node['x-iata-$ref'];
|
|
2788
|
-
if (refPath.includes('#/%24defs')) {
|
|
2789
|
-
refPath = refPath.replace('#/%24defs', '$defs');
|
|
2790
|
-
}
|
|
2791
|
-
else {
|
|
2792
|
-
refPath = refPath.replace('__bundled__', 'definitions');
|
|
2793
|
-
}
|
|
2794
|
-
if (visited.has(node))
|
|
2795
|
-
return { circular: true, $ref: refPath, title: node.title, type: 'any', description: node.description };
|
|
2796
|
-
visited.add(node);
|
|
2797
|
-
const target = resolvePointer(root, refPath);
|
|
2798
|
-
if (!target)
|
|
2799
|
-
return node;
|
|
2800
|
-
const result = Object.assign({}, target);
|
|
2801
|
-
if ('description' in node)
|
|
2802
|
-
result.description = node.description;
|
|
2803
|
-
if ('title' in node)
|
|
2804
|
-
result.title = node.title;
|
|
2805
|
-
return dereference(result, root, visited, depth + 1, maxDepth);
|
|
2806
|
-
}
|
|
2807
|
-
if (Array.isArray(node)) {
|
|
2808
|
-
return node.map(item => dereference(item, root, visited, depth + 1, maxDepth));
|
|
2809
|
-
}
|
|
2810
|
-
const result = {};
|
|
2811
|
-
for (const key in node) {
|
|
2812
|
-
result[key] = dereference(node[key], root, visited, depth + 1, maxDepth);
|
|
2813
|
-
}
|
|
2814
|
-
return result;
|
|
2815
|
-
}
|
|
2816
|
-
const trimSlashes = (str) => {
|
|
2817
|
-
return str.replace(/^\/|\/$/g, '');
|
|
2818
|
-
};
|
|
2819
|
-
function isPropertiesAllHidden(path, hideData) {
|
|
2820
|
-
const current = trimSlashes(path);
|
|
2821
|
-
const parts = current.split('/');
|
|
2822
|
-
for (let i = parts.length; i >= 2; i--) {
|
|
2823
|
-
if (parts[i - 1] === 'properties') {
|
|
2824
|
-
const ancestorPropPath = parts.slice(0, i).join('/');
|
|
2825
|
-
const block = hideData.find(h => trimSlashes(h.path) === ancestorPropPath && ancestorPropPath.endsWith('/properties'));
|
|
2826
|
-
if (block && block.required === undefined) {
|
|
2827
|
-
return true;
|
|
2828
|
-
}
|
|
2829
|
-
}
|
|
2830
|
-
}
|
|
2831
|
-
return false;
|
|
2832
|
-
}
|
|
2833
|
-
function isRequiredOverride(path, hideData) {
|
|
2834
|
-
const entry = hideData.find(h => trimSlashes(h.path) === trimSlashes(path));
|
|
2835
|
-
return entry && typeof entry.required === 'boolean' ? entry.required : undefined;
|
|
2836
|
-
}
|
|
2837
|
-
function isPathHidden(path, hideData, complexData) {
|
|
2838
|
-
const isComplex = checkIfIsComplex(path, complexData);
|
|
2839
|
-
if (isComplex === null) {
|
|
2840
|
-
return false;
|
|
2841
|
-
}
|
|
2842
|
-
else if (isComplex) {
|
|
2843
|
-
const normalizedPath = trimSlashes(path);
|
|
2844
|
-
const direct = hideData.find(h => trimSlashes(h.path) === normalizedPath);
|
|
2845
|
-
if (direct && direct.required === undefined)
|
|
2846
|
-
return true;
|
|
2847
|
-
if (isPropertiesAllHidden(path, hideData))
|
|
2848
|
-
return true;
|
|
2849
|
-
for (const h of hideData) {
|
|
2850
|
-
const hPath = trimSlashes(h.path);
|
|
2851
|
-
if (h.required !== undefined)
|
|
2852
|
-
continue;
|
|
2853
|
-
if (normalizedPath.length > hPath.length &&
|
|
2854
|
-
normalizedPath.startsWith(hPath) &&
|
|
2855
|
-
(hPath.endsWith('/items') || (hPath.match(/\/items\/[^\/]+$/) && normalizedPath.startsWith(hPath + '/')))) {
|
|
2856
|
-
return true;
|
|
2857
|
-
}
|
|
2858
|
-
}
|
|
2859
|
-
return false;
|
|
2860
|
-
}
|
|
2861
|
-
else {
|
|
2862
|
-
return !hideData.some(h => h.path === path || h.path.startsWith(path + '/'));
|
|
2863
|
-
}
|
|
2864
|
-
}
|
|
2865
|
-
const checkIfIsComplex = (path, complexData) => {
|
|
2866
|
-
let isComplex = null;
|
|
2867
|
-
for (const complex of complexData) {
|
|
2868
|
-
if (path.startsWith(complex.location)) {
|
|
2869
|
-
isComplex = complex === null || complex === void 0 ? void 0 : complex.isComplex;
|
|
2870
|
-
break;
|
|
2871
|
-
}
|
|
2872
|
-
}
|
|
2873
|
-
return isComplex;
|
|
2874
|
-
};
|
|
2875
|
-
const LazySchemaTreePreviewer = ({ schema, root = schema, title, level = 1, path = '', hideData = [], complexData = [], parentRequired, propertyKey, _subType, }) => {
|
|
2876
|
-
var _a, _b, _c, _d;
|
|
2877
|
-
const [expanded, setExpanded] = React.useState(false);
|
|
2878
|
-
const [selectedSchemaIndex, setSelectedSchemaIndex] = React.useState(0);
|
|
2879
|
-
const [showSchemaDropdown, setShowSchemaDropdown] = React.useState(false);
|
|
2880
|
-
const [isHoveringSelector, setIsHoveringSelector] = React.useState(false);
|
|
2881
|
-
const isRoot = level === 1 && (title === undefined || path === '');
|
|
2882
|
-
console.log("In LazySchemaTreePreviewer Beta 0.2:", { schema, path, isRoot });
|
|
2883
|
-
React.useEffect(() => {
|
|
2884
|
-
setSelectedSchemaIndex(0);
|
|
2885
|
-
}, [schema === null || schema === void 0 ? void 0 : schema.anyOf, schema === null || schema === void 0 ? void 0 : schema.oneOf]);
|
|
2886
|
-
const thisNodeRequiredOverride = isRequiredOverride(path, hideData);
|
|
2887
|
-
const shouldHideAllChildren = (isRoot && hideData.some(h => trimSlashes(h.path) === 'properties' && h.required === undefined)) ||
|
|
2888
|
-
(!isRoot && isPropertiesAllHidden(path, hideData));
|
|
2889
|
-
const hasExpandableChildren = React.useMemo(() => {
|
|
2890
|
-
var _a;
|
|
2891
|
-
if (shouldHideAllChildren)
|
|
2892
|
-
return false;
|
|
2893
|
-
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))) {
|
|
2894
|
-
let props = schema === null || schema === void 0 ? void 0 : schema.properties;
|
|
2895
|
-
if (schema === null || schema === void 0 ? void 0 : schema.allOf) {
|
|
2896
|
-
schema === null || schema === void 0 ? void 0 : schema.allOf.forEach((item) => {
|
|
2897
|
-
props = Object.assign(Object.assign({}, props), item.properties);
|
|
2898
|
-
});
|
|
2899
|
-
}
|
|
2900
|
-
if ((schema === null || schema === void 0 ? void 0 : schema.anyOf) && (schema === null || schema === void 0 ? void 0 : schema.anyOf.length) > 0) {
|
|
2901
|
-
const selectedSchema = (schema === null || schema === void 0 ? void 0 : schema.anyOf[selectedSchemaIndex]) || (schema === null || schema === void 0 ? void 0 : schema.anyOf[0]);
|
|
2902
|
-
props = Object.assign(Object.assign({}, props), selectedSchema.properties);
|
|
2903
|
-
}
|
|
2904
|
-
if ((schema === null || schema === void 0 ? void 0 : schema.oneOf) && (schema === null || schema === void 0 ? void 0 : schema.oneOf.length) > 0) {
|
|
2905
|
-
const selectedSchema = (schema === null || schema === void 0 ? void 0 : schema.oneOf[selectedSchemaIndex]) || (schema === null || schema === void 0 ? void 0 : schema.oneOf[0]);
|
|
2906
|
-
props = Object.assign(Object.assign({}, props), selectedSchema.properties);
|
|
2907
|
-
}
|
|
2908
|
-
if (props && Object.keys(props).length > 0) {
|
|
2909
|
-
for (const [key] of Object.entries(props)) {
|
|
2910
|
-
const childPath = `${path}/properties/${key}`;
|
|
2911
|
-
const childRequiredOverride = isRequiredOverride(childPath, hideData);
|
|
2912
|
-
const shouldHideChild = isPathHidden(childPath, hideData, complexData) && childRequiredOverride === undefined;
|
|
2913
|
-
if (!shouldHideChild)
|
|
2914
|
-
return true;
|
|
2915
|
-
}
|
|
2916
|
-
}
|
|
2917
|
-
}
|
|
2918
|
-
if ((schema === null || schema === void 0 ? void 0 : schema.type) === 'array' &&
|
|
2919
|
-
(schema === null || schema === void 0 ? void 0 : schema.items) &&
|
|
2920
|
-
Object.keys(schema === null || schema === void 0 ? void 0 : schema.items).length > 0 &&
|
|
2921
|
-
!((_a = schema === null || schema === void 0 ? void 0 : schema.items) === null || _a === void 0 ? void 0 : _a.circular)) {
|
|
2922
|
-
const resolvedItems = dereference(schema === null || schema === void 0 ? void 0 : schema.items, root);
|
|
2923
|
-
const itemsPath = `${path}/items`;
|
|
2924
|
-
if (resolvedItems && resolvedItems.type === 'object' && resolvedItems.properties) {
|
|
2925
|
-
for (const [key] of Object.entries(resolvedItems.properties)) {
|
|
2926
|
-
const childPath = `${itemsPath}/properties/${key}`;
|
|
2927
|
-
const childRequiredOverride = isRequiredOverride(childPath, hideData);
|
|
2928
|
-
const shouldHideChild = isPathHidden(childPath, hideData, complexData) && childRequiredOverride === undefined;
|
|
2929
|
-
if (!shouldHideChild)
|
|
2930
|
-
return true;
|
|
2931
|
-
}
|
|
2932
|
-
}
|
|
2933
|
-
else if (resolvedItems &&
|
|
2934
|
-
resolvedItems.type === 'array' &&
|
|
2935
|
-
resolvedItems.items &&
|
|
2936
|
-
resolvedItems.items.length > 0) {
|
|
2937
|
-
const childPath = `${path}/items`;
|
|
2938
|
-
const childRequiredOverride = isRequiredOverride(childPath, hideData);
|
|
2939
|
-
const shouldHideChild = isPathHidden(childPath, hideData, complexData) && childRequiredOverride === undefined;
|
|
2940
|
-
if (!shouldHideChild)
|
|
2941
|
-
return true;
|
|
2942
|
-
}
|
|
2943
|
-
}
|
|
2944
|
-
return false;
|
|
2945
|
-
}, [schema, path, hideData, complexData, shouldHideAllChildren, root, selectedSchemaIndex]);
|
|
2946
|
-
const shouldHideNode = React.useMemo(() => {
|
|
2947
|
-
if (isRoot)
|
|
2948
|
-
return false;
|
|
2949
|
-
if (isPathHidden(path, hideData, complexData) && thisNodeRequiredOverride === undefined)
|
|
2950
|
-
return true;
|
|
2951
|
-
return false;
|
|
2952
|
-
}, [path, hideData, isRoot, thisNodeRequiredOverride, complexData]);
|
|
2953
|
-
if (!schema || shouldHideNode) {
|
|
2954
|
-
return null;
|
|
2955
|
-
}
|
|
2956
|
-
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';
|
|
2957
|
-
const handleToggle = () => {
|
|
2958
|
-
const circular = detectCircularPath(path);
|
|
2959
|
-
if (!circular) {
|
|
2960
|
-
setExpanded(prev => !prev);
|
|
2961
|
-
}
|
|
2962
|
-
};
|
|
2963
|
-
const renderChildren = () => {
|
|
2964
|
-
var _a, _b, _c, _d;
|
|
2965
|
-
if (shouldHideAllChildren)
|
|
2966
|
-
return null;
|
|
2967
|
-
if (!expanded && !isRoot)
|
|
2968
|
-
return null;
|
|
2969
|
-
const children = [];
|
|
2970
|
-
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))) {
|
|
2971
|
-
let props = schema === null || schema === void 0 ? void 0 : schema.properties;
|
|
2972
|
-
if (schema === null || schema === void 0 ? void 0 : schema.allOf) {
|
|
2973
|
-
schema === null || schema === void 0 ? void 0 : schema.allOf.forEach((item) => {
|
|
2974
|
-
props = Object.assign(Object.assign({}, props), item.properties);
|
|
2975
|
-
});
|
|
2976
|
-
}
|
|
2977
|
-
if ((schema === null || schema === void 0 ? void 0 : schema.anyOf) && (schema === null || schema === void 0 ? void 0 : schema.anyOf.length) > 0) {
|
|
2978
|
-
const selectedSchema = (schema === null || schema === void 0 ? void 0 : schema.anyOf[selectedSchemaIndex]) || (schema === null || schema === void 0 ? void 0 : schema.anyOf[0]);
|
|
2979
|
-
props = Object.assign(Object.assign({}, props), selectedSchema.properties);
|
|
2980
|
-
}
|
|
2981
|
-
if ((schema === null || schema === void 0 ? void 0 : schema.oneOf) && (schema === null || schema === void 0 ? void 0 : schema.oneOf.length) > 0) {
|
|
2982
|
-
const selectedSchema = (schema === null || schema === void 0 ? void 0 : schema.oneOf[selectedSchemaIndex]) || (schema === null || schema === void 0 ? void 0 : schema.oneOf[0]);
|
|
2983
|
-
props = Object.assign(Object.assign({}, props), selectedSchema.properties);
|
|
2984
|
-
}
|
|
2985
|
-
for (const [key, child] of Object.entries(props || {})) {
|
|
2986
|
-
const childPath = `${path}/properties/${key}`;
|
|
2987
|
-
const childRequiredOverride = isRequiredOverride(childPath, hideData);
|
|
2988
|
-
const shouldHideChild = isPathHidden(childPath, hideData, complexData) && childRequiredOverride === undefined;
|
|
2989
|
-
const resolved = dereference(child, root);
|
|
2990
|
-
if (!shouldHideChild) {
|
|
2991
|
-
children.push(React.createElement("li", { key: key },
|
|
2992
|
-
React.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 })));
|
|
2993
|
-
}
|
|
2994
|
-
}
|
|
2995
|
-
}
|
|
2996
|
-
else if ((schema === null || schema === void 0 ? void 0 : schema.type) === 'array' &&
|
|
2997
|
-
(schema === null || schema === void 0 ? void 0 : schema.items) &&
|
|
2998
|
-
Object.keys(schema === null || schema === void 0 ? void 0 : schema.items).length > 0 &&
|
|
2999
|
-
!((_b = schema === null || schema === void 0 ? void 0 : schema.items) === null || _b === void 0 ? void 0 : _b.circular)) {
|
|
3000
|
-
const resolvedItems = dereference(schema === null || schema === void 0 ? void 0 : schema.items, root);
|
|
3001
|
-
const itemsPath = `${path}/items`;
|
|
3002
|
-
if (resolvedItems && resolvedItems.type === 'object' && resolvedItems.properties) {
|
|
3003
|
-
for (const [key, child] of Object.entries(resolvedItems.properties)) {
|
|
3004
|
-
const childPath = `${itemsPath}/properties/${key}`;
|
|
3005
|
-
const childRequiredOverride = isRequiredOverride(childPath, hideData);
|
|
3006
|
-
const shouldHideChild = isPathHidden(childPath, hideData, complexData) && childRequiredOverride === undefined;
|
|
3007
|
-
const resolved = dereference(child, root);
|
|
3008
|
-
if (!shouldHideChild) {
|
|
3009
|
-
children.push(React.createElement("li", { key: key },
|
|
3010
|
-
React.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 })));
|
|
3011
|
-
}
|
|
3012
|
-
}
|
|
3013
|
-
}
|
|
3014
|
-
else if (resolvedItems && resolvedItems.type === 'array' && resolvedItems.items.length > 0) {
|
|
3015
|
-
const childPath = `${path}/items`;
|
|
3016
|
-
const childRequiredOverride = isRequiredOverride(childPath, hideData);
|
|
3017
|
-
const shouldHideChild = isPathHidden(childPath, hideData, complexData) && childRequiredOverride === undefined;
|
|
3018
|
-
if (!shouldHideChild) {
|
|
3019
|
-
children.push(React.createElement("li", { key: "items" },
|
|
3020
|
-
React.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 })));
|
|
3021
|
-
}
|
|
3022
|
-
}
|
|
3023
|
-
}
|
|
3024
|
-
return children.length > 0 ? React.createElement("ul", { className: "ml-6 border-l border-gray-200 pl-2" }, children) : null;
|
|
3025
|
-
};
|
|
3026
|
-
const combinedSchemaSelector = () => {
|
|
3027
|
-
var _a;
|
|
3028
|
-
return (React.createElement(React.Fragment, null,
|
|
3029
|
-
React.createElement(mosaic.Box, { pos: "fixed", top: 0, left: 0, right: 0, bottom: 0, bg: "transparent", style: { zIndex: 999 }, onClick: () => setShowSchemaDropdown(false) }),
|
|
3030
|
-
React.createElement(mosaic.Box, { pos: "absolute", bg: "canvas", rounded: true, boxShadow: "md", style: {
|
|
3031
|
-
zIndex: 1000,
|
|
3032
|
-
top: '100%',
|
|
3033
|
-
left: 0,
|
|
3034
|
-
minWidth: '150px',
|
|
3035
|
-
maxWidth: '200px',
|
|
3036
|
-
marginTop: '2px',
|
|
3037
|
-
border: '1px solid rgba(0, 0, 0, 0.1)',
|
|
3038
|
-
}, 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.createElement(mosaic.Box, { key: index, px: 3, py: 2, cursor: "pointer", bg: selectedSchemaIndex === index ? 'primary-tint' : 'canvas', fontSize: "xs", display: "flex", alignItems: "center", style: {
|
|
3039
|
-
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',
|
|
3040
|
-
gap: '8px',
|
|
3041
|
-
}, onMouseEnter: (e) => {
|
|
3042
|
-
if (selectedSchemaIndex !== index) {
|
|
3043
|
-
e.currentTarget.style.backgroundColor = 'var(--sl-color-canvas-tint)';
|
|
3044
|
-
}
|
|
3045
|
-
}, onMouseLeave: (e) => {
|
|
3046
|
-
if (selectedSchemaIndex !== index) {
|
|
3047
|
-
e.currentTarget.style.backgroundColor = 'var(--sl-color-canvas)';
|
|
3048
|
-
}
|
|
3049
|
-
}, onClick: () => {
|
|
3050
|
-
setSelectedSchemaIndex(index);
|
|
3051
|
-
setShowSchemaDropdown(false);
|
|
3052
|
-
} },
|
|
3053
|
-
React.createElement(mosaic.Box, { flex: 1, color: "body" }, schemaOption.type || 'object'),
|
|
3054
|
-
selectedSchemaIndex === index && (React.createElement(mosaic.Box, { color: "primary", fontSize: "xs" }, "\u2713"))))))));
|
|
3055
|
-
};
|
|
3056
|
-
const renderMinEnums = (schema) => {
|
|
3057
|
-
if (!schema || typeof schema !== 'object')
|
|
3058
|
-
return null;
|
|
3059
|
-
const boxStyle = {
|
|
3060
|
-
background: 'rgba(245, 247, 250, 0.5)',
|
|
3061
|
-
border: '1px solid #a0aec0',
|
|
3062
|
-
borderRadius: '4px',
|
|
3063
|
-
padding: '0px 2px',
|
|
3064
|
-
display: 'inline-block',
|
|
3065
|
-
overflowWrap: 'break-word',
|
|
3066
|
-
textAlign: 'left',
|
|
3067
|
-
maxWidth: 'fit-content',
|
|
3068
|
-
maxHeight: 'fit-content',
|
|
3069
|
-
};
|
|
3070
|
-
if ('minItems' in schema) {
|
|
3071
|
-
const schemaWithMinItems = schema;
|
|
3072
|
-
if (typeof schemaWithMinItems.minItems === 'number') {
|
|
3073
|
-
return (React.createElement(mosaic.Box, { className: "sl-text-muted", fontFamily: "ui", fontWeight: "normal", mr: 2, style: boxStyle }, `>=${schemaWithMinItems.minItems} items`));
|
|
3074
|
-
}
|
|
3075
|
-
}
|
|
3076
|
-
if ('enum' in schema && Array.isArray(schema.enum)) {
|
|
3077
|
-
return (React.createElement("div", null,
|
|
3078
|
-
"Allowed values:",
|
|
3079
|
-
' ',
|
|
3080
|
-
schema.enum.map((val, idx) => (React.createElement(mosaic.Box, { key: idx, className: "sl-text-muted", fontFamily: "ui", fontWeight: "normal", mr: 2, style: boxStyle }, val)))));
|
|
3081
|
-
}
|
|
3082
|
-
return null;
|
|
3083
|
-
};
|
|
3084
|
-
const isRequired = parentRequired && propertyKey && parentRequired.includes(propertyKey);
|
|
3085
|
-
let showRequiredLabel = false;
|
|
3086
|
-
const hideDataEntry = hideData.find(hideEntry => trimSlashes(hideEntry.path) === trimSlashes(path));
|
|
3087
|
-
if ((hideDataEntry === null || hideDataEntry === void 0 ? void 0 : hideDataEntry.required) === true || ((hideDataEntry === null || hideDataEntry === void 0 ? void 0 : hideDataEntry.required) === undefined && isRequired)) {
|
|
3088
|
-
showRequiredLabel = true;
|
|
3089
|
-
}
|
|
3090
|
-
if (schema === null || schema === void 0 ? void 0 : schema.$ref) {
|
|
3091
|
-
schema = dereference(schema, root);
|
|
3092
|
-
}
|
|
3093
|
-
return (React.createElement("div", { className: "mb-1" },
|
|
3094
|
-
React.createElement(mosaic.Flex, { maxW: "full", pl: 3, py: 2, "data-test": "schema-row", pos: "relative" },
|
|
3095
|
-
React.createElement(mosaic.VStack, { spacing: 1, maxW: "full", className: "w-full" },
|
|
3096
|
-
React.createElement(mosaic.Flex, { onClick: !isRoot ? handleToggle : undefined, className: `w-full ${isRoot ? '' : 'cursor-pointer'}` },
|
|
3097
|
-
!isRoot ? (React.createElement(mosaic.Box, { mr: 2, className: "sl-font-mono sl-font-semibold sl-mr-2" },
|
|
3098
|
-
hasExpandableChildren &&
|
|
3099
|
-
!TYPES.includes(schema === null || schema === void 0 ? void 0 : schema.type) &&
|
|
3100
|
-
!detectCircularPath(path) &&
|
|
3101
|
-
!((_b = schema === null || schema === void 0 ? void 0 : schema.items) === null || _b === void 0 ? void 0 : _b.circular) &&
|
|
3102
|
-
!(schema === null || schema === void 0 ? void 0 : schema.circular) ? (React.createElement("i", { role: "img", "aria-hidden": "true", className: `sl-icon fal ${expanded ? 'fa-chevron-down' : 'fa-chevron-right'} fa-fw fa-sm` })) : (React.createElement("span", { className: "sl-icon fal fa-fw fa-sm", "aria-hidden": "true" })),
|
|
3103
|
-
' ' + displayTitle)) : null,
|
|
3104
|
-
!isRoot ? (React.createElement(mosaic.Box, { mr: 2, pos: "relative" },
|
|
3105
|
-
React.createElement(mosaic.Box, { display: "inline-flex", alignItems: "center", onMouseEnter: () => {
|
|
3106
|
-
if ((schema === null || schema === void 0 ? void 0 : schema.anyOf) || (schema === null || schema === void 0 ? void 0 : schema.oneOf)) {
|
|
3107
|
-
setIsHoveringSelector(true);
|
|
3108
|
-
}
|
|
3109
|
-
}, onMouseLeave: () => {
|
|
3110
|
-
if (!showSchemaDropdown) {
|
|
3111
|
-
setIsHoveringSelector(false);
|
|
3112
|
-
}
|
|
3113
|
-
}, onClick: (e) => {
|
|
3114
|
-
if ((schema === null || schema === void 0 ? void 0 : schema.anyOf) || (schema === null || schema === void 0 ? void 0 : schema.oneOf)) {
|
|
3115
|
-
e.stopPropagation();
|
|
3116
|
-
setShowSchemaDropdown(prev => !prev);
|
|
3117
|
-
}
|
|
3118
|
-
}, style: {
|
|
3119
|
-
cursor: (schema === null || schema === void 0 ? void 0 : schema.anyOf) || (schema === null || schema === void 0 ? void 0 : schema.oneOf) ? 'pointer' : 'default',
|
|
3120
|
-
} },
|
|
3121
|
-
React.createElement("span", { className: "sl-truncate sl-text-muted" },
|
|
3122
|
-
(() => {
|
|
3123
|
-
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);
|
|
3124
|
-
if ((schema === null || schema === void 0 ? void 0 : schema.anyOf) && (schema === null || schema === void 0 ? void 0 : schema.anyOf.length) > 0) {
|
|
3125
|
-
return `any of ${typeDisplay}`;
|
|
3126
|
-
}
|
|
3127
|
-
else if ((schema === null || schema === void 0 ? void 0 : schema.oneOf) && (schema === null || schema === void 0 ? void 0 : schema.oneOf.length) > 0) {
|
|
3128
|
-
return `one of ${typeDisplay}`;
|
|
3129
|
-
}
|
|
3130
|
-
return typeDisplay;
|
|
3131
|
-
})(),
|
|
3132
|
-
(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),
|
|
3133
|
-
((schema === null || schema === void 0 ? void 0 : schema.anyOf) || (schema === null || schema === void 0 ? void 0 : schema.oneOf)) && (React.createElement(mosaic.Box, { display: "inline-flex", alignItems: "center", ml: 1, style: {
|
|
3134
|
-
opacity: isHoveringSelector ? 1 : 0.6,
|
|
3135
|
-
transition: 'opacity 0.2s',
|
|
3136
|
-
} },
|
|
3137
|
-
React.createElement("i", { className: "sl-icon fas fa-chevron-down", style: {
|
|
3138
|
-
fontSize: '10px',
|
|
3139
|
-
opacity: 0.6,
|
|
3140
|
-
} })))),
|
|
3141
|
-
React.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),
|
|
3142
|
-
((schema === null || schema === void 0 ? void 0 : schema.anyOf) || (schema === null || schema === void 0 ? void 0 : schema.oneOf)) && showSchemaDropdown && combinedSchemaSelector())) : null),
|
|
3143
|
-
React.createElement(mosaic.Flex, { pl: 1, w: "full", align: "start", direction: "col", style: { overflow: 'visible', paddingLeft: '20px' } },
|
|
3144
|
-
(schema === null || schema === void 0 ? void 0 : schema.description) && (React.createElement(mosaic.Box, { fontFamily: "ui", fontWeight: "light" },
|
|
3145
|
-
React.createElement("span", { className: "sl-prose sl-markdown-viewer", style: { fontSize: '12px' } }, schema === null || schema === void 0 ? void 0 : schema.description))),
|
|
3146
|
-
!isRoot && (schema === null || schema === void 0 ? void 0 : schema.examples) !== undefined && (React.createElement(mosaic.Flex, { align: "center", mb: 1, style: { flexWrap: 'wrap' } },
|
|
3147
|
-
React.createElement("span", { className: "text-gray-500", style: { marginRight: 8, flexShrink: 0 } }, "Example"),
|
|
3148
|
-
React.createElement(mosaic.Box, { className: "sl-text-muted", fontFamily: "ui", fontWeight: "normal", mr: 2, style: {
|
|
3149
|
-
background: 'rgba(245, 247, 250, 0.5)',
|
|
3150
|
-
border: '1px solid #a0aec0',
|
|
3151
|
-
borderRadius: '4px',
|
|
3152
|
-
padding: '4px 8px',
|
|
3153
|
-
display: 'inline-block',
|
|
3154
|
-
overflowWrap: 'break-word',
|
|
3155
|
-
textAlign: 'left',
|
|
3156
|
-
maxWidth: '530px',
|
|
3157
|
-
} }, JSON.stringify(schema === null || schema === void 0 ? void 0 : schema.examples))))),
|
|
3158
|
-
React.createElement(mosaic.Flex, { pl: 1, w: "full", align: "start", direction: "col", style: { overflow: 'visible', paddingLeft: '20px' } }, schema &&
|
|
3159
|
-
typeof schema === 'object' &&
|
|
3160
|
-
('minItems' in schema || 'enum' in schema) &&
|
|
3161
|
-
renderMinEnums(schema))),
|
|
3162
|
-
!isRoot && (React.createElement("label", { className: "inline-flex items-top ml-2" },
|
|
3163
|
-
React.createElement(mosaic.Box, { mr: 2, fontFamily: "ui", fontWeight: "normal" }, showRequiredLabel && (React.createElement("div", { className: "sl-ml-2 sl-text-warning" },
|
|
3164
|
-
React.createElement("span", { style: { marginLeft: '10px' } }, "required"))))))),
|
|
3165
|
-
renderChildren()));
|
|
3166
|
-
};
|
|
3167
|
-
|
|
3168
2767
|
const isBodyEmpty = (body) => {
|
|
3169
2768
|
if (!body)
|
|
3170
2769
|
return true;
|
|
3171
2770
|
const { contents = [], description } = body;
|
|
3172
2771
|
return contents.length === 0 && !(description === null || description === void 0 ? void 0 : description.trim());
|
|
3173
2772
|
};
|
|
3174
|
-
const Body = ({ body, onChange, isHttpWebhookOperation = false
|
|
2773
|
+
const Body = ({ body, onChange, isHttpWebhookOperation = false }) => {
|
|
3175
2774
|
var _a;
|
|
3176
2775
|
const [refResolver, maxRefDepth] = useSchemaInlineRefResolver();
|
|
3177
2776
|
const [chosenContent, setChosenContent] = React__namespace.useState(0);
|
|
@@ -3184,36 +2783,13 @@ const Body = ({ body, onChange, isHttpWebhookOperation = false, disableProps })
|
|
|
3184
2783
|
const { contents = [], description } = body;
|
|
3185
2784
|
const schema = (_a = contents[chosenContent]) === null || _a === void 0 ? void 0 : _a.schema;
|
|
3186
2785
|
const descriptionChanged = nodeHasChanged === null || nodeHasChanged === void 0 ? void 0 : nodeHasChanged({ nodeId: body.id, attr: 'description' });
|
|
3187
|
-
const getMaskProperties = () => {
|
|
3188
|
-
const disablePropsConfig = disableProps || [];
|
|
3189
|
-
const absolutePathsToHide = [];
|
|
3190
|
-
disablePropsConfig.forEach(configEntry => {
|
|
3191
|
-
const { location, paths, isComplex } = configEntry;
|
|
3192
|
-
if (paths.length === 0 && !isComplex) {
|
|
3193
|
-
absolutePathsToHide.push({ path: location });
|
|
3194
|
-
}
|
|
3195
|
-
else {
|
|
3196
|
-
paths.forEach((item) => {
|
|
3197
|
-
const fullPath = location === '#' ? item === null || item === void 0 ? void 0 : item.path : `${location}/${item.path}`;
|
|
3198
|
-
let object = { path: fullPath };
|
|
3199
|
-
if (item.hasOwnProperty('required')) {
|
|
3200
|
-
object = Object.assign(Object.assign({}, object), { required: item === null || item === void 0 ? void 0 : item.required });
|
|
3201
|
-
}
|
|
3202
|
-
absolutePathsToHide.push(object);
|
|
3203
|
-
});
|
|
3204
|
-
}
|
|
3205
|
-
});
|
|
3206
|
-
return absolutePathsToHide;
|
|
3207
|
-
};
|
|
3208
|
-
const shouldUseLazySchema = disableProps === null || disableProps === void 0 ? void 0 : disableProps.some(entry => entry.isComplex === true);
|
|
3209
|
-
console.log('!!!!! shouldUseLazySchema body!!!!', shouldUseLazySchema);
|
|
3210
2786
|
return (React__namespace.createElement(mosaic.VStack, { spacing: 6 },
|
|
3211
2787
|
React__namespace.createElement(SectionSubtitle, { title: "Body", id: "request-body" }, contents.length > 0 && (React__namespace.createElement(mosaic.Flex, { flex: 1, justify: "end" },
|
|
3212
2788
|
React__namespace.createElement(mosaic.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" })))),
|
|
3213
2789
|
description && (React__namespace.createElement(mosaic.Box, { pos: "relative" },
|
|
3214
2790
|
React__namespace.createElement(MarkdownViewer, { markdown: description }),
|
|
3215
2791
|
React__namespace.createElement(mosaic.NodeAnnotation, { change: descriptionChanged }))),
|
|
3216
|
-
|
|
2792
|
+
isJSONSchema(schema) && (React__namespace.createElement(jsonSchemaViewer.JsonSchemaViewer, { resolveRef: refResolver, maxRefDepth: maxRefDepth, schema: getOriginalObject(schema), viewMode: isHttpWebhookOperation ? 'standalone' : 'write', renderRootTreeLines: true, nodeHasChanged: nodeHasChanged, renderExtensionAddon: renderExtensionAddon }))));
|
|
3217
2793
|
};
|
|
3218
2794
|
Body.displayName = 'HttpOperation.Body';
|
|
3219
2795
|
|
|
@@ -3280,7 +2856,7 @@ const httpOperationParamsToSchema = ({ parameters, parameterType }) => {
|
|
|
3280
2856
|
return schema;
|
|
3281
2857
|
};
|
|
3282
2858
|
|
|
3283
|
-
const Request = ({ operation: { request, request: { path: pathParams = [], headers: headerParams = [], cookie: cookieParams = [], body, query: queryParams = [], } = {}, security, }, hideSecurityInfo, onChange, isHttpWebhookOperation = false,
|
|
2859
|
+
const Request = ({ operation: { request, request: { path: pathParams = [], headers: headerParams = [], cookie: cookieParams = [], body, query: queryParams = [], } = {}, security, }, hideSecurityInfo, onChange, isHttpWebhookOperation = false, }) => {
|
|
3284
2860
|
if (!request || typeof request !== 'object')
|
|
3285
2861
|
return null;
|
|
3286
2862
|
const bodyIsEmpty = isBodyEmpty(body);
|
|
@@ -3308,7 +2884,7 @@ const Request = ({ operation: { request, request: { path: pathParams = [], heade
|
|
|
3308
2884
|
cookieParams.length > 0 && (React__namespace.createElement(mosaic.VStack, { spacing: 5 },
|
|
3309
2885
|
React__namespace.createElement(SectionSubtitle, { title: "Cookies", id: "request-cookies" }),
|
|
3310
2886
|
React__namespace.createElement(Parameters, { parameterType: "cookie", parameters: cookieParams }))),
|
|
3311
|
-
body &&
|
|
2887
|
+
body && React__namespace.createElement(Body, { onChange: onChange, body: body, isHttpWebhookOperation: isHttpWebhookOperation })));
|
|
3312
2888
|
};
|
|
3313
2889
|
Request.displayName = 'HttpOperation.Request';
|
|
3314
2890
|
const schemeExpandedState = utils.atomWithStorage('HttpOperation_security_expanded', {});
|
|
@@ -3339,7 +2915,7 @@ const OptionalMessage$1 = () => {
|
|
|
3339
2915
|
return React__namespace.createElement(mosaic.Callout, { appearance: "outline" }, OptionalSecurityMessage);
|
|
3340
2916
|
};
|
|
3341
2917
|
|
|
3342
|
-
const Responses = ({ responses: unsortedResponses, onStatusCodeChange, onMediaTypeChange, isCompact,
|
|
2918
|
+
const Responses = ({ responses: unsortedResponses, onStatusCodeChange, onMediaTypeChange, isCompact, }) => {
|
|
3343
2919
|
var _a, _b;
|
|
3344
2920
|
const responses = sortBy(uniqBy(unsortedResponses, r => r.code), r => r.code);
|
|
3345
2921
|
const [activeResponseId, setActiveResponseId] = React__namespace.useState((_b = (_a = responses[0]) === null || _a === void 0 ? void 0 : _a.code) !== null && _b !== void 0 ? _b : '');
|
|
@@ -3372,12 +2948,11 @@ const Responses = ({ responses: unsortedResponses, onStatusCodeChange, onMediaTy
|
|
|
3372
2948
|
const tabResponses = (React__namespace.createElement(mosaic.TabList, { density: "compact" }, responses.map(({ code }) => (React__namespace.createElement(mosaic.Tab, { key: code, id: code, intent: codeToIntentVal(code) }, code)))));
|
|
3373
2949
|
return (React__namespace.createElement(mosaic.VStack, { spacing: 8, as: mosaic.Tabs, selectedId: activeResponseId, onChange: setActiveResponseId, appearance: "pill" },
|
|
3374
2950
|
React__namespace.createElement(SectionTitle, { title: "Responses", isCompact: isCompact }, isCompact ? compactResponses : tabResponses),
|
|
3375
|
-
isCompact ? (React__namespace.createElement(Response, { response: response, onMediaTypeChange: onMediaTypeChange
|
|
3376
|
-
React__namespace.createElement(Response, { response: response, onMediaTypeChange: onMediaTypeChange
|
|
2951
|
+
isCompact ? (React__namespace.createElement(Response, { response: response, onMediaTypeChange: onMediaTypeChange })) : (React__namespace.createElement(mosaic.TabPanels, { p: 0 }, responses.map(response => (React__namespace.createElement(mosaic.TabPanel, { key: response.code, id: response.code },
|
|
2952
|
+
React__namespace.createElement(Response, { response: response, onMediaTypeChange: onMediaTypeChange }))))))));
|
|
3377
2953
|
};
|
|
3378
2954
|
Responses.displayName = 'HttpOperation.Responses';
|
|
3379
|
-
const Response = ({ response, onMediaTypeChange
|
|
3380
|
-
var _a, _b;
|
|
2955
|
+
const Response = ({ response, onMediaTypeChange }) => {
|
|
3381
2956
|
const { contents = [], headers = [], description } = response;
|
|
3382
2957
|
const [chosenContent, setChosenContent] = React__namespace.useState(0);
|
|
3383
2958
|
const [refResolver, maxRefDepth] = useSchemaInlineRefResolver();
|
|
@@ -3388,29 +2963,6 @@ const Response = ({ response, onMediaTypeChange, disableProps, statusCode }) =>
|
|
|
3388
2963
|
responseContent && (onMediaTypeChange === null || onMediaTypeChange === void 0 ? void 0 : onMediaTypeChange(responseContent.mediaType));
|
|
3389
2964
|
}, [responseContent]);
|
|
3390
2965
|
const descriptionChanged = nodeHasChanged === null || nodeHasChanged === void 0 ? void 0 : nodeHasChanged({ nodeId: response.id, attr: 'description' });
|
|
3391
|
-
const getMaskProperties = () => {
|
|
3392
|
-
if (!disableProps || !statusCode)
|
|
3393
|
-
return [];
|
|
3394
|
-
const configEntries = disableProps[statusCode] || [];
|
|
3395
|
-
const absolutePathsToHide = [];
|
|
3396
|
-
configEntries.forEach(({ location, paths, isComplex }) => {
|
|
3397
|
-
if (paths.length === 0 && !isComplex) {
|
|
3398
|
-
absolutePathsToHide.push({ path: location });
|
|
3399
|
-
}
|
|
3400
|
-
else {
|
|
3401
|
-
paths.forEach((item) => {
|
|
3402
|
-
const fullPath = location === '#' ? item === null || item === void 0 ? void 0 : item.path : `${location}/${item.path}`;
|
|
3403
|
-
let object = { path: fullPath };
|
|
3404
|
-
if (item.hasOwnProperty('required')) {
|
|
3405
|
-
object = Object.assign(Object.assign({}, object), { required: item === null || item === void 0 ? void 0 : item.required });
|
|
3406
|
-
}
|
|
3407
|
-
absolutePathsToHide.push(object);
|
|
3408
|
-
});
|
|
3409
|
-
}
|
|
3410
|
-
});
|
|
3411
|
-
return absolutePathsToHide;
|
|
3412
|
-
};
|
|
3413
|
-
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;
|
|
3414
2966
|
return (React__namespace.createElement(mosaic.VStack, { spacing: 8, pt: 8 },
|
|
3415
2967
|
description && (React__namespace.createElement(mosaic.Box, { pos: "relative" },
|
|
3416
2968
|
React__namespace.createElement(MarkdownViewer, { markdown: description }),
|
|
@@ -3422,7 +2974,7 @@ const Response = ({ response, onMediaTypeChange, disableProps, statusCode }) =>
|
|
|
3422
2974
|
React__namespace.createElement(SectionSubtitle, { title: "Body", id: "response-body" },
|
|
3423
2975
|
React__namespace.createElement(mosaic.Flex, { flex: 1, justify: "end" },
|
|
3424
2976
|
React__namespace.createElement(mosaic.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" }))),
|
|
3425
|
-
schema &&
|
|
2977
|
+
schema && (React__namespace.createElement(jsonSchemaViewer.JsonSchemaViewer, { schema: getOriginalObject(schema), resolveRef: refResolver, maxRefDepth: maxRefDepth, viewMode: "read", parentCrumbs: ['responses', response.code], renderRootTreeLines: true, nodeHasChanged: nodeHasChanged, renderExtensionAddon: renderExtensionAddon }))))));
|
|
3426
2978
|
};
|
|
3427
2979
|
Response.displayName = 'HttpOperation.Response';
|
|
3428
2980
|
const codeToIntentVal = (code) => {
|
|
@@ -3471,7 +3023,7 @@ const Callback = ({ data, isCompact }) => {
|
|
|
3471
3023
|
};
|
|
3472
3024
|
Callbacks.displayName = 'HttpOperation.Callback';
|
|
3473
3025
|
|
|
3474
|
-
const HttpOperationComponent = React__namespace.memo(({ className, data: unresolvedData, layoutOptions, tryItCredentialsPolicy, tryItCorsProxy
|
|
3026
|
+
const HttpOperationComponent = React__namespace.memo(({ className, data: unresolvedData, layoutOptions, tryItCredentialsPolicy, tryItCorsProxy }) => {
|
|
3475
3027
|
var _a;
|
|
3476
3028
|
const { nodeHasChanged } = useOptionsCtx();
|
|
3477
3029
|
const data = useResolvedObject(unresolvedData);
|
|
@@ -3502,11 +3054,11 @@ const HttpOperationComponent = React__namespace.memo(({ className, data: unresol
|
|
|
3502
3054
|
React__namespace.createElement(MarkdownViewer, { className: "HttpOperation__Description", markdown: data.description }),
|
|
3503
3055
|
React__namespace.createElement(mosaic.NodeAnnotation, { change: descriptionChanged }))),
|
|
3504
3056
|
React__namespace.createElement(NodeVendorExtensions, { data: data }),
|
|
3505
|
-
React__namespace.createElement(Request, { onChange: setTextRequestBodyIndex, operation: data, hideSecurityInfo: layoutOptions === null || layoutOptions === void 0 ? void 0 : layoutOptions.hideSecurityInfo, isHttpWebhookOperation: isHttpWebhookOperation(data)
|
|
3506
|
-
data.responses && (React__namespace.createElement(Responses, { responses: data.responses, onMediaTypeChange: setResponseMediaType, onStatusCodeChange: setResponseStatusCode, isCompact: isCompact
|
|
3057
|
+
React__namespace.createElement(Request, { onChange: setTextRequestBodyIndex, operation: data, hideSecurityInfo: layoutOptions === null || layoutOptions === void 0 ? void 0 : layoutOptions.hideSecurityInfo, isHttpWebhookOperation: isHttpWebhookOperation(data) }),
|
|
3058
|
+
data.responses && (React__namespace.createElement(Responses, { responses: data.responses, onMediaTypeChange: setResponseMediaType, onStatusCodeChange: setResponseStatusCode, isCompact: isCompact })),
|
|
3507
3059
|
((_a = data.callbacks) === null || _a === void 0 ? void 0 : _a.length) ? React__namespace.createElement(Callbacks, { callbacks: data.callbacks, isCompact: isCompact }) : null,
|
|
3508
3060
|
isCompact && tryItPanel));
|
|
3509
|
-
return (React__namespace.createElement(TwoColumnLayout, { ref: layoutRef, className: cn('HttpOperation', className), header: header, left: description, right: !
|
|
3061
|
+
return (React__namespace.createElement(TwoColumnLayout, { ref: layoutRef, className: cn('HttpOperation', className), header: header, left: description, right: !isCompact && tryItPanel }));
|
|
3510
3062
|
});
|
|
3511
3063
|
HttpOperationComponent.displayName = 'HttpOperation.Component';
|
|
3512
3064
|
const HttpOperation = reactErrorBoundary.withErrorBoundary(HttpOperationComponent, {
|
|
@@ -3757,7 +3309,7 @@ const HttpServiceComponent = React__namespace.memo(({ data: unresolvedData, loca
|
|
|
3757
3309
|
HttpServiceComponent.displayName = 'HttpService.Component';
|
|
3758
3310
|
const HttpService = reactErrorBoundary.withErrorBoundary(HttpServiceComponent, { recoverableProps: ['data'] });
|
|
3759
3311
|
|
|
3760
|
-
const ModelComponent = ({ data: unresolvedData, className, nodeTitle, layoutOptions, exportProps,
|
|
3312
|
+
const ModelComponent = ({ data: unresolvedData, className, nodeTitle, layoutOptions, exportProps, }) => {
|
|
3761
3313
|
var _a, _b;
|
|
3762
3314
|
const [resolveRef, maxRefDepth] = useSchemaInlineRefResolver();
|
|
3763
3315
|
const data = useResolvedObject(unresolvedData);
|
|
@@ -3780,40 +3332,14 @@ const ModelComponent = ({ data: unresolvedData, className, nodeTitle, layoutOpti
|
|
|
3780
3332
|
exportProps && !(layoutOptions === null || layoutOptions === void 0 ? void 0 : layoutOptions.hideExport) && !isCompact && React__namespace.createElement(ExportButton, Object.assign({}, exportProps))));
|
|
3781
3333
|
const modelExamples = !(layoutOptions === null || layoutOptions === void 0 ? void 0 : layoutOptions.hideModelExamples) && React__namespace.createElement(ModelExamples, { data: data, isCollapsible: isCompact });
|
|
3782
3334
|
const descriptionChanged = nodeHasChanged === null || nodeHasChanged === void 0 ? void 0 : nodeHasChanged({ nodeId, attr: 'description' });
|
|
3783
|
-
const getMaskProperties = () => {
|
|
3784
|
-
const disablePropsConfig = disableProps === null || disableProps === void 0 ? void 0 : disableProps.models;
|
|
3785
|
-
const absolutePathsToHide = [];
|
|
3786
|
-
if (disableProps === null || disableProps === void 0 ? void 0 : disableProps.models) {
|
|
3787
|
-
disablePropsConfig.forEach((configEntry) => {
|
|
3788
|
-
const { location, paths, isComplex } = configEntry;
|
|
3789
|
-
if (paths.length === 0 && !isComplex) {
|
|
3790
|
-
absolutePathsToHide.push({ path: location });
|
|
3791
|
-
}
|
|
3792
|
-
else {
|
|
3793
|
-
paths.forEach((item) => {
|
|
3794
|
-
const fullPath = location === '#' ? item === null || item === void 0 ? void 0 : item.path : `${location}/${item.path}`;
|
|
3795
|
-
let object = { path: fullPath };
|
|
3796
|
-
if (item.hasOwnProperty('required')) {
|
|
3797
|
-
object = Object.assign(Object.assign({}, object), { required: item === null || item === void 0 ? void 0 : item.required });
|
|
3798
|
-
}
|
|
3799
|
-
absolutePathsToHide.push(object);
|
|
3800
|
-
});
|
|
3801
|
-
}
|
|
3802
|
-
});
|
|
3803
|
-
}
|
|
3804
|
-
return absolutePathsToHide;
|
|
3805
|
-
};
|
|
3806
|
-
const shouldUseLazySchema = disableProps && (disableProps === null || disableProps === void 0 ? void 0 : disableProps.models)
|
|
3807
|
-
? disableProps.models.some((entry) => entry.isComplex === true)
|
|
3808
|
-
: false;
|
|
3809
3335
|
const description = (React__namespace.createElement(mosaic.VStack, { spacing: 10 },
|
|
3810
3336
|
data.description && data.type === 'object' && (React__namespace.createElement(mosaic.Box, { pos: "relative" },
|
|
3811
3337
|
React__namespace.createElement(MarkdownViewer, { role: "textbox", markdown: data.description }),
|
|
3812
3338
|
React__namespace.createElement(mosaic.NodeAnnotation, { change: descriptionChanged }))),
|
|
3813
3339
|
React__namespace.createElement(NodeVendorExtensions, { data: data }),
|
|
3814
|
-
|
|
3815
|
-
|
|
3816
|
-
return (React__namespace.createElement(TwoColumnLayout, { ref: layoutRef, className: cn('Model', className), header: header, left: description, right: !
|
|
3340
|
+
isCompact && modelExamples,
|
|
3341
|
+
React__namespace.createElement(jsonSchemaViewer.JsonSchemaViewer, { resolveRef: resolveRef, maxRefDepth: maxRefDepth, schema: getOriginalObject(data), nodeHasChanged: nodeHasChanged, renderExtensionAddon: renderExtensionAddon, skipTopLevelDescription: true })));
|
|
3342
|
+
return (React__namespace.createElement(TwoColumnLayout, { ref: layoutRef, className: cn('Model', className), header: header, left: description, right: !isCompact && modelExamples }));
|
|
3817
3343
|
};
|
|
3818
3344
|
const ModelExamples = React__namespace.memo(({ data, isCollapsible = false }) => {
|
|
3819
3345
|
var _a;
|
|
@@ -3835,41 +3361,30 @@ const Model = reactErrorBoundary.withErrorBoundary(ModelComponent, { recoverable
|
|
|
3835
3361
|
|
|
3836
3362
|
const Docs = React__namespace.memo((_a) => {
|
|
3837
3363
|
var _b;
|
|
3838
|
-
var { nodeType, nodeData,
|
|
3364
|
+
var { nodeType, nodeData, useNodeForRefResolving = false, refResolver, maxRefDepth, nodeHasChanged, renderExtensionAddon } = _a, commonProps = tslib.__rest(_a, ["nodeType", "nodeData", "useNodeForRefResolving", "refResolver", "maxRefDepth", "nodeHasChanged", "renderExtensionAddon"]);
|
|
3839
3365
|
const parsedNode = useParsedData(nodeType, nodeData);
|
|
3840
3366
|
if (!parsedNode) {
|
|
3841
3367
|
(_b = commonProps.nodeUnsupported) === null || _b === void 0 ? void 0 : _b.call(commonProps, 'dataEmpty');
|
|
3842
3368
|
return null;
|
|
3843
3369
|
}
|
|
3844
|
-
let elem = React__namespace.createElement(ParsedDocs, Object.assign({ node: parsedNode
|
|
3370
|
+
let elem = React__namespace.createElement(ParsedDocs, Object.assign({ node: parsedNode }, commonProps));
|
|
3845
3371
|
if (useNodeForRefResolving) {
|
|
3846
3372
|
elem = (React__namespace.createElement(InlineRefResolverProvider, { document: parsedNode.data, resolver: refResolver, maxRefDepth: maxRefDepth }, elem));
|
|
3847
3373
|
}
|
|
3848
3374
|
return (React__namespace.createElement(ElementsOptionsProvider, { nodeHasChanged: nodeHasChanged, renderExtensionAddon: renderExtensionAddon }, elem));
|
|
3849
3375
|
});
|
|
3850
|
-
const getTryItVisibility = (disableProps) => {
|
|
3851
|
-
var _a, _b, _c, _d;
|
|
3852
|
-
if (!disableProps)
|
|
3853
|
-
return { hideOperationTryIt: false, hideModelTryIt: false };
|
|
3854
|
-
const requestHasComplex = (_b = (_a = disableProps.request) === null || _a === void 0 ? void 0 : _a.some(item => item.isComplex)) !== null && _b !== void 0 ? _b : false;
|
|
3855
|
-
const responseHasComplex = Object.values(disableProps.response || {}).some(arr => arr.some(item => item.isComplex));
|
|
3856
|
-
const hideOperationTryIt = requestHasComplex || responseHasComplex;
|
|
3857
|
-
const hideModelTryIt = (_d = (_c = disableProps.models) === null || _c === void 0 ? void 0 : _c.some(item => item.isComplex)) !== null && _d !== void 0 ? _d : false;
|
|
3858
|
-
return { hideOperationTryIt, hideModelTryIt };
|
|
3859
|
-
};
|
|
3860
3376
|
const ParsedDocs = (_a) => {
|
|
3861
|
-
var { node, nodeUnsupported
|
|
3862
|
-
const { hideOperationTryIt, hideModelTryIt } = getTryItVisibility(disableProps);
|
|
3377
|
+
var { node, nodeUnsupported } = _a, commonProps = tslib.__rest(_a, ["node", "nodeUnsupported"]);
|
|
3863
3378
|
switch (node.type) {
|
|
3864
3379
|
case 'article':
|
|
3865
3380
|
return React__namespace.createElement(Article, Object.assign({ data: node.data }, commonProps));
|
|
3866
3381
|
case 'http_operation':
|
|
3867
3382
|
case 'http_webhook':
|
|
3868
|
-
return React__namespace.createElement(HttpOperation, Object.assign({ data: node.data
|
|
3383
|
+
return React__namespace.createElement(HttpOperation, Object.assign({ data: node.data }, commonProps));
|
|
3869
3384
|
case 'http_service':
|
|
3870
3385
|
return React__namespace.createElement(HttpService, Object.assign({ data: node.data }, commonProps));
|
|
3871
3386
|
case 'model':
|
|
3872
|
-
return React__namespace.createElement(Model, Object.assign({ data: node.data
|
|
3387
|
+
return React__namespace.createElement(Model, Object.assign({ data: node.data }, commonProps));
|
|
3873
3388
|
default:
|
|
3874
3389
|
nodeUnsupported === null || nodeUnsupported === void 0 ? void 0 : nodeUnsupported('invalidType');
|
|
3875
3390
|
return null;
|
|
@@ -4007,7 +3522,7 @@ function findFirstNode(items) {
|
|
|
4007
3522
|
return;
|
|
4008
3523
|
}
|
|
4009
3524
|
function isDivider(item) {
|
|
4010
|
-
return Object.keys(item).length ===
|
|
3525
|
+
return Object.keys(item).length === 2 && 'title' in item && 'index' in item;
|
|
4011
3526
|
}
|
|
4012
3527
|
function isGroup(item) {
|
|
4013
3528
|
return Object.keys(item).length >= 2 && 'title' in item && 'items' in item;
|
|
@@ -4019,13 +3534,33 @@ function isNode(item) {
|
|
|
4019
3534
|
return 'title' in item && 'slug' in item && 'id' in item && 'meta' in item && 'type' in item;
|
|
4020
3535
|
}
|
|
4021
3536
|
function isExternalLink(item) {
|
|
4022
|
-
return Object.keys(item).length ===
|
|
3537
|
+
return Object.keys(item).length === 3 && 'title' in item && 'url' in item && 'index' in item;
|
|
4023
3538
|
}
|
|
4024
3539
|
|
|
4025
|
-
const
|
|
3540
|
+
const ActiveItemContext = React__namespace.createContext({
|
|
3541
|
+
activeId: undefined,
|
|
3542
|
+
lastActiveIndex: '',
|
|
3543
|
+
setLastActiveIndex: () => { },
|
|
3544
|
+
});
|
|
4026
3545
|
const LinkContext = React__namespace.createContext(undefined);
|
|
4027
3546
|
LinkContext.displayName = 'LinkContext';
|
|
4028
3547
|
const TableOfContents = React__namespace.memo(({ tree, activeId, Link, maxDepthOpenByDefault, externalScrollbar = false, isInResponsiveMode = false, onLinkClick, }) => {
|
|
3548
|
+
const [lastActiveIndex, setLastActiveIndex] = React.useState('');
|
|
3549
|
+
const value = React__namespace.useMemo(() => ({
|
|
3550
|
+
lastActiveIndex,
|
|
3551
|
+
setLastActiveIndex,
|
|
3552
|
+
activeId,
|
|
3553
|
+
}), [lastActiveIndex, activeId]);
|
|
3554
|
+
const updateTocTree = React__namespace.useCallback((arr, parentId) => {
|
|
3555
|
+
return arr.map((item, key) => {
|
|
3556
|
+
let newItem = Object.assign(Object.assign({}, item), { index: parentId + key + '-' });
|
|
3557
|
+
if (isGroup(item) || isNodeGroup(item)) {
|
|
3558
|
+
newItem.items = updateTocTree(item.items, parentId + key + '-');
|
|
3559
|
+
}
|
|
3560
|
+
return newItem;
|
|
3561
|
+
});
|
|
3562
|
+
}, []);
|
|
3563
|
+
const updatedTree = updateTocTree(tree, '');
|
|
4029
3564
|
const container = React__namespace.useRef(null);
|
|
4030
3565
|
const child = React__namespace.useRef(null);
|
|
4031
3566
|
const firstRender = useFirstRender();
|
|
@@ -4045,18 +3580,30 @@ const TableOfContents = React__namespace.memo(({ tree, activeId, Link, maxDepthO
|
|
|
4045
3580
|
return (React__namespace.createElement(mosaic.Box, { ref: container, w: "full", bg: isInResponsiveMode ? 'canvas' : 'canvas-100', overflowY: "auto" },
|
|
4046
3581
|
React__namespace.createElement(mosaic.Box, { ref: child, my: 3 },
|
|
4047
3582
|
React__namespace.createElement(LinkContext.Provider, { value: Link },
|
|
4048
|
-
React__namespace.createElement(
|
|
4049
|
-
|
|
4050
|
-
|
|
4051
|
-
|
|
4052
|
-
|
|
4053
|
-
|
|
3583
|
+
React__namespace.createElement(ActiveItemContext.Provider, { value: value },
|
|
3584
|
+
React__namespace.createElement(TOCContainer, { updatedTree: updatedTree }, updatedTree.map((item, key) => {
|
|
3585
|
+
if (isDivider(item)) {
|
|
3586
|
+
return React__namespace.createElement(Divider, { key: key, item: item, isInResponsiveMode: isInResponsiveMode });
|
|
3587
|
+
}
|
|
3588
|
+
return (React__namespace.createElement(GroupItem, { key: key, item: item, depth: 0, maxDepthOpenByDefault: maxDepthOpenByDefault, onLinkClick: onLinkClick, isInResponsiveMode: isInResponsiveMode }));
|
|
3589
|
+
})))))));
|
|
4054
3590
|
});
|
|
4055
3591
|
TableOfContents.displayName = 'TableOfContents';
|
|
4056
3592
|
const Divider = React__namespace.memo(({ item, isInResponsiveMode = false }) => {
|
|
4057
3593
|
return (React__namespace.createElement(mosaic.Box, { pl: 4, mb: 2, mt: 6, textTransform: "uppercase", fontSize: isInResponsiveMode ? 'lg' : 'sm', lineHeight: "relaxed", letterSpacing: "wide", fontWeight: "bold" }, item.title));
|
|
4058
3594
|
});
|
|
4059
3595
|
Divider.displayName = 'Divider';
|
|
3596
|
+
const TOCContainer = React__namespace.memo(({ children, updatedTree }) => {
|
|
3597
|
+
const { setLastActiveIndex } = React__namespace.useContext(ActiveItemContext);
|
|
3598
|
+
React__namespace.useEffect(() => {
|
|
3599
|
+
const firstNode = findFirstNode(updatedTree);
|
|
3600
|
+
if (firstNode) {
|
|
3601
|
+
setLastActiveIndex(firstNode.index);
|
|
3602
|
+
}
|
|
3603
|
+
}, []);
|
|
3604
|
+
return React__namespace.createElement(mosaic.Box, null, children);
|
|
3605
|
+
});
|
|
3606
|
+
TOCContainer.displayName = 'TOCContainer';
|
|
4060
3607
|
const GroupItem = React__namespace.memo(({ item, depth, maxDepthOpenByDefault, isInResponsiveMode, onLinkClick }) => {
|
|
4061
3608
|
if (isExternalLink(item)) {
|
|
4062
3609
|
return (React__namespace.createElement(mosaic.Box, { as: "a", href: item.url, target: "_blank", rel: "noopener noreferrer", display: "block" },
|
|
@@ -4074,9 +3621,24 @@ const GroupItem = React__namespace.memo(({ item, depth, maxDepthOpenByDefault, i
|
|
|
4074
3621
|
});
|
|
4075
3622
|
GroupItem.displayName = 'GroupItem';
|
|
4076
3623
|
const Group = React__namespace.memo(({ depth, item, maxDepthOpenByDefault, isInResponsiveMode, onLinkClick = () => { } }) => {
|
|
4077
|
-
const activeId = React__namespace.useContext(
|
|
3624
|
+
const { activeId, lastActiveIndex } = React__namespace.useContext(ActiveItemContext);
|
|
4078
3625
|
const [isOpen, setIsOpen] = React__namespace.useState(() => isGroupOpenByDefault(depth, item, activeId, maxDepthOpenByDefault));
|
|
4079
|
-
const
|
|
3626
|
+
const isActiveGroup = React__namespace.useCallback((items, activeId, contextIndex) => {
|
|
3627
|
+
return items.some(element => {
|
|
3628
|
+
const hasSlugOrId = 'slug' in element || 'id' in element;
|
|
3629
|
+
const hasItems = 'items' in element && Array.isArray(element.items);
|
|
3630
|
+
if (!hasSlugOrId && !hasItems)
|
|
3631
|
+
return false;
|
|
3632
|
+
if (activeId &&
|
|
3633
|
+
'index' in element &&
|
|
3634
|
+
(element.slug === activeId || element.id === activeId) &&
|
|
3635
|
+
element.index === contextIndex) {
|
|
3636
|
+
return true;
|
|
3637
|
+
}
|
|
3638
|
+
return hasItems ? isActiveGroup(element.items, activeId, contextIndex) : false;
|
|
3639
|
+
});
|
|
3640
|
+
}, []);
|
|
3641
|
+
const hasActive = isActiveGroup(item.items, activeId, lastActiveIndex);
|
|
4080
3642
|
React__namespace.useEffect(() => {
|
|
4081
3643
|
const openByDefault = isGroupOpenByDefault(depth, item, activeId, maxDepthOpenByDefault);
|
|
4082
3644
|
if (isOpen !== openByDefault) {
|
|
@@ -4126,8 +3688,10 @@ const Item = React__namespace.memo(({ depth, isActive, id, title, meta, icon, is
|
|
|
4126
3688
|
});
|
|
4127
3689
|
Item.displayName = 'Item';
|
|
4128
3690
|
const Node = React__namespace.memo(({ item, depth, meta, showAsActive, isInResponsiveMode, onClick, onLinkClick = () => { } }) => {
|
|
4129
|
-
const activeId = React__namespace.useContext(
|
|
4130
|
-
const
|
|
3691
|
+
const { activeId, lastActiveIndex, setLastActiveIndex } = React__namespace.useContext(ActiveItemContext);
|
|
3692
|
+
const { index } = item;
|
|
3693
|
+
const isSlugMatched = activeId === item.slug || activeId === item.id;
|
|
3694
|
+
const isActive = lastActiveIndex === index && isSlugMatched;
|
|
4131
3695
|
const LinkComponent = React__namespace.useContext(LinkContext);
|
|
4132
3696
|
const handleClick = (e) => {
|
|
4133
3697
|
if (isActive) {
|
|
@@ -4135,6 +3699,7 @@ const Node = React__namespace.memo(({ item, depth, meta, showAsActive, isInRespo
|
|
|
4135
3699
|
e.preventDefault();
|
|
4136
3700
|
}
|
|
4137
3701
|
else {
|
|
3702
|
+
setLastActiveIndex(index);
|
|
4138
3703
|
onLinkClick();
|
|
4139
3704
|
}
|
|
4140
3705
|
if (onClick) {
|
|
@@ -4142,7 +3707,7 @@ const Node = React__namespace.memo(({ item, depth, meta, showAsActive, isInRespo
|
|
|
4142
3707
|
}
|
|
4143
3708
|
};
|
|
4144
3709
|
return (React__namespace.createElement(mosaic.Box, { as: LinkComponent, to: resolveRelativeLink(item.slug), display: "block", textDecoration: "no-underline", className: "ElementsTableOfContentsItem" },
|
|
4145
|
-
React__namespace.createElement(Item, { id: getHtmlIdFromItemId(item.slug || item.id), isActive: isActive || showAsActive, depth: depth, title: item.title, icon: NODE_TYPE_TITLE_ICON[item.type] && (React__namespace.createElement(mosaic.Box, { as: mosaic.Icon, color: NODE_TYPE_ICON_COLOR[item.type], icon: NODE_TYPE_TITLE_ICON[item.type] })), meta: meta, isInResponsiveMode: isInResponsiveMode, onClick: handleClick })));
|
|
3710
|
+
React__namespace.createElement(Item, { id: getHtmlIdFromItemId(item.slug || item.id), isActive: isActive || showAsActive, depth: depth, title: item.title, icon: NODE_TYPE_TITLE_ICON[item.type] && (React__namespace.createElement(mosaic.Box, { as: mosaic.Icon, color: NODE_TYPE_ICON_COLOR[item.type], icon: NODE_TYPE_TITLE_ICON[item.type] })), meta: meta, isInResponsiveMode: isInResponsiveMode, onClick: e => handleClick(e) })));
|
|
4146
3711
|
});
|
|
4147
3712
|
Node.displayName = 'Node';
|
|
4148
3713
|
const Version = ({ value }) => {
|