@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.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;
|
|
@@ -1363,8 +1361,50 @@ const booleanOptions = [
|
|
|
1363
1361
|
{ label: 'False', value: 'false' },
|
|
1364
1362
|
{ label: 'True', value: 'true' },
|
|
1365
1363
|
];
|
|
1364
|
+
function encodeSafeSelectorValue(value) {
|
|
1365
|
+
if (typeof value === 'number') {
|
|
1366
|
+
return value;
|
|
1367
|
+
}
|
|
1368
|
+
const hasSpecialChars = /["'\[\]\\(){}]/.test(value);
|
|
1369
|
+
if (!hasSpecialChars) {
|
|
1370
|
+
return value;
|
|
1371
|
+
}
|
|
1372
|
+
try {
|
|
1373
|
+
return 'b64:' + btoa(value);
|
|
1374
|
+
}
|
|
1375
|
+
catch (e) {
|
|
1376
|
+
return 'enc:' + encodeURIComponent(value);
|
|
1377
|
+
}
|
|
1378
|
+
}
|
|
1379
|
+
function decodeSafeSelectorValue(value) {
|
|
1380
|
+
if (typeof value === 'number') {
|
|
1381
|
+
return value;
|
|
1382
|
+
}
|
|
1383
|
+
if (value.startsWith('b64:')) {
|
|
1384
|
+
try {
|
|
1385
|
+
return atob(value.substring(4));
|
|
1386
|
+
}
|
|
1387
|
+
catch (e) {
|
|
1388
|
+
return value;
|
|
1389
|
+
}
|
|
1390
|
+
}
|
|
1391
|
+
if (value.startsWith('enc:')) {
|
|
1392
|
+
try {
|
|
1393
|
+
return decodeURIComponent(value.substring(4));
|
|
1394
|
+
}
|
|
1395
|
+
catch (e) {
|
|
1396
|
+
return value;
|
|
1397
|
+
}
|
|
1398
|
+
}
|
|
1399
|
+
return value;
|
|
1400
|
+
}
|
|
1366
1401
|
function enumOptions(enumValues, required) {
|
|
1367
|
-
const options = map(enumValues, v =>
|
|
1402
|
+
const options = map(enumValues, v => {
|
|
1403
|
+
var _a;
|
|
1404
|
+
const stringValue = typeof v === 'object' && v !== null ? (_a = json.safeStringify(v)) !== null && _a !== void 0 ? _a : String(v) : typeof v === 'number' ? v : String(v);
|
|
1405
|
+
const safeValue = encodeSafeSelectorValue(stringValue);
|
|
1406
|
+
return { value: safeValue, label: String(stringValue) };
|
|
1407
|
+
});
|
|
1368
1408
|
return required ? options : [{ label: 'Not Set', value: '' }, ...options];
|
|
1369
1409
|
}
|
|
1370
1410
|
function parameterOptions(parameter) {
|
|
@@ -1394,15 +1434,16 @@ function parameterSupportsFileUpload(parameter) {
|
|
|
1394
1434
|
((_c = parameter.schema) === null || _c === void 0 ? void 0 : _c.contentMediaType) === 'application/octet-stream'));
|
|
1395
1435
|
}
|
|
1396
1436
|
function stringifyValue(value) {
|
|
1397
|
-
|
|
1437
|
+
var _a;
|
|
1438
|
+
if (typeof value === 'object' && value !== null) {
|
|
1439
|
+
return (_a = json.safeStringify(value)) !== null && _a !== void 0 ? _a : String(value);
|
|
1440
|
+
}
|
|
1441
|
+
return String(value);
|
|
1398
1442
|
}
|
|
1399
1443
|
function exampleValue(example) {
|
|
1400
1444
|
const value = 'value' in example ? example.value : example.externalValue;
|
|
1401
1445
|
return stringifyValue(value);
|
|
1402
1446
|
}
|
|
1403
|
-
function escapeQuotes(value) {
|
|
1404
|
-
return value.replace(/"/g, '\\"');
|
|
1405
|
-
}
|
|
1406
1447
|
function getPlaceholderForParameter(parameter) {
|
|
1407
1448
|
var _a, _b;
|
|
1408
1449
|
const { value: parameterValue, isDefault } = getValueForParameter(parameter);
|
|
@@ -1428,14 +1469,14 @@ const getValueForParameter = (parameter) => {
|
|
|
1428
1469
|
if (typeof defaultValue !== 'undefined') {
|
|
1429
1470
|
return { value: stringifyValue(defaultValue), isDefault: true };
|
|
1430
1471
|
}
|
|
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 : [];
|
|
1472
|
+
const enums = (_b = (_a = parameter.schema) === null || _a === void 0 ? void 0 : _a.enum) !== null && _b !== void 0 ? _b : [];
|
|
1436
1473
|
if (enums.length > 0) {
|
|
1437
1474
|
return { value: stringifyValue(enums[0]) };
|
|
1438
1475
|
}
|
|
1476
|
+
const examples = (_c = parameter.examples) !== null && _c !== void 0 ? _c : [];
|
|
1477
|
+
if (examples.length > 0) {
|
|
1478
|
+
return { value: exampleValue(examples[0]) };
|
|
1479
|
+
}
|
|
1439
1480
|
return { value: '' };
|
|
1440
1481
|
};
|
|
1441
1482
|
const getInitialValueForParameter = (parameter) => {
|
|
@@ -1491,11 +1532,19 @@ const ParameterEditor = ({ parameter, value, onChange, isOptional, onChangeOptio
|
|
|
1491
1532
|
const examples = exampleOptions(parameter);
|
|
1492
1533
|
const selectedExample = (_a = examples === null || examples === void 0 ? void 0 : examples.find(e => e.value === value)) !== null && _a !== void 0 ? _a : selectExampleOption;
|
|
1493
1534
|
const parameterDisplayName = `${parameter.name}${parameter.required ? '*' : ''}`;
|
|
1535
|
+
const encodedValue = React__namespace.useMemo(() => {
|
|
1536
|
+
if (!value || !parameterValueOptions)
|
|
1537
|
+
return value || '';
|
|
1538
|
+
const matchingOption = parameterValueOptions.find(opt => {
|
|
1539
|
+
return String(decodeSafeSelectorValue(opt.value)) === value;
|
|
1540
|
+
});
|
|
1541
|
+
return matchingOption ? String(matchingOption.value) : value;
|
|
1542
|
+
}, [value, parameterValueOptions]);
|
|
1494
1543
|
const requiredButEmpty = validate && parameter.required && !value;
|
|
1495
1544
|
return (React__namespace.createElement(React__namespace.Fragment, null,
|
|
1496
1545
|
React__namespace.createElement(mosaic.Text, { as: "label", "aria-hidden": "true", "data-testid": "param-label", htmlFor: inputId, fontSize: "base" }, parameterDisplayName),
|
|
1497
1546
|
React__namespace.createElement(mosaic.Text, { mx: 3 }, ":"),
|
|
1498
|
-
React__namespace.createElement("div", null, parameterValueOptions ? (React__namespace.createElement(mosaic.Select, { flex: 1, "aria-label": parameter.name, options: parameterValueOptions, value:
|
|
1547
|
+
React__namespace.createElement("div", null, parameterValueOptions ? (React__namespace.createElement(mosaic.Select, { flex: 1, "aria-label": parameter.name, options: parameterValueOptions, value: encodedValue, onChange: val => onChange && onChange(String(decodeSafeSelectorValue(val))), placeholder: getPlaceholderForSelectedParameter(parameter) })) : (React__namespace.createElement(mosaic.Flex, { flex: 1 },
|
|
1499
1548
|
React__namespace.createElement(mosaic.Input, { id: inputId, "aria-label": parameter.name, appearance: requiredButEmpty ? 'default' : 'minimal', flex: 1, placeholder: getPlaceholderForParameter(parameter), type: ((_b = parameter.schema) === null || _b === void 0 ? void 0 : _b.type) === 'number' ? 'number' : 'text', required: true, intent: requiredButEmpty ? 'danger' : 'default', value: value || '', onChange: e => onChange && onChange(e.currentTarget.value) }),
|
|
1500
1549
|
examples && (React__namespace.createElement(mosaic.Select, { "aria-label": `${parameter.name}-select`, flex: 1, value: selectedExample.value, options: examples, onChange: onChange }))))),
|
|
1501
1550
|
canChangeOptional && !parameter.required && (React__namespace.createElement(React__namespace.Fragment, null,
|
|
@@ -2350,10 +2399,17 @@ ServersDropdown.displayName = 'ServersDropdown';
|
|
|
2350
2399
|
|
|
2351
2400
|
const VariableEditor = ({ variable, value, onChange }) => {
|
|
2352
2401
|
const inputId = useUniqueId(`id_${variable.name}_`);
|
|
2402
|
+
const encodedOptions = React__namespace.useMemo(() => (variable.enum ? variable.enum.map(s => ({ value: encodeSafeSelectorValue(s), label: String(s) })) : []), [variable.enum]);
|
|
2403
|
+
const encodedValue = React__namespace.useMemo(() => {
|
|
2404
|
+
if (!value || !variable.enum)
|
|
2405
|
+
return value || variable.default;
|
|
2406
|
+
const matchingOption = encodedOptions.find(opt => decodeSafeSelectorValue(String(opt.value)) === value);
|
|
2407
|
+
return matchingOption ? String(matchingOption.value) : value;
|
|
2408
|
+
}, [value, variable.enum, variable.default, encodedOptions]);
|
|
2353
2409
|
return (React__namespace.createElement(React__namespace.Fragment, null,
|
|
2354
2410
|
React__namespace.createElement(mosaic.Text, { as: "label", "aria-hidden": "true", "data-testid": "param-label", htmlFor: inputId, fontSize: "base" }, variable.name),
|
|
2355
2411
|
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:
|
|
2412
|
+
React__namespace.createElement("div", null, variable.enum ? (React__namespace.createElement(mosaic.Select, { flex: 1, "aria-label": variable.name, options: encodedOptions, value: encodedValue, onChange: val => onChange && onChange(decodeSafeSelectorValue(String(val))) })) : (React__namespace.createElement(mosaic.Flex, { flex: 1 },
|
|
2357
2413
|
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
2414
|
};
|
|
2359
2415
|
|
|
@@ -2761,417 +2817,13 @@ const PanelContent = ({ schemes }) => {
|
|
|
2761
2817
|
})));
|
|
2762
2818
|
};
|
|
2763
2819
|
|
|
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
2820
|
const isBodyEmpty = (body) => {
|
|
3169
2821
|
if (!body)
|
|
3170
2822
|
return true;
|
|
3171
2823
|
const { contents = [], description } = body;
|
|
3172
2824
|
return contents.length === 0 && !(description === null || description === void 0 ? void 0 : description.trim());
|
|
3173
2825
|
};
|
|
3174
|
-
const Body = ({ body, onChange, isHttpWebhookOperation = false
|
|
2826
|
+
const Body = ({ body, onChange, isHttpWebhookOperation = false }) => {
|
|
3175
2827
|
var _a;
|
|
3176
2828
|
const [refResolver, maxRefDepth] = useSchemaInlineRefResolver();
|
|
3177
2829
|
const [chosenContent, setChosenContent] = React__namespace.useState(0);
|
|
@@ -3184,36 +2836,13 @@ const Body = ({ body, onChange, isHttpWebhookOperation = false, disableProps })
|
|
|
3184
2836
|
const { contents = [], description } = body;
|
|
3185
2837
|
const schema = (_a = contents[chosenContent]) === null || _a === void 0 ? void 0 : _a.schema;
|
|
3186
2838
|
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
2839
|
return (React__namespace.createElement(mosaic.VStack, { spacing: 6 },
|
|
3211
2840
|
React__namespace.createElement(SectionSubtitle, { title: "Body", id: "request-body" }, contents.length > 0 && (React__namespace.createElement(mosaic.Flex, { flex: 1, justify: "end" },
|
|
3212
2841
|
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
2842
|
description && (React__namespace.createElement(mosaic.Box, { pos: "relative" },
|
|
3214
2843
|
React__namespace.createElement(MarkdownViewer, { markdown: description }),
|
|
3215
2844
|
React__namespace.createElement(mosaic.NodeAnnotation, { change: descriptionChanged }))),
|
|
3216
|
-
|
|
2845
|
+
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
2846
|
};
|
|
3218
2847
|
Body.displayName = 'HttpOperation.Body';
|
|
3219
2848
|
|
|
@@ -3280,7 +2909,7 @@ const httpOperationParamsToSchema = ({ parameters, parameterType }) => {
|
|
|
3280
2909
|
return schema;
|
|
3281
2910
|
};
|
|
3282
2911
|
|
|
3283
|
-
const Request = ({ operation: { request, request: { path: pathParams = [], headers: headerParams = [], cookie: cookieParams = [], body, query: queryParams = [], } = {}, security, }, hideSecurityInfo, onChange, isHttpWebhookOperation = false,
|
|
2912
|
+
const Request = ({ operation: { request, request: { path: pathParams = [], headers: headerParams = [], cookie: cookieParams = [], body, query: queryParams = [], } = {}, security, }, hideSecurityInfo, onChange, isHttpWebhookOperation = false, }) => {
|
|
3284
2913
|
if (!request || typeof request !== 'object')
|
|
3285
2914
|
return null;
|
|
3286
2915
|
const bodyIsEmpty = isBodyEmpty(body);
|
|
@@ -3308,7 +2937,7 @@ const Request = ({ operation: { request, request: { path: pathParams = [], heade
|
|
|
3308
2937
|
cookieParams.length > 0 && (React__namespace.createElement(mosaic.VStack, { spacing: 5 },
|
|
3309
2938
|
React__namespace.createElement(SectionSubtitle, { title: "Cookies", id: "request-cookies" }),
|
|
3310
2939
|
React__namespace.createElement(Parameters, { parameterType: "cookie", parameters: cookieParams }))),
|
|
3311
|
-
body &&
|
|
2940
|
+
body && React__namespace.createElement(Body, { onChange: onChange, body: body, isHttpWebhookOperation: isHttpWebhookOperation })));
|
|
3312
2941
|
};
|
|
3313
2942
|
Request.displayName = 'HttpOperation.Request';
|
|
3314
2943
|
const schemeExpandedState = utils.atomWithStorage('HttpOperation_security_expanded', {});
|
|
@@ -3339,7 +2968,7 @@ const OptionalMessage$1 = () => {
|
|
|
3339
2968
|
return React__namespace.createElement(mosaic.Callout, { appearance: "outline" }, OptionalSecurityMessage);
|
|
3340
2969
|
};
|
|
3341
2970
|
|
|
3342
|
-
const Responses = ({ responses: unsortedResponses, onStatusCodeChange, onMediaTypeChange, isCompact,
|
|
2971
|
+
const Responses = ({ responses: unsortedResponses, onStatusCodeChange, onMediaTypeChange, isCompact, }) => {
|
|
3343
2972
|
var _a, _b;
|
|
3344
2973
|
const responses = sortBy(uniqBy(unsortedResponses, r => r.code), r => r.code);
|
|
3345
2974
|
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 +3001,11 @@ const Responses = ({ responses: unsortedResponses, onStatusCodeChange, onMediaTy
|
|
|
3372
3001
|
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
3002
|
return (React__namespace.createElement(mosaic.VStack, { spacing: 8, as: mosaic.Tabs, selectedId: activeResponseId, onChange: setActiveResponseId, appearance: "pill" },
|
|
3374
3003
|
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
|
|
3004
|
+
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 },
|
|
3005
|
+
React__namespace.createElement(Response, { response: response, onMediaTypeChange: onMediaTypeChange }))))))));
|
|
3377
3006
|
};
|
|
3378
3007
|
Responses.displayName = 'HttpOperation.Responses';
|
|
3379
|
-
const Response = ({ response, onMediaTypeChange
|
|
3380
|
-
var _a, _b;
|
|
3008
|
+
const Response = ({ response, onMediaTypeChange }) => {
|
|
3381
3009
|
const { contents = [], headers = [], description } = response;
|
|
3382
3010
|
const [chosenContent, setChosenContent] = React__namespace.useState(0);
|
|
3383
3011
|
const [refResolver, maxRefDepth] = useSchemaInlineRefResolver();
|
|
@@ -3388,29 +3016,6 @@ const Response = ({ response, onMediaTypeChange, disableProps, statusCode }) =>
|
|
|
3388
3016
|
responseContent && (onMediaTypeChange === null || onMediaTypeChange === void 0 ? void 0 : onMediaTypeChange(responseContent.mediaType));
|
|
3389
3017
|
}, [responseContent]);
|
|
3390
3018
|
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
3019
|
return (React__namespace.createElement(mosaic.VStack, { spacing: 8, pt: 8 },
|
|
3415
3020
|
description && (React__namespace.createElement(mosaic.Box, { pos: "relative" },
|
|
3416
3021
|
React__namespace.createElement(MarkdownViewer, { markdown: description }),
|
|
@@ -3422,7 +3027,7 @@ const Response = ({ response, onMediaTypeChange, disableProps, statusCode }) =>
|
|
|
3422
3027
|
React__namespace.createElement(SectionSubtitle, { title: "Body", id: "response-body" },
|
|
3423
3028
|
React__namespace.createElement(mosaic.Flex, { flex: 1, justify: "end" },
|
|
3424
3029
|
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 &&
|
|
3030
|
+
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
3031
|
};
|
|
3427
3032
|
Response.displayName = 'HttpOperation.Response';
|
|
3428
3033
|
const codeToIntentVal = (code) => {
|
|
@@ -3471,7 +3076,7 @@ const Callback = ({ data, isCompact }) => {
|
|
|
3471
3076
|
};
|
|
3472
3077
|
Callbacks.displayName = 'HttpOperation.Callback';
|
|
3473
3078
|
|
|
3474
|
-
const HttpOperationComponent = React__namespace.memo(({ className, data: unresolvedData, layoutOptions, tryItCredentialsPolicy, tryItCorsProxy
|
|
3079
|
+
const HttpOperationComponent = React__namespace.memo(({ className, data: unresolvedData, layoutOptions, tryItCredentialsPolicy, tryItCorsProxy }) => {
|
|
3475
3080
|
var _a;
|
|
3476
3081
|
const { nodeHasChanged } = useOptionsCtx();
|
|
3477
3082
|
const data = useResolvedObject(unresolvedData);
|
|
@@ -3502,11 +3107,11 @@ const HttpOperationComponent = React__namespace.memo(({ className, data: unresol
|
|
|
3502
3107
|
React__namespace.createElement(MarkdownViewer, { className: "HttpOperation__Description", markdown: data.description }),
|
|
3503
3108
|
React__namespace.createElement(mosaic.NodeAnnotation, { change: descriptionChanged }))),
|
|
3504
3109
|
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
|
|
3110
|
+
React__namespace.createElement(Request, { onChange: setTextRequestBodyIndex, operation: data, hideSecurityInfo: layoutOptions === null || layoutOptions === void 0 ? void 0 : layoutOptions.hideSecurityInfo, isHttpWebhookOperation: isHttpWebhookOperation(data) }),
|
|
3111
|
+
data.responses && (React__namespace.createElement(Responses, { responses: data.responses, onMediaTypeChange: setResponseMediaType, onStatusCodeChange: setResponseStatusCode, isCompact: isCompact })),
|
|
3507
3112
|
((_a = data.callbacks) === null || _a === void 0 ? void 0 : _a.length) ? React__namespace.createElement(Callbacks, { callbacks: data.callbacks, isCompact: isCompact }) : null,
|
|
3508
3113
|
isCompact && tryItPanel));
|
|
3509
|
-
return (React__namespace.createElement(TwoColumnLayout, { ref: layoutRef, className: cn('HttpOperation', className), header: header, left: description, right: !
|
|
3114
|
+
return (React__namespace.createElement(TwoColumnLayout, { ref: layoutRef, className: cn('HttpOperation', className), header: header, left: description, right: !isCompact && tryItPanel }));
|
|
3510
3115
|
});
|
|
3511
3116
|
HttpOperationComponent.displayName = 'HttpOperation.Component';
|
|
3512
3117
|
const HttpOperation = reactErrorBoundary.withErrorBoundary(HttpOperationComponent, {
|
|
@@ -3757,7 +3362,7 @@ const HttpServiceComponent = React__namespace.memo(({ data: unresolvedData, loca
|
|
|
3757
3362
|
HttpServiceComponent.displayName = 'HttpService.Component';
|
|
3758
3363
|
const HttpService = reactErrorBoundary.withErrorBoundary(HttpServiceComponent, { recoverableProps: ['data'] });
|
|
3759
3364
|
|
|
3760
|
-
const ModelComponent = ({ data: unresolvedData, className, nodeTitle, layoutOptions, exportProps,
|
|
3365
|
+
const ModelComponent = ({ data: unresolvedData, className, nodeTitle, layoutOptions, exportProps, }) => {
|
|
3761
3366
|
var _a, _b;
|
|
3762
3367
|
const [resolveRef, maxRefDepth] = useSchemaInlineRefResolver();
|
|
3763
3368
|
const data = useResolvedObject(unresolvedData);
|
|
@@ -3780,40 +3385,14 @@ const ModelComponent = ({ data: unresolvedData, className, nodeTitle, layoutOpti
|
|
|
3780
3385
|
exportProps && !(layoutOptions === null || layoutOptions === void 0 ? void 0 : layoutOptions.hideExport) && !isCompact && React__namespace.createElement(ExportButton, Object.assign({}, exportProps))));
|
|
3781
3386
|
const modelExamples = !(layoutOptions === null || layoutOptions === void 0 ? void 0 : layoutOptions.hideModelExamples) && React__namespace.createElement(ModelExamples, { data: data, isCollapsible: isCompact });
|
|
3782
3387
|
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
3388
|
const description = (React__namespace.createElement(mosaic.VStack, { spacing: 10 },
|
|
3810
3389
|
data.description && data.type === 'object' && (React__namespace.createElement(mosaic.Box, { pos: "relative" },
|
|
3811
3390
|
React__namespace.createElement(MarkdownViewer, { role: "textbox", markdown: data.description }),
|
|
3812
3391
|
React__namespace.createElement(mosaic.NodeAnnotation, { change: descriptionChanged }))),
|
|
3813
3392
|
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: !
|
|
3393
|
+
isCompact && modelExamples,
|
|
3394
|
+
React__namespace.createElement(jsonSchemaViewer.JsonSchemaViewer, { resolveRef: resolveRef, maxRefDepth: maxRefDepth, schema: getOriginalObject(data), nodeHasChanged: nodeHasChanged, renderExtensionAddon: renderExtensionAddon, skipTopLevelDescription: true })));
|
|
3395
|
+
return (React__namespace.createElement(TwoColumnLayout, { ref: layoutRef, className: cn('Model', className), header: header, left: description, right: !isCompact && modelExamples }));
|
|
3817
3396
|
};
|
|
3818
3397
|
const ModelExamples = React__namespace.memo(({ data, isCollapsible = false }) => {
|
|
3819
3398
|
var _a;
|
|
@@ -3835,41 +3414,30 @@ const Model = reactErrorBoundary.withErrorBoundary(ModelComponent, { recoverable
|
|
|
3835
3414
|
|
|
3836
3415
|
const Docs = React__namespace.memo((_a) => {
|
|
3837
3416
|
var _b;
|
|
3838
|
-
var { nodeType, nodeData,
|
|
3417
|
+
var { nodeType, nodeData, useNodeForRefResolving = false, refResolver, maxRefDepth, nodeHasChanged, renderExtensionAddon } = _a, commonProps = tslib.__rest(_a, ["nodeType", "nodeData", "useNodeForRefResolving", "refResolver", "maxRefDepth", "nodeHasChanged", "renderExtensionAddon"]);
|
|
3839
3418
|
const parsedNode = useParsedData(nodeType, nodeData);
|
|
3840
3419
|
if (!parsedNode) {
|
|
3841
3420
|
(_b = commonProps.nodeUnsupported) === null || _b === void 0 ? void 0 : _b.call(commonProps, 'dataEmpty');
|
|
3842
3421
|
return null;
|
|
3843
3422
|
}
|
|
3844
|
-
let elem = React__namespace.createElement(ParsedDocs, Object.assign({ node: parsedNode
|
|
3423
|
+
let elem = React__namespace.createElement(ParsedDocs, Object.assign({ node: parsedNode }, commonProps));
|
|
3845
3424
|
if (useNodeForRefResolving) {
|
|
3846
3425
|
elem = (React__namespace.createElement(InlineRefResolverProvider, { document: parsedNode.data, resolver: refResolver, maxRefDepth: maxRefDepth }, elem));
|
|
3847
3426
|
}
|
|
3848
3427
|
return (React__namespace.createElement(ElementsOptionsProvider, { nodeHasChanged: nodeHasChanged, renderExtensionAddon: renderExtensionAddon }, elem));
|
|
3849
3428
|
});
|
|
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
3429
|
const ParsedDocs = (_a) => {
|
|
3861
|
-
var { node, nodeUnsupported
|
|
3862
|
-
const { hideOperationTryIt, hideModelTryIt } = getTryItVisibility(disableProps);
|
|
3430
|
+
var { node, nodeUnsupported } = _a, commonProps = tslib.__rest(_a, ["node", "nodeUnsupported"]);
|
|
3863
3431
|
switch (node.type) {
|
|
3864
3432
|
case 'article':
|
|
3865
3433
|
return React__namespace.createElement(Article, Object.assign({ data: node.data }, commonProps));
|
|
3866
3434
|
case 'http_operation':
|
|
3867
3435
|
case 'http_webhook':
|
|
3868
|
-
return React__namespace.createElement(HttpOperation, Object.assign({ data: node.data
|
|
3436
|
+
return React__namespace.createElement(HttpOperation, Object.assign({ data: node.data }, commonProps));
|
|
3869
3437
|
case 'http_service':
|
|
3870
3438
|
return React__namespace.createElement(HttpService, Object.assign({ data: node.data }, commonProps));
|
|
3871
3439
|
case 'model':
|
|
3872
|
-
return React__namespace.createElement(Model, Object.assign({ data: node.data
|
|
3440
|
+
return React__namespace.createElement(Model, Object.assign({ data: node.data }, commonProps));
|
|
3873
3441
|
default:
|
|
3874
3442
|
nodeUnsupported === null || nodeUnsupported === void 0 ? void 0 : nodeUnsupported('invalidType');
|
|
3875
3443
|
return null;
|
|
@@ -4007,7 +3575,7 @@ function findFirstNode(items) {
|
|
|
4007
3575
|
return;
|
|
4008
3576
|
}
|
|
4009
3577
|
function isDivider(item) {
|
|
4010
|
-
return Object.keys(item).length ===
|
|
3578
|
+
return Object.keys(item).length === 2 && 'title' in item && 'index' in item;
|
|
4011
3579
|
}
|
|
4012
3580
|
function isGroup(item) {
|
|
4013
3581
|
return Object.keys(item).length >= 2 && 'title' in item && 'items' in item;
|
|
@@ -4019,13 +3587,33 @@ function isNode(item) {
|
|
|
4019
3587
|
return 'title' in item && 'slug' in item && 'id' in item && 'meta' in item && 'type' in item;
|
|
4020
3588
|
}
|
|
4021
3589
|
function isExternalLink(item) {
|
|
4022
|
-
return Object.keys(item).length ===
|
|
3590
|
+
return Object.keys(item).length === 3 && 'title' in item && 'url' in item && 'index' in item;
|
|
4023
3591
|
}
|
|
4024
3592
|
|
|
4025
|
-
const
|
|
3593
|
+
const ActiveItemContext = React__namespace.createContext({
|
|
3594
|
+
activeId: undefined,
|
|
3595
|
+
lastActiveIndex: '',
|
|
3596
|
+
setLastActiveIndex: () => { },
|
|
3597
|
+
});
|
|
4026
3598
|
const LinkContext = React__namespace.createContext(undefined);
|
|
4027
3599
|
LinkContext.displayName = 'LinkContext';
|
|
4028
3600
|
const TableOfContents = React__namespace.memo(({ tree, activeId, Link, maxDepthOpenByDefault, externalScrollbar = false, isInResponsiveMode = false, onLinkClick, }) => {
|
|
3601
|
+
const [lastActiveIndex, setLastActiveIndex] = React.useState('');
|
|
3602
|
+
const value = React__namespace.useMemo(() => ({
|
|
3603
|
+
lastActiveIndex,
|
|
3604
|
+
setLastActiveIndex,
|
|
3605
|
+
activeId,
|
|
3606
|
+
}), [lastActiveIndex, activeId]);
|
|
3607
|
+
const updateTocTree = React__namespace.useCallback((arr, parentId) => {
|
|
3608
|
+
return arr.map((item, key) => {
|
|
3609
|
+
let newItem = Object.assign(Object.assign({}, item), { index: parentId + key + '-' });
|
|
3610
|
+
if (isGroup(item) || isNodeGroup(item)) {
|
|
3611
|
+
newItem.items = updateTocTree(item.items, parentId + key + '-');
|
|
3612
|
+
}
|
|
3613
|
+
return newItem;
|
|
3614
|
+
});
|
|
3615
|
+
}, []);
|
|
3616
|
+
const updatedTree = updateTocTree(tree, '');
|
|
4029
3617
|
const container = React__namespace.useRef(null);
|
|
4030
3618
|
const child = React__namespace.useRef(null);
|
|
4031
3619
|
const firstRender = useFirstRender();
|
|
@@ -4045,18 +3633,30 @@ const TableOfContents = React__namespace.memo(({ tree, activeId, Link, maxDepthO
|
|
|
4045
3633
|
return (React__namespace.createElement(mosaic.Box, { ref: container, w: "full", bg: isInResponsiveMode ? 'canvas' : 'canvas-100', overflowY: "auto" },
|
|
4046
3634
|
React__namespace.createElement(mosaic.Box, { ref: child, my: 3 },
|
|
4047
3635
|
React__namespace.createElement(LinkContext.Provider, { value: Link },
|
|
4048
|
-
React__namespace.createElement(
|
|
4049
|
-
|
|
4050
|
-
|
|
4051
|
-
|
|
4052
|
-
|
|
4053
|
-
|
|
3636
|
+
React__namespace.createElement(ActiveItemContext.Provider, { value: value },
|
|
3637
|
+
React__namespace.createElement(TOCContainer, { updatedTree: updatedTree }, updatedTree.map((item, key) => {
|
|
3638
|
+
if (isDivider(item)) {
|
|
3639
|
+
return React__namespace.createElement(Divider, { key: key, item: item, isInResponsiveMode: isInResponsiveMode });
|
|
3640
|
+
}
|
|
3641
|
+
return (React__namespace.createElement(GroupItem, { key: key, item: item, depth: 0, maxDepthOpenByDefault: maxDepthOpenByDefault, onLinkClick: onLinkClick, isInResponsiveMode: isInResponsiveMode }));
|
|
3642
|
+
})))))));
|
|
4054
3643
|
});
|
|
4055
3644
|
TableOfContents.displayName = 'TableOfContents';
|
|
4056
3645
|
const Divider = React__namespace.memo(({ item, isInResponsiveMode = false }) => {
|
|
4057
3646
|
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
3647
|
});
|
|
4059
3648
|
Divider.displayName = 'Divider';
|
|
3649
|
+
const TOCContainer = React__namespace.memo(({ children, updatedTree }) => {
|
|
3650
|
+
const { setLastActiveIndex } = React__namespace.useContext(ActiveItemContext);
|
|
3651
|
+
React__namespace.useEffect(() => {
|
|
3652
|
+
const firstNode = findFirstNode(updatedTree);
|
|
3653
|
+
if (firstNode) {
|
|
3654
|
+
setLastActiveIndex(firstNode.index);
|
|
3655
|
+
}
|
|
3656
|
+
}, []);
|
|
3657
|
+
return React__namespace.createElement(mosaic.Box, null, children);
|
|
3658
|
+
});
|
|
3659
|
+
TOCContainer.displayName = 'TOCContainer';
|
|
4060
3660
|
const GroupItem = React__namespace.memo(({ item, depth, maxDepthOpenByDefault, isInResponsiveMode, onLinkClick }) => {
|
|
4061
3661
|
if (isExternalLink(item)) {
|
|
4062
3662
|
return (React__namespace.createElement(mosaic.Box, { as: "a", href: item.url, target: "_blank", rel: "noopener noreferrer", display: "block" },
|
|
@@ -4074,9 +3674,24 @@ const GroupItem = React__namespace.memo(({ item, depth, maxDepthOpenByDefault, i
|
|
|
4074
3674
|
});
|
|
4075
3675
|
GroupItem.displayName = 'GroupItem';
|
|
4076
3676
|
const Group = React__namespace.memo(({ depth, item, maxDepthOpenByDefault, isInResponsiveMode, onLinkClick = () => { } }) => {
|
|
4077
|
-
const activeId = React__namespace.useContext(
|
|
3677
|
+
const { activeId, lastActiveIndex } = React__namespace.useContext(ActiveItemContext);
|
|
4078
3678
|
const [isOpen, setIsOpen] = React__namespace.useState(() => isGroupOpenByDefault(depth, item, activeId, maxDepthOpenByDefault));
|
|
4079
|
-
const
|
|
3679
|
+
const isActiveGroup = React__namespace.useCallback((items, activeId, contextIndex) => {
|
|
3680
|
+
return items.some(element => {
|
|
3681
|
+
const hasSlugOrId = 'slug' in element || 'id' in element;
|
|
3682
|
+
const hasItems = 'items' in element && Array.isArray(element.items);
|
|
3683
|
+
if (!hasSlugOrId && !hasItems)
|
|
3684
|
+
return false;
|
|
3685
|
+
if (activeId &&
|
|
3686
|
+
'index' in element &&
|
|
3687
|
+
(element.slug === activeId || element.id === activeId) &&
|
|
3688
|
+
element.index === contextIndex) {
|
|
3689
|
+
return true;
|
|
3690
|
+
}
|
|
3691
|
+
return hasItems ? isActiveGroup(element.items, activeId, contextIndex) : false;
|
|
3692
|
+
});
|
|
3693
|
+
}, []);
|
|
3694
|
+
const hasActive = isActiveGroup(item.items, activeId, lastActiveIndex);
|
|
4080
3695
|
React__namespace.useEffect(() => {
|
|
4081
3696
|
const openByDefault = isGroupOpenByDefault(depth, item, activeId, maxDepthOpenByDefault);
|
|
4082
3697
|
if (isOpen !== openByDefault) {
|
|
@@ -4126,8 +3741,10 @@ const Item = React__namespace.memo(({ depth, isActive, id, title, meta, icon, is
|
|
|
4126
3741
|
});
|
|
4127
3742
|
Item.displayName = 'Item';
|
|
4128
3743
|
const Node = React__namespace.memo(({ item, depth, meta, showAsActive, isInResponsiveMode, onClick, onLinkClick = () => { } }) => {
|
|
4129
|
-
const activeId = React__namespace.useContext(
|
|
4130
|
-
const
|
|
3744
|
+
const { activeId, lastActiveIndex, setLastActiveIndex } = React__namespace.useContext(ActiveItemContext);
|
|
3745
|
+
const { index } = item;
|
|
3746
|
+
const isSlugMatched = activeId === item.slug || activeId === item.id;
|
|
3747
|
+
const isActive = lastActiveIndex === index && isSlugMatched;
|
|
4131
3748
|
const LinkComponent = React__namespace.useContext(LinkContext);
|
|
4132
3749
|
const handleClick = (e) => {
|
|
4133
3750
|
if (isActive) {
|
|
@@ -4135,6 +3752,7 @@ const Node = React__namespace.memo(({ item, depth, meta, showAsActive, isInRespo
|
|
|
4135
3752
|
e.preventDefault();
|
|
4136
3753
|
}
|
|
4137
3754
|
else {
|
|
3755
|
+
setLastActiveIndex(index);
|
|
4138
3756
|
onLinkClick();
|
|
4139
3757
|
}
|
|
4140
3758
|
if (onClick) {
|
|
@@ -4142,7 +3760,7 @@ const Node = React__namespace.memo(({ item, depth, meta, showAsActive, isInRespo
|
|
|
4142
3760
|
}
|
|
4143
3761
|
};
|
|
4144
3762
|
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 })));
|
|
3763
|
+
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
3764
|
});
|
|
4147
3765
|
Node.displayName = 'Node';
|
|
4148
3766
|
const Version = ({ value }) => {
|