@backstage/plugin-config-schema 0.1.54 → 0.1.55-next.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/CHANGELOG.md +10 -0
- package/dist/api/StaticSchemaLoader.esm.js +38 -0
- package/dist/api/StaticSchemaLoader.esm.js.map +1 -0
- package/dist/api/types.esm.js +8 -0
- package/dist/api/types.esm.js.map +1 -0
- package/dist/components/ConfigSchemaPage/ConfigSchemaPage.esm.js +30 -0
- package/dist/components/ConfigSchemaPage/ConfigSchemaPage.esm.js.map +1 -0
- package/dist/components/ConfigSchemaPage/index.esm.js +2 -0
- package/dist/components/ConfigSchemaPage/index.esm.js.map +1 -0
- package/dist/components/SchemaBrowser/SchemaBrowser.esm.js +158 -0
- package/dist/components/SchemaBrowser/SchemaBrowser.esm.js.map +1 -0
- package/dist/components/SchemaView/ArrayView.esm.js +31 -0
- package/dist/components/SchemaView/ArrayView.esm.js.map +1 -0
- package/dist/components/SchemaView/ChildView.esm.js +88 -0
- package/dist/components/SchemaView/ChildView.esm.js.map +1 -0
- package/dist/components/SchemaView/MatchView.esm.js +24 -0
- package/dist/components/SchemaView/MatchView.esm.js.map +1 -0
- package/dist/components/SchemaView/MetadataView.esm.js +68 -0
- package/dist/components/SchemaView/MetadataView.esm.js.map +1 -0
- package/dist/components/SchemaView/ObjectView.esm.js +52 -0
- package/dist/components/SchemaView/ObjectView.esm.js.map +1 -0
- package/dist/components/SchemaView/ScalarView.esm.js +11 -0
- package/dist/components/SchemaView/ScalarView.esm.js.map +1 -0
- package/dist/components/SchemaView/SchemaView.esm.js +51 -0
- package/dist/components/SchemaView/SchemaView.esm.js.map +1 -0
- package/dist/components/SchemaViewer/SchemaViewer.esm.js +24 -0
- package/dist/components/SchemaViewer/SchemaViewer.esm.js.map +1 -0
- package/dist/components/ScrollTargetsContext/ScrollTargetsContext.esm.js +43 -0
- package/dist/components/ScrollTargetsContext/ScrollTargetsContext.esm.js.map +1 -0
- package/dist/index.esm.js +3 -60
- package/dist/index.esm.js.map +1 -1
- package/dist/plugin.esm.js +19 -0
- package/dist/plugin.esm.js.map +1 -0
- package/dist/routes.esm.js +8 -0
- package/dist/routes.esm.js.map +1 -0
- package/package.json +4 -4
- package/dist/esm/index-BXdCPlAj.esm.js +0 -511
- package/dist/esm/index-BXdCPlAj.esm.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# @backstage/plugin-config-schema
|
|
2
2
|
|
|
3
|
+
## 0.1.55-next.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies
|
|
8
|
+
- @backstage/core-components@0.14.5-next.0
|
|
9
|
+
- @backstage/core-plugin-api@1.9.2
|
|
10
|
+
- @backstage/errors@1.2.4
|
|
11
|
+
- @backstage/types@1.1.1
|
|
12
|
+
|
|
3
13
|
## 0.1.54
|
|
4
14
|
|
|
5
15
|
### Patch Changes
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import ObservableImpl from 'zen-observable';
|
|
2
|
+
import { ResponseError } from '@backstage/errors';
|
|
3
|
+
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
|
+
var __publicField = (obj, key, value) => {
|
|
7
|
+
__defNormalProp(obj, key + "" , value);
|
|
8
|
+
return value;
|
|
9
|
+
};
|
|
10
|
+
const DEFAULT_URL = "config-schema.json";
|
|
11
|
+
class StaticSchemaLoader {
|
|
12
|
+
constructor(options = {}) {
|
|
13
|
+
__publicField(this, "url");
|
|
14
|
+
var _a;
|
|
15
|
+
this.url = (_a = options == null ? void 0 : options.url) != null ? _a : DEFAULT_URL;
|
|
16
|
+
}
|
|
17
|
+
schema$() {
|
|
18
|
+
return new ObservableImpl((subscriber) => {
|
|
19
|
+
this.fetchSchema().then(
|
|
20
|
+
(schema) => subscriber.next({ schema }),
|
|
21
|
+
(error) => subscriber.error(error)
|
|
22
|
+
);
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
async fetchSchema() {
|
|
26
|
+
const res = await fetch(this.url);
|
|
27
|
+
if (!res.ok) {
|
|
28
|
+
if (res.status === 404) {
|
|
29
|
+
return void 0;
|
|
30
|
+
}
|
|
31
|
+
throw await ResponseError.fromResponse(res);
|
|
32
|
+
}
|
|
33
|
+
return await res.json();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export { StaticSchemaLoader };
|
|
38
|
+
//# sourceMappingURL=StaticSchemaLoader.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StaticSchemaLoader.esm.js","sources":["../../src/api/StaticSchemaLoader.ts"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport ObservableImpl from 'zen-observable';\nimport { ResponseError } from '@backstage/errors';\nimport { Schema } from 'jsonschema';\nimport { ConfigSchemaApi, ConfigSchemaResult } from './types';\nimport { Observable } from '@backstage/types';\n\nconst DEFAULT_URL = 'config-schema.json';\n\n/**\n * A ConfigSchemaApi implementation that loads the configuration from a URL.\n *\n * @public\n */\nexport class StaticSchemaLoader implements ConfigSchemaApi {\n private readonly url: string;\n\n constructor(options: { url?: string } = {}) {\n this.url = options?.url ?? DEFAULT_URL;\n }\n\n schema$(): Observable<ConfigSchemaResult> {\n return new ObservableImpl(subscriber => {\n this.fetchSchema().then(\n schema => subscriber.next({ schema }),\n error => subscriber.error(error),\n );\n });\n }\n\n private async fetchSchema(): Promise<undefined | Schema> {\n const res = await fetch(this.url);\n\n if (!res.ok) {\n if (res.status === 404) {\n return undefined;\n }\n\n throw await ResponseError.fromResponse(res);\n }\n\n return await res.json();\n }\n}\n"],"names":[],"mappings":";;;;;;;;;AAsBA,MAAM,WAAc,GAAA,oBAAA,CAAA;AAOb,MAAM,kBAA8C,CAAA;AAAA,EAGzD,WAAA,CAAY,OAA4B,GAAA,EAAI,EAAA;AAF5C,IAAiB,aAAA,CAAA,IAAA,EAAA,KAAA,CAAA,CAAA;AA9BnB,IAAA,IAAA,EAAA,CAAA;AAiCI,IAAK,IAAA,CAAA,GAAA,GAAA,CAAM,EAAS,GAAA,OAAA,IAAA,IAAA,GAAA,KAAA,CAAA,GAAA,OAAA,CAAA,GAAA,KAAT,IAAgB,GAAA,EAAA,GAAA,WAAA,CAAA;AAAA,GAC7B;AAAA,EAEA,OAA0C,GAAA;AACxC,IAAO,OAAA,IAAI,eAAe,CAAc,UAAA,KAAA;AACtC,MAAA,IAAA,CAAK,aAAc,CAAA,IAAA;AAAA,QACjB,CAAU,MAAA,KAAA,UAAA,CAAW,IAAK,CAAA,EAAE,QAAQ,CAAA;AAAA,QACpC,CAAA,KAAA,KAAS,UAAW,CAAA,KAAA,CAAM,KAAK,CAAA;AAAA,OACjC,CAAA;AAAA,KACD,CAAA,CAAA;AAAA,GACH;AAAA,EAEA,MAAc,WAA2C,GAAA;AACvD,IAAA,MAAM,GAAM,GAAA,MAAM,KAAM,CAAA,IAAA,CAAK,GAAG,CAAA,CAAA;AAEhC,IAAI,IAAA,CAAC,IAAI,EAAI,EAAA;AACX,MAAI,IAAA,GAAA,CAAI,WAAW,GAAK,EAAA;AACtB,QAAO,OAAA,KAAA,CAAA,CAAA;AAAA,OACT;AAEA,MAAM,MAAA,MAAM,aAAc,CAAA,YAAA,CAAa,GAAG,CAAA,CAAA;AAAA,KAC5C;AAEA,IAAO,OAAA,MAAM,IAAI,IAAK,EAAA,CAAA;AAAA,GACxB;AACF;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.esm.js","sources":["../../src/api/types.ts"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Schema } from 'jsonschema';\nimport { createApiRef } from '@backstage/core-plugin-api';\nimport { Observable } from '@backstage/types';\n\n/** @public */\nexport interface ConfigSchemaResult {\n schema?: Schema;\n}\n\n/** @public */\nexport interface ConfigSchemaApi {\n schema$(): Observable<ConfigSchemaResult>;\n}\n\n/** @public */\nexport const configSchemaApiRef = createApiRef<ConfigSchemaApi>({\n id: 'plugin.config-schema',\n});\n"],"names":[],"mappings":";;AA+BO,MAAM,qBAAqB,YAA8B,CAAA;AAAA,EAC9D,EAAI,EAAA,sBAAA;AACN,CAAC;;;;"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import React, { useMemo } from 'react';
|
|
2
|
+
import useObservable from 'react-use/esm/useObservable';
|
|
3
|
+
import { configSchemaApiRef } from '../../api/types.esm.js';
|
|
4
|
+
import 'zen-observable';
|
|
5
|
+
import '@backstage/errors';
|
|
6
|
+
import { SchemaViewer } from '../SchemaViewer/SchemaViewer.esm.js';
|
|
7
|
+
import Typography from '@material-ui/core/Typography';
|
|
8
|
+
import { Page, Header, Content, Progress } from '@backstage/core-components';
|
|
9
|
+
import { useApi } from '@backstage/core-plugin-api';
|
|
10
|
+
|
|
11
|
+
const ConfigSchemaPage = () => {
|
|
12
|
+
const configSchemaApi = useApi(configSchemaApiRef);
|
|
13
|
+
const schemaResult = useObservable(
|
|
14
|
+
useMemo(() => configSchemaApi.schema$(), [configSchemaApi])
|
|
15
|
+
);
|
|
16
|
+
let content;
|
|
17
|
+
if (schemaResult) {
|
|
18
|
+
if (schemaResult.schema) {
|
|
19
|
+
content = /* @__PURE__ */ React.createElement(SchemaViewer, { schema: schemaResult.schema });
|
|
20
|
+
} else {
|
|
21
|
+
content = /* @__PURE__ */ React.createElement(Typography, { variant: "h4" }, "No configuration schema available");
|
|
22
|
+
}
|
|
23
|
+
} else {
|
|
24
|
+
content = /* @__PURE__ */ React.createElement(Progress, null);
|
|
25
|
+
}
|
|
26
|
+
return /* @__PURE__ */ React.createElement(Page, { themeId: "tool" }, /* @__PURE__ */ React.createElement(Header, { title: "Configuration Reference" }), /* @__PURE__ */ React.createElement(Content, { stretch: true }, content));
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export { ConfigSchemaPage };
|
|
30
|
+
//# sourceMappingURL=ConfigSchemaPage.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConfigSchemaPage.esm.js","sources":["../../../src/components/ConfigSchemaPage/ConfigSchemaPage.tsx"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport React, { useMemo } from 'react';\nimport useObservable from 'react-use/esm/useObservable';\nimport { configSchemaApiRef } from '../../api';\nimport { SchemaViewer } from '../SchemaViewer';\nimport Typography from '@material-ui/core/Typography';\n\nimport { Header, Page, Content, Progress } from '@backstage/core-components';\nimport { useApi } from '@backstage/core-plugin-api';\n\nexport const ConfigSchemaPage = () => {\n const configSchemaApi = useApi(configSchemaApiRef);\n const schemaResult = useObservable(\n useMemo(() => configSchemaApi.schema$(), [configSchemaApi]),\n );\n\n let content;\n if (schemaResult) {\n if (schemaResult.schema) {\n content = <SchemaViewer schema={schemaResult.schema} />;\n } else {\n content = (\n <Typography variant=\"h4\">No configuration schema available</Typography>\n );\n }\n } else {\n content = <Progress />;\n }\n\n return (\n <Page themeId=\"tool\">\n <Header title=\"Configuration Reference\" />\n <Content stretch>{content}</Content>\n </Page>\n );\n};\n"],"names":[],"mappings":";;;;;;;;;;AAwBO,MAAM,mBAAmB,MAAM;AACpC,EAAM,MAAA,eAAA,GAAkB,OAAO,kBAAkB,CAAA,CAAA;AACjD,EAAA,MAAM,YAAe,GAAA,aAAA;AAAA,IACnB,QAAQ,MAAM,eAAA,CAAgB,SAAW,EAAA,CAAC,eAAe,CAAC,CAAA;AAAA,GAC5D,CAAA;AAEA,EAAI,IAAA,OAAA,CAAA;AACJ,EAAA,IAAI,YAAc,EAAA;AAChB,IAAA,IAAI,aAAa,MAAQ,EAAA;AACvB,MAAA,OAAA,mBAAW,KAAA,CAAA,aAAA,CAAA,YAAA,EAAA,EAAa,MAAQ,EAAA,YAAA,CAAa,MAAQ,EAAA,CAAA,CAAA;AAAA,KAChD,MAAA;AACL,MAAA,OAAA,mBACG,KAAA,CAAA,aAAA,CAAA,UAAA,EAAA,EAAW,OAAQ,EAAA,IAAA,EAAA,EAAK,mCAAiC,CAAA,CAAA;AAAA,KAE9D;AAAA,GACK,MAAA;AACL,IAAA,OAAA,uCAAW,QAAS,EAAA,IAAA,CAAA,CAAA;AAAA,GACtB;AAEA,EAAA,uBACG,KAAA,CAAA,aAAA,CAAA,IAAA,EAAA,EAAK,OAAQ,EAAA,MAAA,EAAA,sCACX,MAAO,EAAA,EAAA,KAAA,EAAM,yBAA0B,EAAA,CAAA,kBACvC,KAAA,CAAA,aAAA,CAAA,OAAA,EAAA,EAAQ,OAAO,EAAA,IAAA,EAAA,EAAE,OAAQ,CAC5B,CAAA,CAAA;AAEJ;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { withStyles, createStyles, alpha } from '@material-ui/core/styles';
|
|
2
|
+
import ChevronRightIcon from '@material-ui/icons/ChevronRight';
|
|
3
|
+
import ExpandMoreIcon from '@material-ui/icons/ExpandMore';
|
|
4
|
+
import TreeItem from '@material-ui/lab/TreeItem';
|
|
5
|
+
import TreeView from '@material-ui/lab/TreeView';
|
|
6
|
+
import React, { useRef, useMemo } from 'react';
|
|
7
|
+
import { useScrollTargets } from '../ScrollTargetsContext/ScrollTargetsContext.esm.js';
|
|
8
|
+
|
|
9
|
+
const StyledTreeItem = withStyles(
|
|
10
|
+
(theme) => createStyles({
|
|
11
|
+
label: {
|
|
12
|
+
userSelect: "none"
|
|
13
|
+
},
|
|
14
|
+
group: {
|
|
15
|
+
marginLeft: 7,
|
|
16
|
+
paddingLeft: theme.spacing(1),
|
|
17
|
+
borderLeft: `1px solid ${alpha(theme.palette.text.primary, 0.15)}`
|
|
18
|
+
}
|
|
19
|
+
})
|
|
20
|
+
)((props) => /* @__PURE__ */ React.createElement(TreeItem, { ...props }));
|
|
21
|
+
function createSchemaBrowserItems(expanded, schema, path = "", depth = 0) {
|
|
22
|
+
let matchArr;
|
|
23
|
+
if (schema.anyOf) {
|
|
24
|
+
matchArr = schema.anyOf;
|
|
25
|
+
} else if (schema.oneOf) {
|
|
26
|
+
matchArr = schema.oneOf;
|
|
27
|
+
} else if (schema.allOf) {
|
|
28
|
+
matchArr = schema.allOf;
|
|
29
|
+
}
|
|
30
|
+
if (matchArr) {
|
|
31
|
+
return matchArr.map((childSchema, index) => {
|
|
32
|
+
const childPath = `${path}/${index + 1}`;
|
|
33
|
+
if (depth > 0)
|
|
34
|
+
expanded.push(childPath);
|
|
35
|
+
return /* @__PURE__ */ React.createElement(
|
|
36
|
+
StyledTreeItem,
|
|
37
|
+
{
|
|
38
|
+
key: childPath,
|
|
39
|
+
nodeId: childPath,
|
|
40
|
+
label: `<Option ${index + 1}>`
|
|
41
|
+
},
|
|
42
|
+
createSchemaBrowserItems(
|
|
43
|
+
expanded,
|
|
44
|
+
childSchema,
|
|
45
|
+
childPath,
|
|
46
|
+
depth + 1
|
|
47
|
+
)
|
|
48
|
+
);
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
switch (schema.type) {
|
|
52
|
+
case "array": {
|
|
53
|
+
const childPath = `${path}[]`;
|
|
54
|
+
if (depth > 0)
|
|
55
|
+
expanded.push(childPath);
|
|
56
|
+
return /* @__PURE__ */ React.createElement(StyledTreeItem, { nodeId: childPath, label: "[]" }, schema.items && createSchemaBrowserItems(
|
|
57
|
+
expanded,
|
|
58
|
+
schema.items,
|
|
59
|
+
childPath,
|
|
60
|
+
depth + 1
|
|
61
|
+
));
|
|
62
|
+
}
|
|
63
|
+
case "object":
|
|
64
|
+
case void 0: {
|
|
65
|
+
const children = [];
|
|
66
|
+
if (schema.properties) {
|
|
67
|
+
children.push(
|
|
68
|
+
...Object.entries(schema.properties).map(([name, childSchema]) => {
|
|
69
|
+
const childPath = path ? `${path}.${name}` : name;
|
|
70
|
+
if (depth > 0)
|
|
71
|
+
expanded.push(childPath);
|
|
72
|
+
return /* @__PURE__ */ React.createElement(StyledTreeItem, { key: childPath, nodeId: childPath, label: name }, createSchemaBrowserItems(
|
|
73
|
+
expanded,
|
|
74
|
+
childSchema,
|
|
75
|
+
childPath,
|
|
76
|
+
depth + 1
|
|
77
|
+
));
|
|
78
|
+
})
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
if (schema.patternProperties) {
|
|
82
|
+
children.push(
|
|
83
|
+
...Object.entries(schema.patternProperties).map(
|
|
84
|
+
([name, childSchema]) => {
|
|
85
|
+
const childPath = `${path}.<${name}>`;
|
|
86
|
+
if (depth > 0)
|
|
87
|
+
expanded.push(childPath);
|
|
88
|
+
return /* @__PURE__ */ React.createElement(
|
|
89
|
+
StyledTreeItem,
|
|
90
|
+
{
|
|
91
|
+
key: childPath,
|
|
92
|
+
nodeId: childPath,
|
|
93
|
+
label: `<${name}>`
|
|
94
|
+
},
|
|
95
|
+
createSchemaBrowserItems(
|
|
96
|
+
expanded,
|
|
97
|
+
childSchema,
|
|
98
|
+
childPath,
|
|
99
|
+
depth + 1
|
|
100
|
+
)
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
)
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
if (schema.additionalProperties && schema.additionalProperties !== true) {
|
|
107
|
+
const childPath = `${path}.*`;
|
|
108
|
+
if (depth > 0)
|
|
109
|
+
expanded.push(childPath);
|
|
110
|
+
children.push(
|
|
111
|
+
/* @__PURE__ */ React.createElement(StyledTreeItem, { key: childPath, nodeId: childPath, label: "*" }, createSchemaBrowserItems(
|
|
112
|
+
expanded,
|
|
113
|
+
schema.additionalProperties,
|
|
114
|
+
childPath,
|
|
115
|
+
depth + 1
|
|
116
|
+
))
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, children);
|
|
120
|
+
}
|
|
121
|
+
default:
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
function SchemaBrowser({ schema }) {
|
|
126
|
+
const scroll = useScrollTargets();
|
|
127
|
+
const expandedRef = useRef([]);
|
|
128
|
+
const data = useMemo(() => {
|
|
129
|
+
const expanded = new Array();
|
|
130
|
+
const items = createSchemaBrowserItems(expanded, schema);
|
|
131
|
+
return { items, expanded };
|
|
132
|
+
}, [schema]);
|
|
133
|
+
if (!scroll) {
|
|
134
|
+
throw new Error("No scroll handler available");
|
|
135
|
+
}
|
|
136
|
+
const handleToggle = (_event, expanded) => {
|
|
137
|
+
expandedRef.current = expanded;
|
|
138
|
+
};
|
|
139
|
+
const handleSelect = (_event, nodeId) => {
|
|
140
|
+
if (expandedRef.current.includes(nodeId)) {
|
|
141
|
+
scroll.scrollTo(nodeId);
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
return /* @__PURE__ */ React.createElement(
|
|
145
|
+
TreeView,
|
|
146
|
+
{
|
|
147
|
+
defaultExpanded: data.expanded,
|
|
148
|
+
defaultCollapseIcon: /* @__PURE__ */ React.createElement(ExpandMoreIcon, null),
|
|
149
|
+
defaultExpandIcon: /* @__PURE__ */ React.createElement(ChevronRightIcon, null),
|
|
150
|
+
onNodeToggle: handleToggle,
|
|
151
|
+
onNodeSelect: handleSelect
|
|
152
|
+
},
|
|
153
|
+
data.items
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export { SchemaBrowser, createSchemaBrowserItems };
|
|
158
|
+
//# sourceMappingURL=SchemaBrowser.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SchemaBrowser.esm.js","sources":["../../../src/components/SchemaBrowser/SchemaBrowser.tsx"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { alpha } from '@material-ui/core/styles';\nimport { createStyles, withStyles } from '@material-ui/core/styles';\nimport ChevronRightIcon from '@material-ui/icons/ChevronRight';\nimport ExpandMoreIcon from '@material-ui/icons/ExpandMore';\nimport TreeItem, { TreeItemProps } from '@material-ui/lab/TreeItem';\nimport TreeView from '@material-ui/lab/TreeView';\nimport { Schema } from 'jsonschema';\nimport React, { ReactNode, useMemo, useRef } from 'react';\nimport { useScrollTargets } from '../ScrollTargetsContext';\n\nconst StyledTreeItem = withStyles(theme =>\n createStyles({\n label: {\n userSelect: 'none',\n },\n group: {\n marginLeft: 7,\n paddingLeft: theme.spacing(1),\n borderLeft: `1px solid ${alpha(theme.palette.text.primary, 0.15)}`,\n },\n }),\n)((props: TreeItemProps) => <TreeItem {...props} />);\n\nexport function createSchemaBrowserItems(\n expanded: string[],\n schema: Schema,\n path: string = '',\n depth: number = 0,\n): ReactNode {\n let matchArr;\n if (schema.anyOf) {\n matchArr = schema.anyOf;\n } else if (schema.oneOf) {\n matchArr = schema.oneOf;\n } else if (schema.allOf) {\n matchArr = schema.allOf;\n }\n if (matchArr) {\n return matchArr.map((childSchema, index) => {\n const childPath = `${path}/${index + 1}`;\n if (depth > 0) expanded.push(childPath);\n return (\n <StyledTreeItem\n key={childPath}\n nodeId={childPath}\n label={`<Option ${index + 1}>`}\n >\n {createSchemaBrowserItems(\n expanded,\n childSchema,\n childPath,\n depth + 1,\n )}\n </StyledTreeItem>\n );\n });\n }\n\n switch (schema.type) {\n case 'array': {\n const childPath = `${path}[]`;\n if (depth > 0) expanded.push(childPath);\n return (\n <StyledTreeItem nodeId={childPath} label=\"[]\">\n {schema.items &&\n createSchemaBrowserItems(\n expanded,\n schema.items as Schema,\n childPath,\n depth + 1,\n )}\n </StyledTreeItem>\n );\n }\n case 'object':\n case undefined: {\n const children = [];\n\n if (schema.properties) {\n children.push(\n ...Object.entries(schema.properties).map(([name, childSchema]) => {\n const childPath = path ? `${path}.${name}` : name;\n if (depth > 0) expanded.push(childPath);\n return (\n <StyledTreeItem key={childPath} nodeId={childPath} label={name}>\n {createSchemaBrowserItems(\n expanded,\n childSchema,\n childPath,\n depth + 1,\n )}\n </StyledTreeItem>\n );\n }),\n );\n }\n\n if (schema.patternProperties) {\n children.push(\n ...Object.entries(schema.patternProperties).map(\n ([name, childSchema]) => {\n const childPath = `${path}.<${name}>`;\n if (depth > 0) expanded.push(childPath);\n return (\n <StyledTreeItem\n key={childPath}\n nodeId={childPath}\n label={`<${name}>`}\n >\n {createSchemaBrowserItems(\n expanded,\n childSchema,\n childPath,\n depth + 1,\n )}\n </StyledTreeItem>\n );\n },\n ),\n );\n }\n\n if (schema.additionalProperties && schema.additionalProperties !== true) {\n const childPath = `${path}.*`;\n if (depth > 0) expanded.push(childPath);\n children.push(\n <StyledTreeItem key={childPath} nodeId={childPath} label=\"*\">\n {createSchemaBrowserItems(\n expanded,\n schema.additionalProperties,\n childPath,\n depth + 1,\n )}\n </StyledTreeItem>,\n );\n }\n\n return <>{children}</>;\n }\n\n default:\n return null;\n }\n}\n\nexport function SchemaBrowser({ schema }: { schema: Schema }) {\n const scroll = useScrollTargets();\n const expandedRef = useRef<string[]>([]);\n const data = useMemo(() => {\n const expanded = new Array<string>();\n\n const items = createSchemaBrowserItems(expanded, schema);\n\n return { items, expanded };\n }, [schema]);\n\n if (!scroll) {\n throw new Error('No scroll handler available');\n }\n\n const handleToggle = (_event: unknown, expanded: string[]) => {\n expandedRef.current = expanded;\n };\n\n const handleSelect = (_event: unknown, nodeId: string) => {\n if (expandedRef.current.includes(nodeId)) {\n scroll.scrollTo(nodeId);\n }\n };\n\n return (\n <TreeView\n defaultExpanded={data.expanded}\n defaultCollapseIcon={<ExpandMoreIcon />}\n defaultExpandIcon={<ChevronRightIcon />}\n onNodeToggle={handleToggle}\n onNodeSelect={handleSelect}\n >\n {data.items}\n </TreeView>\n );\n}\n"],"names":[],"mappings":";;;;;;;;AA0BA,MAAM,cAAiB,GAAA,UAAA;AAAA,EAAW,WAChC,YAAa,CAAA;AAAA,IACX,KAAO,EAAA;AAAA,MACL,UAAY,EAAA,MAAA;AAAA,KACd;AAAA,IACA,KAAO,EAAA;AAAA,MACL,UAAY,EAAA,CAAA;AAAA,MACZ,WAAA,EAAa,KAAM,CAAA,OAAA,CAAQ,CAAC,CAAA;AAAA,MAC5B,UAAA,EAAY,aAAa,KAAM,CAAA,KAAA,CAAM,QAAQ,IAAK,CAAA,OAAA,EAAS,IAAI,CAAC,CAAA,CAAA;A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AA,KAAA;AAAA,IAEb,IAAK,CAAA,KAAA;AAAA,GACR,CAAA;AAEJ;;;;"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import Box from '@material-ui/core/Box';
|
|
2
|
+
import Typography from '@material-ui/core/Typography';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { ChildView } from './ChildView.esm.js';
|
|
5
|
+
import { MetadataView } from './MetadataView.esm.js';
|
|
6
|
+
|
|
7
|
+
function ArrayView({ path, depth, schema }) {
|
|
8
|
+
const itemDepth = depth + 1;
|
|
9
|
+
const itemPath = path ? `${path}[]` : "[]";
|
|
10
|
+
const itemSchema = schema.items;
|
|
11
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(Box, { marginBottom: 4 }, schema.description && /* @__PURE__ */ React.createElement(Box, { marginBottom: 4 }, /* @__PURE__ */ React.createElement(Typography, { variant: "body1" }, schema.description)), /* @__PURE__ */ React.createElement(MetadataView, { schema })), /* @__PURE__ */ React.createElement(Typography, { variant: "overline" }, "Items"), /* @__PURE__ */ React.createElement(
|
|
12
|
+
ChildView,
|
|
13
|
+
{
|
|
14
|
+
lastChild: true,
|
|
15
|
+
path: itemPath,
|
|
16
|
+
depth: itemDepth,
|
|
17
|
+
schema: itemSchema
|
|
18
|
+
}
|
|
19
|
+
), schema.additionalItems && schema.additionalItems !== true && /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(Typography, { variant: "overline" }, "Additional Items"), /* @__PURE__ */ React.createElement(
|
|
20
|
+
ChildView,
|
|
21
|
+
{
|
|
22
|
+
path: itemPath,
|
|
23
|
+
depth: itemDepth,
|
|
24
|
+
schema: schema.additionalItems,
|
|
25
|
+
lastChild: true
|
|
26
|
+
}
|
|
27
|
+
)));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export { ArrayView };
|
|
31
|
+
//# sourceMappingURL=ArrayView.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ArrayView.esm.js","sources":["../../../src/components/SchemaView/ArrayView.tsx"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport Box from '@material-ui/core/Box';\nimport Typography from '@material-ui/core/Typography';\nimport { Schema } from 'jsonschema';\nimport React from 'react';\nimport { ChildView } from './ChildView';\nimport { MetadataView } from './MetadataView';\nimport { SchemaViewProps } from './types';\n\nexport function ArrayView({ path, depth, schema }: SchemaViewProps) {\n const itemDepth = depth + 1;\n const itemPath = path ? `${path}[]` : '[]';\n const itemSchema = schema.items;\n\n return (\n <>\n <Box marginBottom={4}>\n {schema.description && (\n <Box marginBottom={4}>\n <Typography variant=\"body1\">{schema.description}</Typography>\n </Box>\n )}\n <MetadataView schema={schema} />\n </Box>\n <Typography variant=\"overline\">Items</Typography>\n <ChildView\n lastChild\n path={itemPath}\n depth={itemDepth}\n schema={itemSchema as Schema | undefined}\n />\n {schema.additionalItems && schema.additionalItems !== true && (\n <>\n <Typography variant=\"overline\">Additional Items</Typography>\n <ChildView\n path={itemPath}\n depth={itemDepth}\n schema={schema.additionalItems}\n lastChild\n />\n </>\n )}\n </>\n );\n}\n"],"names":[],"mappings":";;;;;;AAwBO,SAAS,SAAU,CAAA,EAAE,IAAM,EAAA,KAAA,EAAO,QAA2B,EAAA;AAClE,EAAA,MAAM,YAAY,KAAQ,GAAA,CAAA,CAAA;AAC1B,EAAA,MAAM,QAAW,GAAA,IAAA,GAAO,CAAG,EAAA,IAAI,CAAO,EAAA,CAAA,GAAA,IAAA,CAAA;AACtC,EAAA,MAAM,aA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
|
+
import Box from '@material-ui/core/Box';
|
|
2
|
+
import Chip from '@material-ui/core/Chip';
|
|
3
|
+
import Divider from '@material-ui/core/Divider';
|
|
4
|
+
import Typography from '@material-ui/core/Typography';
|
|
5
|
+
import { makeStyles } from '@material-ui/core/styles';
|
|
6
|
+
import React, { useRef, useEffect } from 'react';
|
|
7
|
+
import { useScrollTargets } from '../ScrollTargetsContext/ScrollTargetsContext.esm.js';
|
|
8
|
+
import { SchemaView } from './SchemaView.esm.js';
|
|
9
|
+
|
|
10
|
+
function titleVariant(depth) {
|
|
11
|
+
if (depth <= 1) {
|
|
12
|
+
return "h2";
|
|
13
|
+
} else if (depth === 2) {
|
|
14
|
+
return "h3";
|
|
15
|
+
} else if (depth === 3) {
|
|
16
|
+
return "h4";
|
|
17
|
+
} else if (depth === 4) {
|
|
18
|
+
return "h5";
|
|
19
|
+
}
|
|
20
|
+
return "h6";
|
|
21
|
+
}
|
|
22
|
+
const useChildViewStyles = makeStyles((theme) => ({
|
|
23
|
+
title: {
|
|
24
|
+
marginBottom: 0
|
|
25
|
+
},
|
|
26
|
+
chip: {
|
|
27
|
+
marginLeft: theme.spacing(1),
|
|
28
|
+
marginRight: 0,
|
|
29
|
+
marginBottom: 0
|
|
30
|
+
}
|
|
31
|
+
}));
|
|
32
|
+
function ChildView({
|
|
33
|
+
path,
|
|
34
|
+
depth,
|
|
35
|
+
schema,
|
|
36
|
+
required,
|
|
37
|
+
lastChild
|
|
38
|
+
}) {
|
|
39
|
+
const classes = useChildViewStyles();
|
|
40
|
+
const titleRef = useRef(null);
|
|
41
|
+
const scroll = useScrollTargets();
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
return scroll == null ? void 0 : scroll.setScrollListener(path, () => {
|
|
44
|
+
var _a;
|
|
45
|
+
(_a = titleRef.current) == null ? void 0 : _a.scrollIntoView({ behavior: "smooth" });
|
|
46
|
+
});
|
|
47
|
+
}, [scroll, path]);
|
|
48
|
+
const chips = new Array();
|
|
49
|
+
const chipProps = { size: "small", classes: { root: classes.chip } };
|
|
50
|
+
if (required) {
|
|
51
|
+
chips.push(
|
|
52
|
+
/* @__PURE__ */ React.createElement(Chip, { label: "required", color: "default", key: "required", ...chipProps })
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
const visibility = schema == null ? void 0 : schema.visibility;
|
|
56
|
+
if (visibility === "frontend") {
|
|
57
|
+
chips.push(
|
|
58
|
+
/* @__PURE__ */ React.createElement(Chip, { label: "frontend", color: "primary", key: "visibility", ...chipProps })
|
|
59
|
+
);
|
|
60
|
+
} else if (visibility === "secret") {
|
|
61
|
+
chips.push(
|
|
62
|
+
/* @__PURE__ */ React.createElement(Chip, { label: "secret", color: "secondary", key: "visibility", ...chipProps })
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
return /* @__PURE__ */ React.createElement(Box, { paddingBottom: lastChild ? 4 : 8, display: "flex", flexDirection: "row" }, /* @__PURE__ */ React.createElement(Divider, { orientation: "vertical", flexItem: true }), /* @__PURE__ */ React.createElement(Box, { paddingLeft: 2, flex: 1 }, /* @__PURE__ */ React.createElement(
|
|
66
|
+
Box,
|
|
67
|
+
{
|
|
68
|
+
display: "flex",
|
|
69
|
+
flexDirection: "row",
|
|
70
|
+
marginBottom: 2,
|
|
71
|
+
alignItems: "center"
|
|
72
|
+
},
|
|
73
|
+
/* @__PURE__ */ React.createElement(
|
|
74
|
+
Typography,
|
|
75
|
+
{
|
|
76
|
+
ref: titleRef,
|
|
77
|
+
variant: titleVariant(depth),
|
|
78
|
+
classes: { root: classes.title }
|
|
79
|
+
},
|
|
80
|
+
path
|
|
81
|
+
),
|
|
82
|
+
chips.length > 0 && /* @__PURE__ */ React.createElement(Box, { marginLeft: 1 }),
|
|
83
|
+
chips
|
|
84
|
+
), schema && /* @__PURE__ */ React.createElement(SchemaView, { path, depth, schema })));
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export { ChildView };
|
|
88
|
+
//# sourceMappingURL=ChildView.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ChildView.esm.js","sources":["../../../src/components/SchemaView/ChildView.tsx"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { JsonValue } from '@backstage/types';\nimport Box from '@material-ui/core/Box';\nimport Chip from '@material-ui/core/Chip';\nimport Divider from '@material-ui/core/Divider';\nimport Typography from '@material-ui/core/Typography';\nimport { makeStyles } from '@material-ui/core/styles';\nimport { Schema } from 'jsonschema';\nimport React, { useEffect, useRef } from 'react';\nimport { useScrollTargets } from '../ScrollTargetsContext/ScrollTargetsContext';\nimport { SchemaView } from './SchemaView';\n\nexport interface MetadataViewRowProps {\n label: string;\n text?: string;\n data?: JsonValue;\n}\n\nfunction titleVariant(depth: number) {\n if (depth <= 1) {\n return 'h2';\n } else if (depth === 2) {\n return 'h3';\n } else if (depth === 3) {\n return 'h4';\n } else if (depth === 4) {\n return 'h5';\n }\n return 'h6';\n}\n\nconst useChildViewStyles = makeStyles(theme => ({\n title: {\n marginBottom: 0,\n },\n chip: {\n marginLeft: theme.spacing(1),\n marginRight: 0,\n marginBottom: 0,\n },\n}));\n\nexport function ChildView({\n path,\n depth,\n schema,\n required,\n lastChild,\n}: {\n path: string;\n depth: number;\n schema?: Schema;\n required?: boolean;\n lastChild?: boolean;\n}) {\n const classes = useChildViewStyles();\n const titleRef = useRef<HTMLElement>(null);\n const scroll = useScrollTargets();\n\n useEffect(() => {\n return scroll?.setScrollListener(path, () => {\n titleRef.current?.scrollIntoView({ behavior: 'smooth' });\n });\n }, [scroll, path]);\n\n const chips = new Array<JSX.Element>();\n const chipProps = { size: 'small' as const, classes: { root: classes.chip } };\n\n if (required) {\n chips.push(\n <Chip label=\"required\" color=\"default\" key=\"required\" {...chipProps} />,\n );\n }\n\n const visibility = (schema as { visibility?: string })?.visibility;\n if (visibility === 'frontend') {\n chips.push(\n <Chip label=\"frontend\" color=\"primary\" key=\"visibility\" {...chipProps} />,\n );\n } else if (visibility === 'secret') {\n chips.push(\n <Chip label=\"secret\" color=\"secondary\" key=\"visibility\" {...chipProps} />,\n );\n }\n\n return (\n <Box paddingBottom={lastChild ? 4 : 8} display=\"flex\" flexDirection=\"row\">\n <Divider orientation=\"vertical\" flexItem />\n <Box paddingLeft={2} flex={1}>\n <Box\n display=\"flex\"\n flexDirection=\"row\"\n marginBottom={2}\n alignItems=\"center\"\n >\n <Typography\n ref={titleRef}\n variant={titleVariant(depth)}\n classes={{ root: classes.title }}\n >\n {path}\n </Typography>\n {chips.length > 0 && <Box marginLeft={1} />}\n {chips}\n </Box>\n {schema && (\n <SchemaView path={path} depth={depth} schema={schema as Schema} />\n )}\n </Box>\n </Box>\n );\n}\n"],"names":[],"mappings":";;;;;;;;;AAiCA,SAAS,aAAa,KAAe,EAAA;AACnC,EAAA,IAAI,SAAS,CAAG,EAAA;AACd,IAAO,OAAA,IAAA,CAAA;AAAA,GACT,MAAA,IAAW,UAAU,CAAG,EAAA;AACtB,IAAO,OAAA,IAAA,CAAA;AAAA,GACT,MAAA,IAAW,UAAU,CAAG,EAAA;AACtB,IAAO,OAAA,IAAA,CAAA;AAAA,GACT,MAAA,IAAW,UAAU,CAAG,EAAA;AACtB,IAAO,OAAA,IAAA,CAAA;AAAA,GACT;AACA,EAAO,OAAA,IAAA,CAAA;AACT,CAAA;AAEA,MAAM,kBAAA,GAAqB,WAAW,CAAU,KAAA,MAAA;AAAA,EAC9C,KAAO,EAAA;AAAA,IACL,YAAc,EAAA,CAAA;AAAA,GAChB;AAAA,EACA,IAAM,EAAA;AAAA,IACJ,UAAA,EA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E9B,IAAA;AAAA,KACH;AAAA,IACC,MAAM,MAAS,GAAA,CAAA,oBAAM,KAAA,CAAA,aAAA,CAAA,GAAA,EAAA,EAAI,YAAY,CAAG,EAAA,CAAA;AAAA,IACxC,KAAA;AAAA,GACH,EACC,0BACE,KAAA,CAAA,aAAA,CAAA,UAAA,EAAA,EAAW,MAAY,KAAc,EAAA,MAAA,EAA0B,CAEpE,CACF,CAAA,CAAA;AAEJ;;;;"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import Typography from '@material-ui/core/Typography';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { ChildView } from './ChildView.esm.js';
|
|
4
|
+
|
|
5
|
+
function MatchView({
|
|
6
|
+
path,
|
|
7
|
+
depth,
|
|
8
|
+
schema,
|
|
9
|
+
label
|
|
10
|
+
}) {
|
|
11
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(Typography, { variant: "overline" }, label), schema.map((optionSchema, index) => /* @__PURE__ */ React.createElement(
|
|
12
|
+
ChildView,
|
|
13
|
+
{
|
|
14
|
+
key: index,
|
|
15
|
+
path: `${path}/${index + 1}`,
|
|
16
|
+
depth: depth + 1,
|
|
17
|
+
schema: optionSchema,
|
|
18
|
+
lastChild: index === schema.length - 1
|
|
19
|
+
}
|
|
20
|
+
)));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export { MatchView };
|
|
24
|
+
//# sourceMappingURL=MatchView.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MatchView.esm.js","sources":["../../../src/components/SchemaView/MatchView.tsx"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport Typography from '@material-ui/core/Typography';\nimport { Schema } from 'jsonschema';\nimport React from 'react';\nimport { ChildView } from './ChildView';\n\nexport function MatchView({\n path,\n depth,\n schema,\n label,\n}: {\n path: string;\n depth: number;\n schema: Schema[];\n label: string;\n}) {\n return (\n <>\n <Typography variant=\"overline\">{label}</Typography>\n {schema.map((optionSchema, index) => (\n <ChildView\n key={index}\n path={`${path}/${index + 1}`}\n depth={depth + 1}\n schema={optionSchema}\n lastChild={index === schema.length - 1}\n />\n ))}\n </>\n );\n}\n"],"names":[],"mappings":";;;;AAoBO,SAAS,SAAU,CAAA;AAAA,EACxB,IAAA;AAAA,EACA,KAAA;AAAA,EACA,MAAA;AAAA,EACA,KAAA;AACF,CAKG,EAAA;AACD,EACE,uBAAA,KAAA,CAAA,aAAA,CAAA,KAAA,CAAA,QAAA,EAAA,IAAA,kBACG,KAAA,CAAA,aAAA,CAAA,UAAA,EAAA,EAAW,OAAQ,EAAA,UAAA,EAAA,EAAY,KAAM,CAAA,EACrC,MAAO,CAAA,GAAA,CAAI,CAAC,YAAA,EAAc,KACzB,qBAAA,KAAA,CAAA,aAAA;AAAA,IAAC,SAAA;AAAA,IAAA;AAAA,MACC,GAAK,EAAA,KAAA;AAAA,MACL,IAAM,EAAA,CAAA,EAAG,IAAI,CAAA,CAAA,EAAI,QAAQ,CAAC,CAAA,CAAA;AAAA,MAC1B,OAAO,KAAQ,GAAA,CAAA;AAAA,MACf,MAAQ,EAAA,YAAA;AAAA,MACR,SAAA,EAAW,KAAU,KAAA,MAAA,CAAO,MAAS,GAAA,CAAA;AAAA,KAAA;AAAA,GAExC,CACH,CAAA,CAAA;AAEJ;;;;"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import Paper from '@material-ui/core/Paper';
|
|
2
|
+
import Table from '@material-ui/core/Table';
|
|
3
|
+
import TableBody from '@material-ui/core/TableBody';
|
|
4
|
+
import TableCell from '@material-ui/core/TableCell';
|
|
5
|
+
import TableRow from '@material-ui/core/TableRow';
|
|
6
|
+
import Typography from '@material-ui/core/Typography';
|
|
7
|
+
import React from 'react';
|
|
8
|
+
|
|
9
|
+
function MetadataViewRow({ label, text, data }) {
|
|
10
|
+
if (text === void 0 && data === void 0) {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
return /* @__PURE__ */ React.createElement(TableRow, null, /* @__PURE__ */ React.createElement(TableCell, { style: { width: 160 } }, /* @__PURE__ */ React.createElement(Typography, { variant: "body1", noWrap: true, style: { fontWeight: 900 } }, label)), /* @__PURE__ */ React.createElement(TableCell, null, /* @__PURE__ */ React.createElement(Typography, { variant: "body1" }, data ? JSON.stringify(data) : text)));
|
|
14
|
+
}
|
|
15
|
+
function MetadataView({ schema }) {
|
|
16
|
+
return /* @__PURE__ */ React.createElement(Paper, { variant: "outlined", square: true, style: { width: "100%" } }, /* @__PURE__ */ React.createElement(Table, { size: "small" }, /* @__PURE__ */ React.createElement(TableBody, null, /* @__PURE__ */ React.createElement(MetadataViewRow, { label: "Type", data: schema.type }), /* @__PURE__ */ React.createElement(MetadataViewRow, { label: "Allowed values", data: schema.enum }), schema.additionalProperties === true && /* @__PURE__ */ React.createElement(MetadataViewRow, { label: "Additional Properties", text: "true" }), schema.additionalItems === true && /* @__PURE__ */ React.createElement(MetadataViewRow, { label: "Additional Items", text: "true" }), /* @__PURE__ */ React.createElement(MetadataViewRow, { label: "Format", text: schema.format }), /* @__PURE__ */ React.createElement(
|
|
17
|
+
MetadataViewRow,
|
|
18
|
+
{
|
|
19
|
+
label: "Pattern",
|
|
20
|
+
text: schema.pattern && String(schema.pattern)
|
|
21
|
+
}
|
|
22
|
+
), /* @__PURE__ */ React.createElement(MetadataViewRow, { label: "Minimum", data: schema.minimum }), /* @__PURE__ */ React.createElement(MetadataViewRow, { label: "Maximum", data: schema.maximum }), /* @__PURE__ */ React.createElement(
|
|
23
|
+
MetadataViewRow,
|
|
24
|
+
{
|
|
25
|
+
label: "Exclusive minimum",
|
|
26
|
+
data: schema.exclusiveMinimum
|
|
27
|
+
}
|
|
28
|
+
), /* @__PURE__ */ React.createElement(
|
|
29
|
+
MetadataViewRow,
|
|
30
|
+
{
|
|
31
|
+
label: "Exclusive maximum",
|
|
32
|
+
data: schema.exclusiveMaximum
|
|
33
|
+
}
|
|
34
|
+
), /* @__PURE__ */ React.createElement(MetadataViewRow, { label: "Multiple of", data: schema.multipleOf }), /* @__PURE__ */ React.createElement(
|
|
35
|
+
MetadataViewRow,
|
|
36
|
+
{
|
|
37
|
+
label: "Maximum number of items",
|
|
38
|
+
data: schema.maxItems
|
|
39
|
+
}
|
|
40
|
+
), /* @__PURE__ */ React.createElement(
|
|
41
|
+
MetadataViewRow,
|
|
42
|
+
{
|
|
43
|
+
label: "Minimum number of items",
|
|
44
|
+
data: schema.minItems
|
|
45
|
+
}
|
|
46
|
+
), /* @__PURE__ */ React.createElement(
|
|
47
|
+
MetadataViewRow,
|
|
48
|
+
{
|
|
49
|
+
label: "Maximum number of properties",
|
|
50
|
+
data: schema.maxProperties
|
|
51
|
+
}
|
|
52
|
+
), /* @__PURE__ */ React.createElement(
|
|
53
|
+
MetadataViewRow,
|
|
54
|
+
{
|
|
55
|
+
label: "Minimum number of properties",
|
|
56
|
+
data: schema.minProperties
|
|
57
|
+
}
|
|
58
|
+
), /* @__PURE__ */ React.createElement(MetadataViewRow, { label: "Maximum Length", data: schema.maxLength }), /* @__PURE__ */ React.createElement(MetadataViewRow, { label: "Minimum Length", data: schema.minLength }), /* @__PURE__ */ React.createElement(
|
|
59
|
+
MetadataViewRow,
|
|
60
|
+
{
|
|
61
|
+
label: "Items must be unique",
|
|
62
|
+
data: schema.uniqueItems
|
|
63
|
+
}
|
|
64
|
+
))));
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export { MetadataView, MetadataViewRow };
|
|
68
|
+
//# sourceMappingURL=MetadataView.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MetadataView.esm.js","sources":["../../../src/components/SchemaView/MetadataView.tsx"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { JsonValue } from '@backstage/types';\nimport Paper from '@material-ui/core/Paper';\nimport Table from '@material-ui/core/Table';\nimport TableBody from '@material-ui/core/TableBody';\nimport TableCell from '@material-ui/core/TableCell';\nimport TableRow from '@material-ui/core/TableRow';\nimport Typography from '@material-ui/core/Typography';\nimport { Schema } from 'jsonschema';\nimport React from 'react';\n\nexport interface MetadataViewRowProps {\n label: string;\n text?: string;\n data?: JsonValue;\n}\n\nexport function MetadataViewRow({ label, text, data }: MetadataViewRowProps) {\n if (text === undefined && data === undefined) {\n return null;\n }\n return (\n <TableRow>\n <TableCell style={{ width: 160 }}>\n <Typography variant=\"body1\" noWrap style={{ fontWeight: 900 }}>\n {label}\n </Typography>\n </TableCell>\n <TableCell>\n <Typography variant=\"body1\">\n {data ? JSON.stringify(data) : text}\n </Typography>\n </TableCell>\n </TableRow>\n );\n}\n\nexport function MetadataView({ schema }: { schema: Schema }) {\n return (\n <Paper variant=\"outlined\" square style={{ width: '100%' }}>\n <Table size=\"small\">\n <TableBody>\n <MetadataViewRow label=\"Type\" data={schema.type} />\n <MetadataViewRow label=\"Allowed values\" data={schema.enum} />\n {schema.additionalProperties === true && (\n <MetadataViewRow label=\"Additional Properties\" text=\"true\" />\n )}\n {schema.additionalItems === true && (\n <MetadataViewRow label=\"Additional Items\" text=\"true\" />\n )}\n <MetadataViewRow label=\"Format\" text={schema.format} />\n <MetadataViewRow\n label=\"Pattern\"\n text={schema.pattern && String(schema.pattern)}\n />\n <MetadataViewRow label=\"Minimum\" data={schema.minimum} />\n <MetadataViewRow label=\"Maximum\" data={schema.maximum} />\n <MetadataViewRow\n label=\"Exclusive minimum\"\n data={schema.exclusiveMinimum}\n />\n <MetadataViewRow\n label=\"Exclusive maximum\"\n data={schema.exclusiveMaximum}\n />\n <MetadataViewRow label=\"Multiple of\" data={schema.multipleOf} />\n <MetadataViewRow\n label=\"Maximum number of items\"\n data={schema.maxItems}\n />\n <MetadataViewRow\n label=\"Minimum number of items\"\n data={schema.minItems}\n />\n <MetadataViewRow\n label=\"Maximum number of properties\"\n data={schema.maxProperties}\n />\n <MetadataViewRow\n label=\"Minimum number of properties\"\n data={schema.minProperties}\n />\n <MetadataViewRow label=\"Maximum Length\" data={schema.maxLength} />\n <MetadataViewRow label=\"Minimum Length\" data={schema.minLength} />\n <MetadataViewRow\n label=\"Items must be unique\"\n data={schema.uniqueItems}\n />\n </TableBody>\n </Table>\n </Paper>\n );\n}\n"],"names":[],"mappings":";;;;;;;;AAgCO,SAAS,eAAgB,CAAA,EAAE,KAAO,EAAA,IAAA,EAAM,MAA8B,EAAA;AAC3E,EAAI,IAAA,IAAA,KAAS,KAAa,CAAA,IAAA,IAAA,KAAS,KAAW,CAAA,EAAA;AAC5C,IAAO,OAAA,IAAA,CAAA;AAAA,GACT;AACA,EAAA,2CACG,QACC,EAAA,IAAA,kBAAA,KAAA,CAAA,aAAA,CAAC,SAAU,EAAA,EAAA,KAAA,EAAO,EAAE,KAAO,EAAA,GAAA,EACzB,EAAA,kBAAA,KAAA,CAAA,aAAA,CAAC,cAAW,OAAQ,EAAA,OAAA,EAAQ,MAAM,EAAA,IAAA,EAAC,OAAO,EAAE,UAAA,EAAY,GAAI,EAAA,EAAA,EACzD,KACH,CACF,CAAA,kBACC,KAAA,CAAA,aAAA,CAAA,SAAA,EAAA,IAAA,sCACE,UAAW,EAAA,EAAA,OAAA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EAAA,EAAgB,KAAM,EAAA,gBAAA,EAAiB,MAAM,MAAO,CAAA,SAAA,EAAW,CAChE,kBAAA,KAAA,CAAA,aAAA,CAAC,mBAAgB,KAAM,EAAA,gBAAA,EAAiB,IAAM,EAAA,MAAA,CAAO,WAAW,CAChE,kBAAA,KAAA,CAAA,aAAA;AAAA,IAAC,eAAA;AAAA,IAAA;AAAA,MACC,KAAM,EAAA,sBAAA;AAAA,MACN,MAAM,MAAO,CAAA,WAAA;AAAA,KAAA;AAAA,GAEjB,CACF,CACF,CAAA,CAAA;AAEJ;;;;"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import Box from '@material-ui/core/Box';
|
|
2
|
+
import Typography from '@material-ui/core/Typography';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { ChildView } from './ChildView.esm.js';
|
|
5
|
+
import { MetadataView } from './MetadataView.esm.js';
|
|
6
|
+
|
|
7
|
+
function isRequired(name, required) {
|
|
8
|
+
if (required === true) {
|
|
9
|
+
return true;
|
|
10
|
+
}
|
|
11
|
+
if (Array.isArray(required)) {
|
|
12
|
+
return required.includes(name);
|
|
13
|
+
}
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
function ObjectView({ path, depth, schema }) {
|
|
17
|
+
var _a, _b;
|
|
18
|
+
const properties = Object.entries((_a = schema.properties) != null ? _a : {});
|
|
19
|
+
const patternProperties = Object.entries((_b = schema.patternProperties) != null ? _b : {});
|
|
20
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, depth > 0 && /* @__PURE__ */ React.createElement(Box, { marginBottom: 4 }, schema.description && /* @__PURE__ */ React.createElement(Box, { marginBottom: 4 }, /* @__PURE__ */ React.createElement(Typography, { variant: "body1" }, schema.description)), /* @__PURE__ */ React.createElement(MetadataView, { schema })), properties.length > 0 && /* @__PURE__ */ React.createElement(React.Fragment, null, depth > 0 && /* @__PURE__ */ React.createElement(Typography, { variant: "overline" }, "Properties"), properties.map(([name, propSchema], index) => /* @__PURE__ */ React.createElement(
|
|
21
|
+
ChildView,
|
|
22
|
+
{
|
|
23
|
+
key: name,
|
|
24
|
+
path: path ? `${path}.${name}` : name,
|
|
25
|
+
depth: depth + 1,
|
|
26
|
+
schema: propSchema,
|
|
27
|
+
lastChild: index === properties.length - 1,
|
|
28
|
+
required: isRequired(name, schema.required)
|
|
29
|
+
}
|
|
30
|
+
))), patternProperties.length > 0 && /* @__PURE__ */ React.createElement(React.Fragment, null, depth > 0 && /* @__PURE__ */ React.createElement(Typography, { variant: "overline" }, "Pattern Properties"), patternProperties.map(([name, propSchema], index) => /* @__PURE__ */ React.createElement(
|
|
31
|
+
ChildView,
|
|
32
|
+
{
|
|
33
|
+
key: name,
|
|
34
|
+
path: path ? `${path}.<${name}>` : name,
|
|
35
|
+
depth: depth + 1,
|
|
36
|
+
schema: propSchema,
|
|
37
|
+
lastChild: index === patternProperties.length - 1,
|
|
38
|
+
required: isRequired(name, schema.required)
|
|
39
|
+
}
|
|
40
|
+
))), schema.additionalProperties && schema.additionalProperties !== true && /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(Typography, { variant: "overline" }, "Additional Properties"), /* @__PURE__ */ React.createElement(
|
|
41
|
+
ChildView,
|
|
42
|
+
{
|
|
43
|
+
path: `${path}.*`,
|
|
44
|
+
depth: depth + 1,
|
|
45
|
+
schema: schema.additionalProperties,
|
|
46
|
+
lastChild: true
|
|
47
|
+
}
|
|
48
|
+
)));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export { ObjectView };
|
|
52
|
+
//# sourceMappingURL=ObjectView.esm.js.map
|