@xyd-js/atlas 0.1.0-xyd.16 → 0.1.0-xyd.18
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/.storybook/index.css +1 -2
- package/.storybook/preview.ts +1 -2
- package/CHANGELOG.md +22 -0
- package/dist/Update-BlhP2VFR-COLbZvRj.js +4 -0
- package/dist/Update-BlhP2VFR-COLbZvRj.js.map +1 -0
- package/dist/Update-CMM38Snc-COLbZvRj.js +4 -0
- package/dist/Update-CMM38Snc-COLbZvRj.js.map +1 -0
- package/dist/Update-D5e_yqty-COLbZvRj.js +4 -0
- package/dist/Update-D5e_yqty-COLbZvRj.js.map +1 -0
- package/dist/index.css +47 -58
- package/dist/index.d.ts +30 -11
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/styles.css +89 -0
- package/dist/tokens.css +5 -2
- package/dist/xydPlugin.d.ts +5 -0
- package/dist/xydPlugin.js +2 -0
- package/dist/xydPlugin.js.map +1 -0
- package/index.ts +2 -1
- package/package.json +12 -9
- package/packages/xyd-plugin/SidebarItem.tsx +27 -0
- package/packages/xyd-plugin/index.ts +19 -0
- package/rollup.config.js +27 -25
- package/src/components/ApiRef/ApiRefItem/ApiRefItem.styles.tsx +60 -17
- package/src/components/ApiRef/ApiRefItem/ApiRefItem.tsx +508 -49
- package/src/components/ApiRef/ApiRefProperties/ApiRefProperties.styles.tsx +73 -16
- package/src/components/ApiRef/ApiRefProperties/ApiRefProperties.tsx +574 -56
- package/src/components/ApiRef/ApiRefSamples/ApiRefSamples.styles.tsx +2 -1
- package/src/components/ApiRef/ApiRefSamples/ApiRefSamples.tsx +37 -19
- package/src/components/Atlas/Atlas.styles.tsx +1 -1
- package/src/components/Atlas/Atlas.tsx +35 -19
- package/src/components/Atlas/AtlasContext.tsx +47 -0
- package/src/components/Atlas/AtlasDecorator.styles.ts +22 -0
- package/src/components/Atlas/AtlasDecorator.tsx +15 -0
- package/src/components/Atlas/AtlasLazy/AtlasLazy.tsx +2 -2
- package/src/components/Atlas/AtlasPrimary.tsx +21 -0
- package/src/components/Atlas/AtlasSecondary.tsx +148 -0
- package/src/components/Atlas/index.ts +6 -2
- package/src/components/Atlas/types.ts +11 -0
- package/src/components/Code/CodeSampleButtons/CodeSampleButtons.styles.tsx +4 -5
- package/src/components/Code/CodeSampleButtons/CodeSampleButtons.tsx +6 -8
- package/src/components/Code/index.ts +0 -4
- package/src/components/Icon/index.tsx +384 -0
- package/src/styles/styles.css +89 -0
- package/src/styles/tokens.css +5 -2
- package/src/utils/mdx.ts +0 -29
- package/tsconfig.json +6 -2
- package/types.d.ts +22 -0
- package/dist/CodeSample-CVki5fdQ-CI-Jdg_T.js +0 -2
- package/dist/CodeSample-CVki5fdQ-CI-Jdg_T.js.map +0 -1
- package/dist/CodeSample-Dkob5gWa-CI-Jdg_T.js +0 -2
- package/dist/CodeSample-Dkob5gWa-CI-Jdg_T.js.map +0 -1
- package/dist/atlas-index.d.ts +0 -15
- package/dist/atlas-index.js +0 -2
- package/dist/atlas-index.js.map +0 -1
- package/packages/atlas-index/AtlasIndex.tsx +0 -79
- package/packages/atlas-index/index.ts +0 -3
- package/src/components/Code/CodeCopy/CodeCopy.styles.tsx +0 -17
- package/src/components/Code/CodeCopy/CodeCopy.tsx +0 -30
- package/src/components/Code/CodeCopy/index.ts +0 -7
- package/src/components/Code/CodeSample/CodeSample.styles.tsx +0 -131
- package/src/components/Code/CodeSample/CodeSample.tsx +0 -143
- package/src/components/Code/CodeSample/index.ts +0 -8
- package/src/components/Code/CodeSample/withLocalStored.tsx +0 -52
- package/src/components/Code/default-theme.ts +0 -266
|
@@ -1,71 +1,231 @@
|
|
|
1
|
-
import React, {useState} from "react";
|
|
2
|
-
import {DefinitionProperty} from "@xyd-js/uniform";
|
|
1
|
+
import React, { useContext, useState } from "react";
|
|
2
|
+
import { DEFINED_DEFINITION_PROPERTY_TYPE, DefinitionProperty, DefinitionPropertyMeta } from "@xyd-js/uniform";
|
|
3
3
|
|
|
4
|
-
import {MDXReference, mdxValue} from "@/utils/mdx"
|
|
5
4
|
import * as cn from "./ApiRefProperties.styles";
|
|
5
|
+
import { AtlasContext, useBaseMatch } from "@/components/Atlas/AtlasContext";
|
|
6
|
+
import { Badge } from "@xyd-js/components/writer";
|
|
6
7
|
|
|
7
8
|
export interface ApiRefPropertiesProps {
|
|
8
|
-
properties:
|
|
9
|
+
properties: DefinitionProperty[]
|
|
9
10
|
}
|
|
10
11
|
|
|
11
|
-
|
|
12
|
+
// TODO: in the future configurable
|
|
13
|
+
const HIDE_INTERNAL = true
|
|
14
|
+
|
|
15
|
+
export function ApiRefProperties({ properties }: ApiRefPropertiesProps) {
|
|
12
16
|
return <ul className={cn.ApiRefPropertiesUlHost}>
|
|
13
17
|
{
|
|
14
|
-
properties?.map((property, i) =>
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
18
|
+
filterProperties(properties)?.map((property, i) => {
|
|
19
|
+
const propName = property.name
|
|
20
|
+
const propValue = property.type
|
|
21
|
+
const propertyProperties = propProperties(property)
|
|
22
|
+
const description = property.ofProperty?.description || property.description || ""
|
|
23
|
+
const metaInfo = renderMetaInfo(property.meta)
|
|
24
|
+
|
|
25
|
+
return <li className={cn.ApiRefPropertiesLiHost} key={i}>
|
|
26
|
+
{
|
|
27
|
+
propName || propValue ?
|
|
28
|
+
<dl className={cn.ApiRefPropertiesDlHost}>
|
|
29
|
+
<PropName property={property} meta={property.meta || []} />
|
|
30
|
+
<PropType
|
|
31
|
+
property={property}
|
|
32
|
+
/>
|
|
33
|
+
<PropMetaList
|
|
34
|
+
metas={property.meta || []}
|
|
35
|
+
/>
|
|
36
|
+
</dl> : null
|
|
37
|
+
}
|
|
38
|
+
|
|
27
39
|
{
|
|
28
|
-
|
|
40
|
+
description || metaInfo ? <div className={cn.ApiRefPropertiesDescriptionHost}>
|
|
41
|
+
<>
|
|
42
|
+
<div>
|
|
43
|
+
{description}
|
|
44
|
+
</div>
|
|
45
|
+
<div>
|
|
46
|
+
{renderMetaInfo(property.meta)}
|
|
47
|
+
</div>
|
|
48
|
+
</>
|
|
49
|
+
</div> : null
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
{
|
|
53
|
+
propertyProperties?.length > 0 ?
|
|
29
54
|
<SubProperties
|
|
30
|
-
|
|
55
|
+
parent={property}
|
|
56
|
+
properties={propertyProperties}
|
|
31
57
|
/> : null
|
|
32
58
|
}
|
|
33
59
|
</li>
|
|
34
|
-
)
|
|
60
|
+
})
|
|
35
61
|
}
|
|
36
62
|
</ul>
|
|
37
63
|
}
|
|
38
64
|
|
|
39
|
-
|
|
40
|
-
|
|
65
|
+
|
|
66
|
+
interface PropNameProps {
|
|
67
|
+
property: DefinitionProperty
|
|
68
|
+
meta: DefinitionPropertyMeta[]
|
|
69
|
+
parentChoiceType?: boolean
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function PropName(props: PropNameProps) {
|
|
73
|
+
const value = props.property.name
|
|
74
|
+
|
|
75
|
+
if (!value) {
|
|
76
|
+
return null
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return <atlas-apiref-propname>
|
|
41
80
|
<dd>
|
|
42
|
-
<code
|
|
81
|
+
<code
|
|
82
|
+
data-parent-choice-type={props.parentChoiceType ? "true" : undefined}
|
|
83
|
+
className={cn.ApiRefPropertiesPropNameCodeHost}
|
|
84
|
+
>{value}</code>
|
|
43
85
|
</dd>
|
|
44
|
-
|
|
86
|
+
</atlas-apiref-propname>
|
|
45
87
|
}
|
|
46
88
|
|
|
47
|
-
|
|
48
|
-
|
|
89
|
+
interface PropTypeProps {
|
|
90
|
+
property: DefinitionProperty
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function PropType({ property }: PropTypeProps) {
|
|
94
|
+
const { Link = "a" } = useContext(AtlasContext)
|
|
95
|
+
const href = useSymbolLink(property)
|
|
96
|
+
|
|
97
|
+
const symbol = resolvePropertySymbol(property)
|
|
98
|
+
|
|
99
|
+
let propSymbol: string | React.ReactNode = symbol
|
|
100
|
+
|
|
101
|
+
if (!propSymbol) {
|
|
102
|
+
return null
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (href) {
|
|
106
|
+
propSymbol = <Link className={cn.ApiRefPropertiesPropTypeCodeLink} href={href}>{propSymbol}</Link>
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
return <atlas-apiref-proptype>
|
|
49
110
|
<dd>
|
|
50
111
|
<code className={cn.ApiRefPropertiesPropTypeCodeHost}>
|
|
112
|
+
{propSymbol}
|
|
113
|
+
</code>
|
|
114
|
+
</dd>
|
|
115
|
+
</atlas-apiref-proptype>
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export interface PropMetaProps extends DefinitionPropertyMeta {
|
|
119
|
+
href?: string
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function PropMeta(props: PropMetaProps) {
|
|
123
|
+
let valueText = props.value
|
|
124
|
+
|
|
125
|
+
switch (props.name) {
|
|
126
|
+
case "required":
|
|
127
|
+
valueText = "Required"
|
|
128
|
+
break
|
|
129
|
+
case "deprecated":
|
|
130
|
+
valueText = "Deprecated"
|
|
131
|
+
break
|
|
132
|
+
case "defaults":
|
|
133
|
+
valueText = `Defaults: ${props.value}`
|
|
134
|
+
break
|
|
135
|
+
case "nullable":
|
|
136
|
+
return null
|
|
137
|
+
case "enum-type":
|
|
138
|
+
return null
|
|
139
|
+
case "minimum":
|
|
140
|
+
return null
|
|
141
|
+
case "maximum":
|
|
142
|
+
return null
|
|
143
|
+
case "example":
|
|
144
|
+
return null
|
|
145
|
+
case "examples":
|
|
146
|
+
return null
|
|
147
|
+
case "internal":
|
|
148
|
+
return null
|
|
149
|
+
case "hasArguments":
|
|
150
|
+
return null
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
return <atlas-apiref-propmeta data-name={props.name} data-value={props.value}>
|
|
154
|
+
<dd>
|
|
155
|
+
<code>
|
|
51
156
|
{
|
|
52
|
-
href
|
|
53
|
-
? <a
|
|
54
|
-
:
|
|
157
|
+
props.href
|
|
158
|
+
? <a href={props.href}>{valueText}</a>
|
|
159
|
+
: valueText
|
|
55
160
|
}
|
|
56
161
|
</code>
|
|
57
162
|
</dd>
|
|
163
|
+
</atlas-apiref-propmeta>
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export interface PropMetaListProps {
|
|
167
|
+
metas: PropMetaProps[]
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function PropMetaList({ metas }: PropMetaListProps) {
|
|
171
|
+
const order = { deprecated: 0, required: 1, defaults: 2 };
|
|
172
|
+
|
|
173
|
+
const sortedMetas = [...metas].sort((a, b) => {
|
|
174
|
+
return (order[a.name as keyof typeof order] ?? 3) - (order[b.name as keyof typeof order] ?? 3);
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
return <>
|
|
178
|
+
{
|
|
179
|
+
sortedMetas.map((meta, i) => (
|
|
180
|
+
<PropMeta
|
|
181
|
+
key={i}
|
|
182
|
+
{...meta}
|
|
183
|
+
/>
|
|
184
|
+
))
|
|
185
|
+
}
|
|
58
186
|
</>
|
|
59
187
|
}
|
|
60
188
|
|
|
61
|
-
|
|
189
|
+
interface SubPropertiesProps {
|
|
190
|
+
parent: DefinitionProperty
|
|
191
|
+
|
|
192
|
+
properties: DefinitionProperty[]
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function SubProperties({ parent, properties }: SubPropertiesProps) {
|
|
62
196
|
const [expanded, setExpanded] = useState(false)
|
|
63
197
|
|
|
198
|
+
// Get the actual properties to display
|
|
199
|
+
const foundProperties = filterProperties(properties || [])
|
|
200
|
+
|
|
201
|
+
const choiceType = isChoiceType(parent)
|
|
202
|
+
const noChildProps = function () {
|
|
203
|
+
if (parent?.type === DEFINED_DEFINITION_PROPERTY_TYPE.ENUM) {
|
|
204
|
+
return false
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
return foundProperties.every(prop => {
|
|
208
|
+
if (prop.ofProperty) {
|
|
209
|
+
return false
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
return !(prop.properties?.length ?? 0)
|
|
213
|
+
})
|
|
214
|
+
}()
|
|
215
|
+
|
|
216
|
+
if (choiceType && noChildProps) {
|
|
217
|
+
return null
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
const hasArguments = parent.meta?.some(m => m.name === 'hasArguments' && m.value === 'true')
|
|
221
|
+
|
|
64
222
|
return <>
|
|
65
|
-
<PropToggle
|
|
223
|
+
{foundProperties?.length ? <PropToggle
|
|
224
|
+
choiceType={choiceType}
|
|
225
|
+
isArgument={hasArguments}
|
|
66
226
|
onClick={() => setExpanded(!expanded)}
|
|
67
227
|
isExpanded={expanded}
|
|
68
|
-
/>
|
|
228
|
+
/> : null}
|
|
69
229
|
|
|
70
230
|
<div
|
|
71
231
|
className={`${cn.ApiRefPropertiesSubPropsHost} ${expanded && cn.ApiRefPropertiesSubPropsHostExpanded}`}
|
|
@@ -73,23 +233,51 @@ function SubProperties({properties}: { properties: MDXReference<DefinitionProper
|
|
|
73
233
|
<div className={cn.ApiRefPropertiesSubPropsBox}>
|
|
74
234
|
<ul role="list" className={cn.ApiRefPropertiesSubPropsUl}>
|
|
75
235
|
{
|
|
76
|
-
|
|
236
|
+
foundProperties?.map((prop, i) => {
|
|
237
|
+
const propName = prop.name
|
|
238
|
+
const propValue = prop.type
|
|
239
|
+
const properties = propProperties(prop)
|
|
240
|
+
const description = prop.ofProperty?.description || prop.description || ""
|
|
241
|
+
const metaInfo = renderMetaInfo(prop.meta)
|
|
242
|
+
|
|
77
243
|
return <li className={cn.ApiRefPropertiesSubPropsLi} key={i}>
|
|
78
|
-
<dl className={cn.ApiRefPropertiesDlHost}>
|
|
79
|
-
<PropName name="name" value={mdxValue(prop.name)}/>
|
|
80
|
-
<PropType
|
|
81
|
-
name="type"
|
|
82
|
-
value={mdxValue(prop.type)}
|
|
83
|
-
href={propertyTypeHref(prop)}
|
|
84
|
-
/>
|
|
85
|
-
</dl>
|
|
86
|
-
<div className={cn.ApiRefPropertiesDescriptionHost}>
|
|
87
|
-
{prop.children}
|
|
88
|
-
</div>
|
|
89
244
|
{
|
|
90
|
-
|
|
245
|
+
propName || propValue ?
|
|
246
|
+
<dl className={cn.ApiRefPropertiesDlHost}>
|
|
247
|
+
<PropName
|
|
248
|
+
property={prop}
|
|
249
|
+
meta={prop.meta || []}
|
|
250
|
+
parentChoiceType={choiceType || !!hasArguments}
|
|
251
|
+
/>
|
|
252
|
+
<PropType
|
|
253
|
+
property={prop}
|
|
254
|
+
/>
|
|
255
|
+
<PropMetaList
|
|
256
|
+
metas={prop.meta || []}
|
|
257
|
+
/>
|
|
258
|
+
</dl> : null
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
{
|
|
262
|
+
description || metaInfo
|
|
263
|
+
? <div className={cn.ApiRefPropertiesDescriptionHost}>
|
|
264
|
+
<>
|
|
265
|
+
<div>
|
|
266
|
+
{description}
|
|
267
|
+
</div>
|
|
268
|
+
<div>
|
|
269
|
+
{renderMetaInfo(prop.meta)}
|
|
270
|
+
</div>
|
|
271
|
+
</>
|
|
272
|
+
</div>
|
|
273
|
+
: null
|
|
274
|
+
}
|
|
275
|
+
{
|
|
276
|
+
properties?.length ?
|
|
91
277
|
<SubProperties
|
|
92
|
-
|
|
278
|
+
parent={prop}
|
|
279
|
+
properties={properties}
|
|
280
|
+
/> : null
|
|
93
281
|
}
|
|
94
282
|
</li>
|
|
95
283
|
})
|
|
@@ -100,12 +288,25 @@ function SubProperties({properties}: { properties: MDXReference<DefinitionProper
|
|
|
100
288
|
</>
|
|
101
289
|
}
|
|
102
290
|
|
|
291
|
+
|
|
103
292
|
interface PropsToggleProps {
|
|
104
293
|
isExpanded: boolean
|
|
294
|
+
choiceType: boolean
|
|
295
|
+
isArgument?: boolean
|
|
105
296
|
onClick: () => void
|
|
106
297
|
}
|
|
107
298
|
|
|
108
|
-
function PropToggle(
|
|
299
|
+
function PropToggle(
|
|
300
|
+
props: PropsToggleProps
|
|
301
|
+
) {
|
|
302
|
+
let text = props.isExpanded ? 'Hide properties' : 'Show properties'
|
|
303
|
+
|
|
304
|
+
if (props.choiceType) {
|
|
305
|
+
text = props.isExpanded ? 'Hide possible types' : 'Show possible types'
|
|
306
|
+
} else if (props.isArgument) {
|
|
307
|
+
text = props.isExpanded ? 'Hide possible arguments' : 'Show possible arguments'
|
|
308
|
+
}
|
|
309
|
+
|
|
109
310
|
return (
|
|
110
311
|
<button
|
|
111
312
|
aria-expanded={props.isExpanded}
|
|
@@ -130,18 +331,335 @@ function PropToggle(props: PropsToggleProps) {
|
|
|
130
331
|
clipRule="evenodd"
|
|
131
332
|
/>
|
|
132
333
|
</svg>
|
|
133
|
-
<span className={cn.ApiRefPropertiesPropToggleLink}>
|
|
334
|
+
<span className={cn.ApiRefPropertiesPropToggleLink}>
|
|
335
|
+
{text}
|
|
336
|
+
</span>
|
|
134
337
|
</button>
|
|
135
338
|
)
|
|
136
339
|
}
|
|
137
340
|
|
|
138
|
-
function
|
|
139
|
-
if (property
|
|
140
|
-
return
|
|
341
|
+
function isChoiceType(property: DefinitionProperty) {
|
|
342
|
+
if (property.ofProperty) {
|
|
343
|
+
return isChoiceType(property.ofProperty)
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
return [
|
|
347
|
+
DEFINED_DEFINITION_PROPERTY_TYPE.UNION,
|
|
348
|
+
DEFINED_DEFINITION_PROPERTY_TYPE.XOR,
|
|
349
|
+
DEFINED_DEFINITION_PROPERTY_TYPE.ENUM,
|
|
350
|
+
].includes(property.type as DEFINED_DEFINITION_PROPERTY_TYPE)
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
function useSymbolLink(property: DefinitionProperty) {
|
|
354
|
+
const baseMatch = useBaseMatch()
|
|
355
|
+
|
|
356
|
+
if (!property?.symbolDef?.canonical?.length) {
|
|
357
|
+
return ""
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
let symbolLink = property.symbolDef.canonical
|
|
361
|
+
|
|
362
|
+
if (!Array.isArray(symbolLink)) { // TODO: support array of canonicals
|
|
363
|
+
if (!symbolLink.startsWith("/")) {
|
|
364
|
+
symbolLink = "/" + symbolLink
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
return `${baseMatch}${symbolLink}`;
|
|
368
|
+
} else {
|
|
369
|
+
console.warn("Multiple canonical links found for property", property.name, property.symbolDef.canonical)
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
return ""
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
function propProperties(prop: DefinitionProperty): DefinitionProperty[] {
|
|
376
|
+
if (prop.properties?.length) {
|
|
377
|
+
return prop.properties
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
if (prop.ofProperty) {
|
|
381
|
+
return propProperties(prop.ofProperty)
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
return []
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
function filterProperties(properties: DefinitionProperty[]): DefinitionProperty[] {
|
|
388
|
+
return properties.filter(property => {
|
|
389
|
+
if (property?.meta?.some(m => m.name === "internal" && m.value === "true")) {
|
|
390
|
+
if (HIDE_INTERNAL) {
|
|
391
|
+
return false
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
return true
|
|
396
|
+
})
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
function resolvePropertySymbol(property: DefinitionProperty): string {
|
|
400
|
+
function resolvePropertySymbolInner(property: DefinitionProperty) {
|
|
401
|
+
if (property?.ofProperty) {
|
|
402
|
+
switch (property.ofProperty.type) {
|
|
403
|
+
case DEFINED_DEFINITION_PROPERTY_TYPE.ARRAY: {
|
|
404
|
+
let ofOfSymbols: string[] = []
|
|
405
|
+
|
|
406
|
+
if (property.type) {
|
|
407
|
+
ofOfSymbols.push(property.type)
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
if (property.ofProperty.ofProperty) {
|
|
411
|
+
const symbol = groupSymbol(property.ofProperty.ofProperty)
|
|
412
|
+
|
|
413
|
+
if (symbol) {
|
|
414
|
+
ofOfSymbols.push(symbol)
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
const atomicDefinedSymbol = atomicDefinedPropertySymbol(property.ofProperty)
|
|
419
|
+
const ofPrefix = [
|
|
420
|
+
atomicDefinedSymbol,
|
|
421
|
+
"of"
|
|
422
|
+
]
|
|
423
|
+
|
|
424
|
+
return [
|
|
425
|
+
[
|
|
426
|
+
...ofPrefix,
|
|
427
|
+
...ofOfSymbols
|
|
428
|
+
].join(" ")
|
|
429
|
+
]
|
|
430
|
+
}
|
|
431
|
+
case DEFINED_DEFINITION_PROPERTY_TYPE.UNION:
|
|
432
|
+
case DEFINED_DEFINITION_PROPERTY_TYPE.ENUM:
|
|
433
|
+
case DEFINED_DEFINITION_PROPERTY_TYPE.XOR: {
|
|
434
|
+
if (property.ofProperty.properties?.length) {
|
|
435
|
+
const atomicDefinedSymbol = atomicDefinedPropertySymbol(property)
|
|
436
|
+
|
|
437
|
+
if (atomicDefinedSymbol) {
|
|
438
|
+
const unionSymbol = groupSymbol({
|
|
439
|
+
name: "",
|
|
440
|
+
description: "",
|
|
441
|
+
type: DEFINED_DEFINITION_PROPERTY_TYPE.UNION,
|
|
442
|
+
properties: property.ofProperty.properties || [],
|
|
443
|
+
})
|
|
444
|
+
|
|
445
|
+
if (unionSymbol?.length && unionSymbol.includes("$$")) {
|
|
446
|
+
return [atomicDefinedSymbol]
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
return [
|
|
450
|
+
[
|
|
451
|
+
atomicDefinedSymbol,
|
|
452
|
+
"of",
|
|
453
|
+
unionSymbol
|
|
454
|
+
].join(" ")
|
|
455
|
+
]
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
return [
|
|
459
|
+
property.type,
|
|
460
|
+
groupSymbol(property.ofProperty)
|
|
461
|
+
]
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
if (property.ofProperty?.ofProperty) {
|
|
465
|
+
return [property.ofProperty?.ofProperty?.type]
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
return []
|
|
469
|
+
}
|
|
470
|
+
default: {
|
|
471
|
+
if (!property.ofProperty.name) {
|
|
472
|
+
const defined = atomicDefinedPropertySymbol(property)
|
|
473
|
+
const symbol = atomicPropertySymbol(property)
|
|
474
|
+
|
|
475
|
+
if (symbol.startsWith("$$")) {
|
|
476
|
+
return [property.ofProperty.type]
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
const chains = [
|
|
480
|
+
symbol
|
|
481
|
+
]
|
|
482
|
+
|
|
483
|
+
if (defined) {
|
|
484
|
+
chains.push("of")
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
chains.push(
|
|
488
|
+
groupSymbol(property.ofProperty)
|
|
489
|
+
)
|
|
490
|
+
|
|
491
|
+
return chains
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
return [
|
|
495
|
+
property.ofProperty.type
|
|
496
|
+
]
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
switch (property.type) {
|
|
502
|
+
case DEFINED_DEFINITION_PROPERTY_TYPE.UNION, DEFINED_DEFINITION_PROPERTY_TYPE.XOR: {
|
|
503
|
+
if (property.properties?.length) {
|
|
504
|
+
const respMap = {}
|
|
505
|
+
let resp: string[] = []
|
|
506
|
+
for (const prop of property.properties) {
|
|
507
|
+
let symbols = resolvePropertySymbolInner(prop)
|
|
508
|
+
|
|
509
|
+
if (prop.ofProperty && symbols.length > 1) {
|
|
510
|
+
symbols = [[
|
|
511
|
+
symbols[0],
|
|
512
|
+
...symbols.slice(1, symbols.length),
|
|
513
|
+
].join("")]
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
resp.push(...symbols)
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
let hasOr = false // TODO: in the future better
|
|
520
|
+
for (const symbol of resp) {
|
|
521
|
+
if (symbol.trim() === "or") {
|
|
522
|
+
hasOr = true
|
|
523
|
+
break
|
|
524
|
+
}
|
|
525
|
+
respMap[symbol] = true
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
if (!hasOr) {
|
|
529
|
+
resp = Object.keys(respMap)
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
return [resp.join(" or ")]
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
break
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
case DEFINED_DEFINITION_PROPERTY_TYPE.ARRAY: {
|
|
539
|
+
return ["array"]
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
case DEFINED_DEFINITION_PROPERTY_TYPE.ENUM: {
|
|
543
|
+
return ["enum"]
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
if (property.type?.startsWith("$$")) {
|
|
548
|
+
return []
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
return [property.type]
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
const symbolsParts = resolvePropertySymbolInner(property)
|
|
555
|
+
if (nullableProperty(property)) {
|
|
556
|
+
if (symbolsParts.length) {
|
|
557
|
+
symbolsParts.push("or", "null")
|
|
558
|
+
} else {
|
|
559
|
+
symbolsParts.push("null")
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
return symbolsParts.join(" ")
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
function atomicDefinedPropertySymbol(property: DefinitionProperty): string {
|
|
567
|
+
switch (property.type) {
|
|
568
|
+
case DEFINED_DEFINITION_PROPERTY_TYPE.ARRAY: {
|
|
569
|
+
return "array"
|
|
570
|
+
}
|
|
571
|
+
case DEFINED_DEFINITION_PROPERTY_TYPE.UNION:
|
|
572
|
+
case DEFINED_DEFINITION_PROPERTY_TYPE.ENUM:
|
|
573
|
+
case DEFINED_DEFINITION_PROPERTY_TYPE.XOR: {
|
|
574
|
+
return ""
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
default: {
|
|
578
|
+
return ""
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
function groupSymbol(property: DefinitionProperty) {
|
|
584
|
+
const symbol = resolvePropertySymbol(property)
|
|
585
|
+
if (symbol?.startsWith("$$")) {
|
|
586
|
+
return ""
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
return symbol
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
function atomicPropertySymbol(property: DefinitionProperty): string {
|
|
593
|
+
const defined = atomicDefinedPropertySymbol(property)
|
|
594
|
+
|
|
595
|
+
if (!defined) {
|
|
596
|
+
return property.type
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
return defined
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
function nullableProperty(property: DefinitionProperty): boolean {
|
|
603
|
+
return property.meta?.some(m => m.name === "nullable" && m.value === "true") || false
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
function renderMetaInfo(meta: DefinitionPropertyMeta[] | undefined) {
|
|
607
|
+
if (!meta?.length) return null;
|
|
608
|
+
|
|
609
|
+
const minimum = meta.find(m => m.name === 'minimum')?.value;
|
|
610
|
+
const maximum = meta.find(m => m.name === 'maximum')?.value;
|
|
611
|
+
const example = meta.find(m => m.name === 'example')?.value;
|
|
612
|
+
const examples = meta.find(m => m.name === 'examples')?.value;
|
|
613
|
+
|
|
614
|
+
const rangeInfo: React.ReactNode[] = [];
|
|
615
|
+
if (minimum !== undefined && maximum !== undefined) {
|
|
616
|
+
rangeInfo.push(
|
|
617
|
+
<div>
|
|
618
|
+
Required range: <Badge>
|
|
619
|
+
{`${minimum} <= x <= ${maximum}`}
|
|
620
|
+
</Badge>
|
|
621
|
+
</div>
|
|
622
|
+
);
|
|
623
|
+
} else if (minimum !== undefined) {
|
|
624
|
+
rangeInfo.push(
|
|
625
|
+
<div>
|
|
626
|
+
Required range: <Badge>
|
|
627
|
+
{`x >= ${minimum}`}
|
|
628
|
+
</Badge>
|
|
629
|
+
</div>
|
|
630
|
+
);
|
|
631
|
+
} else if (maximum !== undefined) {
|
|
632
|
+
rangeInfo.push(
|
|
633
|
+
<div>
|
|
634
|
+
Required range: <Badge>
|
|
635
|
+
{`x <= ${maximum}`}
|
|
636
|
+
</Badge>
|
|
637
|
+
</div>
|
|
638
|
+
);
|
|
141
639
|
}
|
|
142
640
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
641
|
+
const exampleInfo = example || examples ? <div part="examples">
|
|
642
|
+
<span>Examples:</span>
|
|
643
|
+
{
|
|
644
|
+
example ? <Badge>{`${example}`}</Badge> : null
|
|
645
|
+
}
|
|
646
|
+
{
|
|
647
|
+
Array.isArray(examples) && <div part="examples-list">
|
|
648
|
+
{examples.map((example, i) => (
|
|
649
|
+
<Badge key={`example-${i}`}>{`${example}`}</Badge>
|
|
650
|
+
))}
|
|
651
|
+
</div>
|
|
652
|
+
}
|
|
653
|
+
</div> : null
|
|
654
|
+
|
|
655
|
+
if (!rangeInfo?.length && !exampleInfo) {
|
|
656
|
+
return null
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
return <atlas-apiref-meta-info className={cn.ApiRefPropertiesMetaInfoHost}>
|
|
660
|
+
{rangeInfo?.map((info, i) => (
|
|
661
|
+
<div key={`range-${i}`}>{info}</div>
|
|
662
|
+
))}
|
|
663
|
+
{exampleInfo}
|
|
664
|
+
</atlas-apiref-meta-info>
|
|
147
665
|
}
|