@xyd-js/atlas 0.1.0-xyd.4 → 0.1.0-xyd.57
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 -27
- package/.storybook/preview.ts +1 -2
- package/CHANGELOG.md +554 -0
- package/LICENSE +21 -0
- package/dist/Update-48mkPPHi-COLbZvRj.js +4 -0
- package/dist/Update-48mkPPHi-COLbZvRj.js.map +1 -0
- package/dist/Update-6IvrCbUn-COLbZvRj.js +4 -0
- package/dist/Update-6IvrCbUn-COLbZvRj.js.map +1 -0
- package/dist/Update-B31SkKLO-COLbZvRj.js +4 -0
- package/dist/Update-B31SkKLO-COLbZvRj.js.map +1 -0
- package/dist/Update-BDC6jF5Q-COLbZvRj.js +4 -0
- package/dist/Update-BDC6jF5Q-COLbZvRj.js.map +1 -0
- package/dist/Update-BdhhXj2D-COLbZvRj.js +4 -0
- package/dist/Update-BdhhXj2D-COLbZvRj.js.map +1 -0
- package/dist/Update-BzuP6PUF-COLbZvRj.js +4 -0
- package/dist/Update-BzuP6PUF-COLbZvRj.js.map +1 -0
- package/dist/Update-C-w0Og8S-COLbZvRj.js +4 -0
- package/dist/Update-C-w0Og8S-COLbZvRj.js.map +1 -0
- package/dist/Update-CRZyUhwE-COLbZvRj.js +4 -0
- package/dist/Update-CRZyUhwE-COLbZvRj.js.map +1 -0
- package/dist/Update-Cmw6WVrs-COLbZvRj.js +4 -0
- package/dist/Update-Cmw6WVrs-COLbZvRj.js.map +1 -0
- package/dist/Update-D5pUmk9V-COLbZvRj.js +4 -0
- package/dist/Update-D5pUmk9V-COLbZvRj.js.map +1 -0
- package/dist/Update-D7tzid9y-COLbZvRj.js +4 -0
- package/dist/Update-D7tzid9y-COLbZvRj.js.map +1 -0
- package/dist/Update-DDQewhuu-COLbZvRj.js +4 -0
- package/dist/Update-DDQewhuu-COLbZvRj.js.map +1 -0
- package/dist/Update-DPeHa_01-COLbZvRj.js +4 -0
- package/dist/Update-DPeHa_01-COLbZvRj.js.map +1 -0
- package/dist/Update-DUFcLP3--COLbZvRj.js +4 -0
- package/dist/Update-DUFcLP3--COLbZvRj.js.map +1 -0
- package/dist/Update-DbvzJGdB-COLbZvRj.js +4 -0
- package/dist/Update-DbvzJGdB-COLbZvRj.js.map +1 -0
- package/dist/Update-SFXhorqS-COLbZvRj.js +4 -0
- package/dist/Update-SFXhorqS-COLbZvRj.js.map +1 -0
- package/dist/Update-b8FT7xsG-COLbZvRj.js +4 -0
- package/dist/Update-b8FT7xsG-COLbZvRj.js.map +1 -0
- package/dist/index.css +43 -53
- package/dist/index.d.ts +30 -10
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -0
- package/dist/styles.css +89 -0
- package/dist/tokens.css +60 -0
- package/dist/xydPlugin.d.ts +5 -0
- package/dist/xydPlugin.js +2 -0
- package/dist/xydPlugin.js.map +1 -0
- package/index.ts +1 -2
- package/package.json +27 -21
- package/packages/xyd-plugin/SidebarItem.tsx +27 -0
- package/packages/xyd-plugin/index.ts +20 -0
- package/rollup.config.js +66 -21
- package/src/components/ApiRef/ApiRefItem/ApiRefItem.styles.tsx +95 -63
- package/src/components/ApiRef/ApiRefItem/ApiRefItem.tsx +512 -52
- package/src/components/ApiRef/ApiRefProperties/ApiRefProperties.styles.tsx +186 -138
- package/src/components/ApiRef/ApiRefProperties/ApiRefProperties.tsx +590 -59
- package/src/components/ApiRef/ApiRefSamples/ApiRefSamples.styles.tsx +19 -23
- package/src/components/ApiRef/ApiRefSamples/ApiRefSamples.tsx +39 -24
- package/src/components/Atlas/Atlas.styles.tsx +3 -5
- package/src/components/Atlas/Atlas.tsx +35 -17
- 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.styles.tsx +7 -8
- package/src/components/Atlas/AtlasLazy/AtlasLazy.tsx +5 -8
- 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 +56 -65
- package/src/components/Code/CodeSampleButtons/CodeSampleButtons.tsx +20 -29
- package/src/components/Code/index.ts +0 -4
- package/src/components/Icon/index.tsx +384 -0
- package/src/docs/AtlasExample/todo-app.uniform.json +1 -1
- package/src/styles/styles.css +89 -0
- package/src/styles/tokens.css +60 -0
- package/src/utils/mdx.ts +0 -29
- package/tsconfig.json +9 -2
- package/types.d.ts +22 -0
- package/src/components/Code/CodeCopy/CodeCopy.style.tsx +0 -21
- package/src/components/Code/CodeCopy/CodeCopy.tsx +0 -32
- package/src/components/Code/CodeCopy/index.ts +0 -7
- package/src/components/Code/CodeSample/CodeSample.styles.tsx +0 -134
- package/src/components/Code/CodeSample/CodeSample.tsx +0 -149
- 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,91 +1,283 @@
|
|
|
1
|
-
import React, {useState} from "react";
|
|
2
|
-
import {DefinitionProperty} from "@xyd-js/uniform";
|
|
3
|
-
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
$li,
|
|
8
|
-
$description,
|
|
9
|
-
$dl,
|
|
10
|
-
$propNameCode,
|
|
11
|
-
$propTypeCode,
|
|
12
|
-
$subProps,
|
|
13
|
-
$propToggle,
|
|
14
|
-
} from "./ApiRefProperties.styles";
|
|
1
|
+
import React, { useContext, useState } from "react";
|
|
2
|
+
import { DEFINED_DEFINITION_PROPERTY_TYPE, DefinitionProperty, DefinitionPropertyMeta } from "@xyd-js/uniform";
|
|
3
|
+
|
|
4
|
+
import * as cn from "./ApiRefProperties.styles";
|
|
5
|
+
import { AtlasContext, useBaseMatch } from "@/components/Atlas/AtlasContext";
|
|
6
|
+
import { Badge } from "@xyd-js/components/writer";
|
|
15
7
|
|
|
16
8
|
export interface ApiRefPropertiesProps {
|
|
17
|
-
properties:
|
|
9
|
+
properties: DefinitionProperty[]
|
|
18
10
|
}
|
|
19
11
|
|
|
20
|
-
|
|
21
|
-
|
|
12
|
+
// TODO: in the future configurable
|
|
13
|
+
const HIDE_INTERNAL = true
|
|
14
|
+
|
|
15
|
+
export function ApiRefProperties({ properties }: ApiRefPropertiesProps) {
|
|
16
|
+
return <ul className={cn.ApiRefPropertiesUlHost}>
|
|
22
17
|
{
|
|
23
|
-
properties?.map((property, i) =>
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
|
+
|
|
39
|
+
{
|
|
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
|
+
|
|
32
52
|
{
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
53
|
+
propertyProperties?.length > 0 ?
|
|
54
|
+
<SubProperties
|
|
55
|
+
parent={property}
|
|
56
|
+
properties={propertyProperties}
|
|
36
57
|
/> : null
|
|
37
58
|
}
|
|
38
59
|
</li>
|
|
39
|
-
)
|
|
60
|
+
})
|
|
40
61
|
}
|
|
41
62
|
</ul>
|
|
42
63
|
}
|
|
43
64
|
|
|
44
|
-
|
|
45
|
-
|
|
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>
|
|
46
80
|
<dd>
|
|
47
|
-
<code
|
|
81
|
+
<code
|
|
82
|
+
data-parent-choice-type={props.parentChoiceType ? "true" : undefined}
|
|
83
|
+
className={cn.ApiRefPropertiesPropNameCodeHost}
|
|
84
|
+
>{value}</code>
|
|
48
85
|
</dd>
|
|
49
|
-
|
|
86
|
+
</atlas-apiref-propname>
|
|
50
87
|
}
|
|
51
88
|
|
|
52
|
-
|
|
53
|
-
|
|
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>
|
|
54
110
|
<dd>
|
|
55
|
-
<code className={
|
|
111
|
+
<code className={cn.ApiRefPropertiesPropTypeCodeHost}>
|
|
112
|
+
{propSymbol}
|
|
113
|
+
</code>
|
|
56
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>
|
|
156
|
+
{
|
|
157
|
+
props.href
|
|
158
|
+
? <a href={props.href}>{valueText}</a>
|
|
159
|
+
: valueText
|
|
160
|
+
}
|
|
161
|
+
</code>
|
|
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
|
+
}
|
|
57
186
|
</>
|
|
58
187
|
}
|
|
59
188
|
|
|
60
|
-
|
|
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
|
-
|
|
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
|
-
className={`${
|
|
231
|
+
className={`${cn.ApiRefPropertiesSubPropsHost} ${expanded && cn.ApiRefPropertiesSubPropsHostExpanded}`}
|
|
72
232
|
>
|
|
73
|
-
<div className={
|
|
74
|
-
<ul role="list" className={
|
|
233
|
+
<div className={cn.ApiRefPropertiesSubPropsBox}>
|
|
234
|
+
<ul role="list" className={cn.ApiRefPropertiesSubPropsUl}>
|
|
75
235
|
{
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
</div>
|
|
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
|
+
|
|
243
|
+
return <li className={cn.ApiRefPropertiesSubPropsLi} key={i}>
|
|
85
244
|
{
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
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 ?
|
|
277
|
+
<SubProperties
|
|
278
|
+
parent={prop}
|
|
279
|
+
properties={properties}
|
|
280
|
+
/> : null
|
|
89
281
|
}
|
|
90
282
|
</li>
|
|
91
283
|
})
|
|
@@ -99,16 +291,28 @@ function $SubProperties({properties}: { properties: MDXReference<DefinitionPrope
|
|
|
99
291
|
|
|
100
292
|
interface PropsToggleProps {
|
|
101
293
|
isExpanded: boolean
|
|
294
|
+
choiceType: boolean
|
|
295
|
+
isArgument?: boolean
|
|
102
296
|
onClick: () => void
|
|
103
297
|
}
|
|
104
298
|
|
|
105
|
-
function
|
|
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
|
+
|
|
106
310
|
return (
|
|
107
311
|
<button
|
|
108
312
|
aria-expanded={props.isExpanded}
|
|
109
313
|
aria-controls="chat/object-usage_table"
|
|
110
314
|
onClick={props.onClick}
|
|
111
|
-
className={
|
|
315
|
+
className={cn.ApiRefPropertiesPropToggleHost}
|
|
112
316
|
>
|
|
113
317
|
<svg
|
|
114
318
|
xmlns="http://www.w3.org/2000/svg"
|
|
@@ -127,8 +331,335 @@ function $PropToggle(props: PropsToggleProps) {
|
|
|
127
331
|
clipRule="evenodd"
|
|
128
332
|
/>
|
|
129
333
|
</svg>
|
|
130
|
-
<span className={
|
|
334
|
+
<span className={cn.ApiRefPropertiesPropToggleLink}>
|
|
335
|
+
{text}
|
|
336
|
+
</span>
|
|
131
337
|
</button>
|
|
132
338
|
)
|
|
133
339
|
}
|
|
134
340
|
|
|
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
|
+
);
|
|
639
|
+
}
|
|
640
|
+
|
|
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>
|
|
665
|
+
}
|