@xyd-js/atlas 0.0.0-build-8b31648-20250923204702 → 0.0.0-build-9f87f13-20250930210637

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