@stoplight/elements-core 9.0.13-beta-0.3 → 9.0.13-beta-0.4

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/index.esm.js CHANGED
@@ -2870,6 +2870,63 @@ const LazySchemaTreePreviewer = ({ schema, root = schema, title, level = 1, path
2870
2870
  const thisNodeRequiredOverride = isRequiredOverride(path, hideData);
2871
2871
  const shouldHideAllChildren = (isRoot && hideData.some(h => trimSlashes(h.path) === 'properties' && h.required === undefined)) ||
2872
2872
  (!isRoot && isPropertiesAllHidden(path, hideData));
2873
+ const hasExpandableChildren = useMemo(() => {
2874
+ var _a;
2875
+ if (shouldHideAllChildren)
2876
+ return false;
2877
+ 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))) {
2878
+ let props = schema === null || schema === void 0 ? void 0 : schema.properties;
2879
+ if (schema === null || schema === void 0 ? void 0 : schema.allOf) {
2880
+ schema === null || schema === void 0 ? void 0 : schema.allOf.forEach((item) => {
2881
+ props = Object.assign(Object.assign({}, props), item.properties);
2882
+ });
2883
+ }
2884
+ if ((schema === null || schema === void 0 ? void 0 : schema.anyOf) && (schema === null || schema === void 0 ? void 0 : schema.anyOf.length) > 0) {
2885
+ const selectedSchema = (schema === null || schema === void 0 ? void 0 : schema.anyOf[selectedSchemaIndex]) || (schema === null || schema === void 0 ? void 0 : schema.anyOf[0]);
2886
+ props = Object.assign(Object.assign({}, props), selectedSchema.properties);
2887
+ }
2888
+ if ((schema === null || schema === void 0 ? void 0 : schema.oneOf) && (schema === null || schema === void 0 ? void 0 : schema.oneOf.length) > 0) {
2889
+ const selectedSchema = (schema === null || schema === void 0 ? void 0 : schema.oneOf[selectedSchemaIndex]) || (schema === null || schema === void 0 ? void 0 : schema.oneOf[0]);
2890
+ props = Object.assign(Object.assign({}, props), selectedSchema.properties);
2891
+ }
2892
+ if (props && Object.keys(props).length > 0) {
2893
+ for (const [key] of Object.entries(props)) {
2894
+ const childPath = `${path}/properties/${key}`;
2895
+ const childRequiredOverride = isRequiredOverride(childPath, hideData);
2896
+ const shouldHideChild = isPathHidden(childPath, hideData, complexData) && childRequiredOverride === undefined;
2897
+ if (!shouldHideChild)
2898
+ return true;
2899
+ }
2900
+ }
2901
+ }
2902
+ if ((schema === null || schema === void 0 ? void 0 : schema.type) === 'array' &&
2903
+ (schema === null || schema === void 0 ? void 0 : schema.items) &&
2904
+ Object.keys(schema === null || schema === void 0 ? void 0 : schema.items).length > 0 &&
2905
+ !((_a = schema === null || schema === void 0 ? void 0 : schema.items) === null || _a === void 0 ? void 0 : _a.circular)) {
2906
+ const resolvedItems = dereference(schema === null || schema === void 0 ? void 0 : schema.items, root);
2907
+ const itemsPath = `${path}/items`;
2908
+ if (resolvedItems && resolvedItems.type === 'object' && resolvedItems.properties) {
2909
+ for (const [key] of Object.entries(resolvedItems.properties)) {
2910
+ const childPath = `${itemsPath}/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
+ else if (resolvedItems &&
2918
+ resolvedItems.type === 'array' &&
2919
+ resolvedItems.items &&
2920
+ resolvedItems.items.length > 0) {
2921
+ const childPath = `${path}/items`;
2922
+ const childRequiredOverride = isRequiredOverride(childPath, hideData);
2923
+ const shouldHideChild = isPathHidden(childPath, hideData, complexData) && childRequiredOverride === undefined;
2924
+ if (!shouldHideChild)
2925
+ return true;
2926
+ }
2927
+ }
2928
+ return false;
2929
+ }, [schema, path, hideData, complexData, shouldHideAllChildren, root, selectedSchemaIndex]);
2873
2930
  const shouldHideNode = useMemo(() => {
2874
2931
  if (isRoot)
2875
2932
  return false;
@@ -3020,9 +3077,10 @@ const LazySchemaTreePreviewer = ({ schema, root = schema, title, level = 1, path
3020
3077
  return (React__default.createElement("div", { className: "mb-1" },
3021
3078
  React__default.createElement(Flex, { maxW: "full", pl: 3, py: 2, "data-test": "schema-row", pos: "relative" },
3022
3079
  React__default.createElement(VStack, { spacing: 1, maxW: "full", className: "w-full" },
3023
- React__default.createElement(Flex, { onClick: !isRoot ? handleToggle : undefined, className: `w-full ${isRoot ? '' : 'cursor-pointer'}` },
3080
+ React__default.createElement(Flex, { onClick: !isRoot ? handleToggle : undefined, className: `w-full ${(isRoot || !hasExpandableChildren) ? '' : 'cursor-pointer'}` },
3024
3081
  !isRoot ? (React__default.createElement(Box, { mr: 2, className: "sl-font-mono sl-font-semibold sl-mr-2" },
3025
- !TYPES.includes(schema === null || schema === void 0 ? void 0 : schema.type) &&
3082
+ hasExpandableChildren &&
3083
+ !TYPES.includes(schema === null || schema === void 0 ? void 0 : schema.type) &&
3026
3084
  !detectCircularPath(path) &&
3027
3085
  !((_b = schema === null || schema === void 0 ? void 0 : schema.items) === null || _b === void 0 ? void 0 : _b.circular) &&
3028
3086
  !(schema === null || schema === void 0 ? void 0 : schema.circular) ? (React__default.createElement("i", { role: "img", "aria-hidden": "true", className: `sl-icon fal ${expanded ? 'fa-chevron-down' : 'fa-chevron-right'} fa-fw fa-sm` })) : (React__default.createElement("span", { className: "sl-icon fal fa-fw fa-sm", "aria-hidden": "true" })),
package/index.js CHANGED
@@ -2892,6 +2892,63 @@ const LazySchemaTreePreviewer = ({ schema, root = schema, title, level = 1, path
2892
2892
  const thisNodeRequiredOverride = isRequiredOverride(path, hideData);
2893
2893
  const shouldHideAllChildren = (isRoot && hideData.some(h => trimSlashes(h.path) === 'properties' && h.required === undefined)) ||
2894
2894
  (!isRoot && isPropertiesAllHidden(path, hideData));
2895
+ const hasExpandableChildren = React.useMemo(() => {
2896
+ var _a;
2897
+ if (shouldHideAllChildren)
2898
+ return false;
2899
+ 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))) {
2900
+ let props = schema === null || schema === void 0 ? void 0 : schema.properties;
2901
+ if (schema === null || schema === void 0 ? void 0 : schema.allOf) {
2902
+ schema === null || schema === void 0 ? void 0 : schema.allOf.forEach((item) => {
2903
+ props = Object.assign(Object.assign({}, props), item.properties);
2904
+ });
2905
+ }
2906
+ if ((schema === null || schema === void 0 ? void 0 : schema.anyOf) && (schema === null || schema === void 0 ? void 0 : schema.anyOf.length) > 0) {
2907
+ const selectedSchema = (schema === null || schema === void 0 ? void 0 : schema.anyOf[selectedSchemaIndex]) || (schema === null || schema === void 0 ? void 0 : schema.anyOf[0]);
2908
+ props = Object.assign(Object.assign({}, props), selectedSchema.properties);
2909
+ }
2910
+ if ((schema === null || schema === void 0 ? void 0 : schema.oneOf) && (schema === null || schema === void 0 ? void 0 : schema.oneOf.length) > 0) {
2911
+ const selectedSchema = (schema === null || schema === void 0 ? void 0 : schema.oneOf[selectedSchemaIndex]) || (schema === null || schema === void 0 ? void 0 : schema.oneOf[0]);
2912
+ props = Object.assign(Object.assign({}, props), selectedSchema.properties);
2913
+ }
2914
+ if (props && Object.keys(props).length > 0) {
2915
+ for (const [key] of Object.entries(props)) {
2916
+ const childPath = `${path}/properties/${key}`;
2917
+ const childRequiredOverride = isRequiredOverride(childPath, hideData);
2918
+ const shouldHideChild = isPathHidden(childPath, hideData, complexData) && childRequiredOverride === undefined;
2919
+ if (!shouldHideChild)
2920
+ return true;
2921
+ }
2922
+ }
2923
+ }
2924
+ if ((schema === null || schema === void 0 ? void 0 : schema.type) === 'array' &&
2925
+ (schema === null || schema === void 0 ? void 0 : schema.items) &&
2926
+ Object.keys(schema === null || schema === void 0 ? void 0 : schema.items).length > 0 &&
2927
+ !((_a = schema === null || schema === void 0 ? void 0 : schema.items) === null || _a === void 0 ? void 0 : _a.circular)) {
2928
+ const resolvedItems = dereference(schema === null || schema === void 0 ? void 0 : schema.items, root);
2929
+ const itemsPath = `${path}/items`;
2930
+ if (resolvedItems && resolvedItems.type === 'object' && resolvedItems.properties) {
2931
+ for (const [key] of Object.entries(resolvedItems.properties)) {
2932
+ const childPath = `${itemsPath}/properties/${key}`;
2933
+ const childRequiredOverride = isRequiredOverride(childPath, hideData);
2934
+ const shouldHideChild = isPathHidden(childPath, hideData, complexData) && childRequiredOverride === undefined;
2935
+ if (!shouldHideChild)
2936
+ return true;
2937
+ }
2938
+ }
2939
+ else if (resolvedItems &&
2940
+ resolvedItems.type === 'array' &&
2941
+ resolvedItems.items &&
2942
+ resolvedItems.items.length > 0) {
2943
+ const childPath = `${path}/items`;
2944
+ const childRequiredOverride = isRequiredOverride(childPath, hideData);
2945
+ const shouldHideChild = isPathHidden(childPath, hideData, complexData) && childRequiredOverride === undefined;
2946
+ if (!shouldHideChild)
2947
+ return true;
2948
+ }
2949
+ }
2950
+ return false;
2951
+ }, [schema, path, hideData, complexData, shouldHideAllChildren, root, selectedSchemaIndex]);
2895
2952
  const shouldHideNode = React.useMemo(() => {
2896
2953
  if (isRoot)
2897
2954
  return false;
@@ -3042,9 +3099,10 @@ const LazySchemaTreePreviewer = ({ schema, root = schema, title, level = 1, path
3042
3099
  return (React.createElement("div", { className: "mb-1" },
3043
3100
  React.createElement(mosaic.Flex, { maxW: "full", pl: 3, py: 2, "data-test": "schema-row", pos: "relative" },
3044
3101
  React.createElement(mosaic.VStack, { spacing: 1, maxW: "full", className: "w-full" },
3045
- React.createElement(mosaic.Flex, { onClick: !isRoot ? handleToggle : undefined, className: `w-full ${isRoot ? '' : 'cursor-pointer'}` },
3102
+ React.createElement(mosaic.Flex, { onClick: !isRoot ? handleToggle : undefined, className: `w-full ${(isRoot || !hasExpandableChildren) ? '' : 'cursor-pointer'}` },
3046
3103
  !isRoot ? (React.createElement(mosaic.Box, { mr: 2, className: "sl-font-mono sl-font-semibold sl-mr-2" },
3047
- !TYPES.includes(schema === null || schema === void 0 ? void 0 : schema.type) &&
3104
+ hasExpandableChildren &&
3105
+ !TYPES.includes(schema === null || schema === void 0 ? void 0 : schema.type) &&
3048
3106
  !detectCircularPath(path) &&
3049
3107
  !((_b = schema === null || schema === void 0 ? void 0 : schema.items) === null || _b === void 0 ? void 0 : _b.circular) &&
3050
3108
  !(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" })),
package/index.mjs CHANGED
@@ -2870,6 +2870,63 @@ const LazySchemaTreePreviewer = ({ schema, root = schema, title, level = 1, path
2870
2870
  const thisNodeRequiredOverride = isRequiredOverride(path, hideData);
2871
2871
  const shouldHideAllChildren = (isRoot && hideData.some(h => trimSlashes(h.path) === 'properties' && h.required === undefined)) ||
2872
2872
  (!isRoot && isPropertiesAllHidden(path, hideData));
2873
+ const hasExpandableChildren = useMemo(() => {
2874
+ var _a;
2875
+ if (shouldHideAllChildren)
2876
+ return false;
2877
+ 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))) {
2878
+ let props = schema === null || schema === void 0 ? void 0 : schema.properties;
2879
+ if (schema === null || schema === void 0 ? void 0 : schema.allOf) {
2880
+ schema === null || schema === void 0 ? void 0 : schema.allOf.forEach((item) => {
2881
+ props = Object.assign(Object.assign({}, props), item.properties);
2882
+ });
2883
+ }
2884
+ if ((schema === null || schema === void 0 ? void 0 : schema.anyOf) && (schema === null || schema === void 0 ? void 0 : schema.anyOf.length) > 0) {
2885
+ const selectedSchema = (schema === null || schema === void 0 ? void 0 : schema.anyOf[selectedSchemaIndex]) || (schema === null || schema === void 0 ? void 0 : schema.anyOf[0]);
2886
+ props = Object.assign(Object.assign({}, props), selectedSchema.properties);
2887
+ }
2888
+ if ((schema === null || schema === void 0 ? void 0 : schema.oneOf) && (schema === null || schema === void 0 ? void 0 : schema.oneOf.length) > 0) {
2889
+ const selectedSchema = (schema === null || schema === void 0 ? void 0 : schema.oneOf[selectedSchemaIndex]) || (schema === null || schema === void 0 ? void 0 : schema.oneOf[0]);
2890
+ props = Object.assign(Object.assign({}, props), selectedSchema.properties);
2891
+ }
2892
+ if (props && Object.keys(props).length > 0) {
2893
+ for (const [key] of Object.entries(props)) {
2894
+ const childPath = `${path}/properties/${key}`;
2895
+ const childRequiredOverride = isRequiredOverride(childPath, hideData);
2896
+ const shouldHideChild = isPathHidden(childPath, hideData, complexData) && childRequiredOverride === undefined;
2897
+ if (!shouldHideChild)
2898
+ return true;
2899
+ }
2900
+ }
2901
+ }
2902
+ if ((schema === null || schema === void 0 ? void 0 : schema.type) === 'array' &&
2903
+ (schema === null || schema === void 0 ? void 0 : schema.items) &&
2904
+ Object.keys(schema === null || schema === void 0 ? void 0 : schema.items).length > 0 &&
2905
+ !((_a = schema === null || schema === void 0 ? void 0 : schema.items) === null || _a === void 0 ? void 0 : _a.circular)) {
2906
+ const resolvedItems = dereference(schema === null || schema === void 0 ? void 0 : schema.items, root);
2907
+ const itemsPath = `${path}/items`;
2908
+ if (resolvedItems && resolvedItems.type === 'object' && resolvedItems.properties) {
2909
+ for (const [key] of Object.entries(resolvedItems.properties)) {
2910
+ const childPath = `${itemsPath}/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
+ else if (resolvedItems &&
2918
+ resolvedItems.type === 'array' &&
2919
+ resolvedItems.items &&
2920
+ resolvedItems.items.length > 0) {
2921
+ const childPath = `${path}/items`;
2922
+ const childRequiredOverride = isRequiredOverride(childPath, hideData);
2923
+ const shouldHideChild = isPathHidden(childPath, hideData, complexData) && childRequiredOverride === undefined;
2924
+ if (!shouldHideChild)
2925
+ return true;
2926
+ }
2927
+ }
2928
+ return false;
2929
+ }, [schema, path, hideData, complexData, shouldHideAllChildren, root, selectedSchemaIndex]);
2873
2930
  const shouldHideNode = useMemo(() => {
2874
2931
  if (isRoot)
2875
2932
  return false;
@@ -3020,9 +3077,10 @@ const LazySchemaTreePreviewer = ({ schema, root = schema, title, level = 1, path
3020
3077
  return (React__default.createElement("div", { className: "mb-1" },
3021
3078
  React__default.createElement(Flex, { maxW: "full", pl: 3, py: 2, "data-test": "schema-row", pos: "relative" },
3022
3079
  React__default.createElement(VStack, { spacing: 1, maxW: "full", className: "w-full" },
3023
- React__default.createElement(Flex, { onClick: !isRoot ? handleToggle : undefined, className: `w-full ${isRoot ? '' : 'cursor-pointer'}` },
3080
+ React__default.createElement(Flex, { onClick: !isRoot ? handleToggle : undefined, className: `w-full ${(isRoot || !hasExpandableChildren) ? '' : 'cursor-pointer'}` },
3024
3081
  !isRoot ? (React__default.createElement(Box, { mr: 2, className: "sl-font-mono sl-font-semibold sl-mr-2" },
3025
- !TYPES.includes(schema === null || schema === void 0 ? void 0 : schema.type) &&
3082
+ hasExpandableChildren &&
3083
+ !TYPES.includes(schema === null || schema === void 0 ? void 0 : schema.type) &&
3026
3084
  !detectCircularPath(path) &&
3027
3085
  !((_b = schema === null || schema === void 0 ? void 0 : schema.items) === null || _b === void 0 ? void 0 : _b.circular) &&
3028
3086
  !(schema === null || schema === void 0 ? void 0 : schema.circular) ? (React__default.createElement("i", { role: "img", "aria-hidden": "true", className: `sl-icon fal ${expanded ? 'fa-chevron-down' : 'fa-chevron-right'} fa-fw fa-sm` })) : (React__default.createElement("span", { className: "sl-icon fal fa-fw fa-sm", "aria-hidden": "true" })),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stoplight/elements-core",
3
- "version": "9.0.13-beta-0.3",
3
+ "version": "9.0.13-beta-0.4",
4
4
  "main": "./index.js",
5
5
  "sideEffects": [
6
6
  "web-components.min.js",