@open-resource-discovery/metadata-renderer 1.0.0 → 1.0.1

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.
@@ -4,9 +4,8 @@ import { AsyncApiCustomAttributesConfig } from './customAttributes/types';
4
4
  export type AsyncApiRendererProps = {
5
5
  content: string;
6
6
  config?: Partial<ConfigInterface>;
7
- showCustomAttributes?: boolean;
8
7
  customAttributes?: AsyncApiCustomAttributesConfig[];
9
8
  className?: string;
10
9
  theme?: RendererTheme;
11
10
  };
12
- export declare function AsyncApiRenderer({ content, config, showCustomAttributes, customAttributes, className, theme, }: AsyncApiRendererProps): import("react").JSX.Element;
11
+ export declare function AsyncApiRenderer({ content, config, customAttributes, className, theme }: AsyncApiRendererProps): import("react").JSX.Element;
package/dist/asyncapi.js CHANGED
@@ -1,2 +1,2 @@
1
- import { t as AsyncApiRenderer } from "./chunks/asyncApi-K0uQpQwz.js";
1
+ import { t as AsyncApiRenderer } from "./chunks/asyncApi-DtAXW7IY.js";
2
2
  export { AsyncApiRenderer };
@@ -330,146 +330,6 @@ function buildRootExtensionsPlugin(configs) {
330
330
  };
331
331
  }
332
332
  //#endregion
333
- //#region src/lib/asyncApi/customAttributes/stateInfo.tsx
334
- var background = {
335
- ACTIVE: "color-mix(in srgb, #22c55e 15%, transparent)",
336
- BETA: "color-mix(in srgb, #3b82f6 15%, transparent)",
337
- DEPRECATED: "color-mix(in srgb, #f97316 15%, transparent)",
338
- DECOMMISSIONED: "color-mix(in srgb, #ef4444 15%, transparent)"
339
- };
340
- var color = {
341
- ACTIVE: "#16a34a",
342
- BETA: "#2563eb",
343
- DEPRECATED: "#ea580c",
344
- DECOMMISSIONED: "#dc2626"
345
- };
346
- function AsyncApiStateInfo({ propertyName, propertyValue }) {
347
- if (!propertyValue || typeof propertyValue !== "object") return null;
348
- const info = propertyValue;
349
- const status = info.state?.toUpperCase();
350
- const badge = /* @__PURE__ */ jsx("span", {
351
- style: {
352
- display: "inline-block",
353
- borderRadius: "10px",
354
- padding: "0 6px",
355
- background: background[status] || "",
356
- color: color[status] || ""
357
- },
358
- children: status
359
- });
360
- const dateFormatter = new Intl.DateTimeFormat("en-GB", { dateStyle: "long" });
361
- const formatDate = (d) => {
362
- const parsed = new Date(d);
363
- return isNaN(parsed.getTime()) ? d : dateFormatter.format(parsed);
364
- };
365
- return /* @__PURE__ */ jsxs("div", {
366
- className: "asyncapi-attr-row",
367
- children: [/* @__PURE__ */ jsxs("div", {
368
- className: "asyncapi-attr-label",
369
- children: ["API State ", /* @__PURE__ */ jsx(AttributeLink, { attributeName: propertyName })]
370
- }), /* @__PURE__ */ jsxs("div", {
371
- className: "asyncapi-attr-value",
372
- children: [
373
- badge,
374
- info.deprecationDate && /* @__PURE__ */ jsxs("div", { children: ["Deprecated on ", formatDate(info.deprecationDate)] }),
375
- info.decommissionedDate && /* @__PURE__ */ jsxs("div", { children: ["Decommissioned on ", formatDate(info.decommissionedDate)] }),
376
- info.link && /* @__PURE__ */ jsxs("div", { children: ["More info: ", /* @__PURE__ */ jsx("a", {
377
- href: info.link,
378
- target: "_blank",
379
- rel: "noreferrer",
380
- className: "asyncapi-attr-link",
381
- children: info.link
382
- })] })
383
- ]
384
- })]
385
- });
386
- }
387
- //#endregion
388
- //#region src/lib/asyncApi/customAttributes/sapPreset.ts
389
- var sapAsyncApiAttributesConfig = {
390
- prefixStartsWith: "x-sap-",
391
- documentationUrl: (name) => `https://github.com/SAP/asyncapi-specification#${name}`,
392
- extensions: {
393
- "x-sap-catalog-spec-version": {
394
- type: "string",
395
- label: "SAP Catalog Spec Version"
396
- },
397
- "x-sap-application-namespace": {
398
- type: "string",
399
- label: "SAP Application Namespace"
400
- },
401
- "x-sap-ord-id": {
402
- type: "string",
403
- label: "ORD ID"
404
- },
405
- "x-sap-shortText": {
406
- type: "string",
407
- label: "SAP Short Text"
408
- },
409
- "x-sap-software-min-version": {
410
- type: "string",
411
- label: "SAP Software Version"
412
- },
413
- "x-sap-stateInfo": { component: AsyncApiStateInfo },
414
- "x-sap-event-spec-version": {
415
- type: "string",
416
- label: "SAP Event Spec Version"
417
- },
418
- "x-sap-event-source": {
419
- type: "string",
420
- label: "SAP Event Source"
421
- },
422
- "x-sap-event-source-parameters": {
423
- type: "object",
424
- label: "SAP Event Source Parameters"
425
- },
426
- "x-sap-event-version": {
427
- type: "string",
428
- label: "SAP Event Version"
429
- },
430
- "x-sap-event-characteristics": {
431
- type: "object",
432
- label: "SAP Event Characteristics"
433
- },
434
- "x-sap-object-type": {
435
- type: "string",
436
- label: "SAP Object Type"
437
- },
438
- "x-sap-odm-version": {
439
- type: "string",
440
- label: "SAP ODM Version"
441
- },
442
- "x-sap-logical-odm-event-version": {
443
- type: "string",
444
- label: "SAP Logical ODM Event Version"
445
- },
446
- "x-sap-dpp-entity-semantics": {
447
- type: "string",
448
- label: "SAP DPP: Entity Semantics"
449
- },
450
- "x-sap-dpp-data-subject-role": {
451
- type: "string",
452
- label: "SAP DPP: Data Subject Role"
453
- },
454
- "x-sap-dpp-data-subject-role-description": {
455
- type: "string",
456
- label: "SAP DPP: Data Subject Role Description"
457
- },
458
- "x-sap-dpp-field-semantics": {
459
- type: "string",
460
- label: "SAP DPP: Field Semantics"
461
- },
462
- "x-sap-dpp-is-potentially-personal": {
463
- type: "boolean",
464
- label: "SAP DPP: Potentially Personal"
465
- },
466
- "x-sap-dpp-is-potentially-sensitive": {
467
- type: "boolean",
468
- label: "SAP DPP: Potentially Sensitive"
469
- }
470
- }
471
- };
472
- //#endregion
473
333
  //#region src/lib/asyncApi/customAttributes/styles.ts
474
334
  var styles_default = `
475
335
  .asyncapi-attr-row {
@@ -590,19 +450,20 @@ function buildAsyncApiThemeStyle(id, theme) {
590
450
  if (borderRadius) rules.push(`${scope} .rounded, ${scope} .prose pre, ${scope} .\\32 xl\\:rounded { border-radius: ${borderRadius}px; }`, `${scope} .rounded:not(.inline-block) { overflow: hidden; }`, `${scope} .rounded-tl-none { border-top-left-radius: 0px; }`, `${scope} .examples { border-radius: 0px !important; }`);
591
451
  return rules.join("\n");
592
452
  }
593
- function AsyncApiRenderer({ content, config, showCustomAttributes = true, customAttributes, className, theme }) {
453
+ function AsyncApiRenderer({ content, config, customAttributes, className, theme }) {
594
454
  const id = useId();
595
455
  const isDark = className?.split(/\s+/).includes("dark") ?? false;
596
456
  const effectiveTheme = theme ?? (isDark ? DARK_DEFAULTS : null);
597
457
  const themeStyle = effectiveTheme ? buildAsyncApiThemeStyle(id, effectiveTheme) : null;
598
- const activeConfigs = customAttributes ?? [sapAsyncApiAttributesConfig];
599
- const parsedDoc = useMemo(() => showCustomAttributes ? loadObject(content) : null, [content, showCustomAttributes]);
458
+ const activeConfigs = useMemo(() => customAttributes ?? [], [customAttributes]);
459
+ const isEnabled = customAttributes !== void 0;
460
+ const parsedDoc = useMemo(() => isEnabled ? loadObject(content) : null, [content, isEnabled]);
600
461
  const version = useMemo(() => {
601
462
  const doc = parsedDoc;
602
463
  return typeof doc?.asyncapi === "string" ? doc.asyncapi : "";
603
464
  }, [parsedDoc]);
604
465
  const effectiveConfig = useMemo(() => {
605
- if (!showCustomAttributes) return config ?? {};
466
+ if (!isEnabled) return config ?? {};
606
467
  const extensions = buildAsyncApiExtensionsConfig(activeConfigs, parsedDoc, version);
607
468
  return {
608
469
  ...config,
@@ -613,12 +474,12 @@ function AsyncApiRenderer({ content, config, showCustomAttributes = true, custom
613
474
  };
614
475
  }, [
615
476
  config,
616
- showCustomAttributes,
477
+ isEnabled,
617
478
  activeConfigs,
618
479
  parsedDoc,
619
480
  version
620
481
  ]);
621
- const rootPlugin = useMemo(() => showCustomAttributes ? buildRootExtensionsPlugin(activeConfigs) : null, [showCustomAttributes, activeConfigs]);
482
+ const rootPlugin = useMemo(() => isEnabled ? buildRootExtensionsPlugin(activeConfigs) : null, [isEnabled, activeConfigs]);
622
483
  const scope = `[data-renderer-id="${id}"]`;
623
484
  const layoutStyle = `${scope} { container: asyncapi-attrs / inline-size; height: 100%; overflow: auto; scrollbar-gutter: stable; }\n${scope} :where(h1,h2,h3,h4,p,span,strong,a,li,td,div):not(pre *) { overflow-wrap: anywhere; }`;
624
485
  return /* @__PURE__ */ jsxs("div", {
@@ -626,9 +487,9 @@ function AsyncApiRenderer({ content, config, showCustomAttributes = true, custom
626
487
  className,
627
488
  children: [
628
489
  themeStyle && /* @__PURE__ */ jsx("style", { children: themeStyle }),
629
- showCustomAttributes && /* @__PURE__ */ jsx("style", { children: styles_default }),
490
+ isEnabled && /* @__PURE__ */ jsx("style", { children: styles_default }),
630
491
  /* @__PURE__ */ jsx("style", { children: layoutStyle }),
631
- showCustomAttributes && /* @__PURE__ */ jsx("style", { children: `[data-renderer-id="${id}"] #introduction .hidden { display: block !important; }` }),
492
+ isEnabled && /* @__PURE__ */ jsx("style", { children: `[data-renderer-id="${id}"] #introduction .hidden { display: block !important; }` }),
632
493
  /* @__PURE__ */ jsx(AsyncApiComponent, {
633
494
  schema: content,
634
495
  config: effectiveConfig,
@@ -638,4 +499,4 @@ function AsyncApiRenderer({ content, config, showCustomAttributes = true, custom
638
499
  });
639
500
  }
640
501
  //#endregion
641
- export { sapAsyncApiAttributesConfig as n, AsyncApiRenderer as t };
502
+ export { AttributeLink as n, AsyncApiRenderer as t };
@@ -309,169 +309,6 @@ function applyAnnotationRenderers(html, configs, doc) {
309
309
  return domDoc.body.innerHTML;
310
310
  }
311
311
  //#endregion
312
- //#region src/lib/csn/customAttributes/sapPreset.ts
313
- var sapCsnAttributesConfig = {
314
- prefixStartsWith: "@",
315
- annotations: {
316
- "@EndUserText.label": {
317
- type: "string",
318
- label: "End User Text · Label"
319
- },
320
- "@EndUserText.heading": {
321
- type: "string",
322
- label: "End User Text · Heading"
323
- },
324
- "@EndUserText.quickInfo": {
325
- type: "string",
326
- label: "End User Text · Quick Info"
327
- },
328
- "@ObjectModel.modelingPattern": {
329
- type: "object",
330
- label: "Modeling Pattern"
331
- },
332
- "@ObjectModel.text.element": {
333
- type: "array",
334
- label: "Text Element"
335
- },
336
- "@ObjectModel.text.association": {
337
- type: "object",
338
- label: "Text Association"
339
- },
340
- "@ObjectModel.semanticKey": {
341
- type: "array",
342
- label: "Semantic Key"
343
- },
344
- "@ObjectModel.representativeKey": {
345
- type: "object",
346
- label: "Representative Key"
347
- },
348
- "@ObjectModel.compositionRoot": {
349
- type: "boolean",
350
- label: "Composition Root"
351
- },
352
- "@ObjectModel.supportedCapabilities": {
353
- type: "array",
354
- label: "Supported Capabilities"
355
- },
356
- "@ObjectModel.usageType.sizeCategory": {
357
- type: "string",
358
- label: "Usage Type · Size Category"
359
- },
360
- "@ObjectModel.foreignKey.association": {
361
- type: "object",
362
- label: "Foreign Key Association"
363
- },
364
- "@Consumption.valueHelpDefinition": {
365
- type: "array",
366
- label: "Value Help"
367
- },
368
- "@Consumption.hidden": {
369
- type: "boolean",
370
- label: "Hidden"
371
- },
372
- "@PersonalData.entitySemantics": {
373
- type: "string",
374
- label: "DPP · Entity Semantics"
375
- },
376
- "@PersonalData.dataSubjectRole": {
377
- type: "string",
378
- label: "DPP · Data Subject Role"
379
- },
380
- "@PersonalData.dataSubjectRoleDescription": {
381
- type: "string",
382
- label: "DPP · Data Subject Role Description"
383
- },
384
- "@PersonalData.fieldSemantics": {
385
- type: "string",
386
- label: "DPP · Field Semantics"
387
- },
388
- "@PersonalData.isPotentiallyPersonal": {
389
- type: "boolean",
390
- label: "DPP · Potentially Personal"
391
- },
392
- "@PersonalData.isPotentiallySensitive": {
393
- type: "boolean",
394
- label: "DPP · Potentially Sensitive"
395
- },
396
- "@Semantics.currencyCode": {
397
- type: "boolean",
398
- label: "Semantics · Currency Code"
399
- },
400
- "@Semantics.amount.currencyCode": {
401
- type: "object",
402
- label: "Semantics · Amount Currency"
403
- },
404
- "@Semantics.unitOfMeasure": {
405
- type: "boolean",
406
- label: "Semantics · Unit of Measure"
407
- },
408
- "@Semantics.quantity.unitOfMeasure": {
409
- type: "object",
410
- label: "Semantics · Quantity Unit"
411
- },
412
- "@Semantics.text": {
413
- type: "boolean",
414
- label: "Semantics · Text"
415
- },
416
- "@Semantics.uuid": {
417
- type: "boolean",
418
- label: "Semantics · UUID"
419
- },
420
- "@Semantics.language": {
421
- type: "boolean",
422
- label: "Semantics · Language"
423
- },
424
- "@API.element.releaseState": {
425
- type: "string",
426
- label: "API · Element Release State"
427
- },
428
- "@API.entity.releaseState": {
429
- type: "string",
430
- label: "API · Entity Release State"
431
- },
432
- "@ODM.entityName": {
433
- type: "string",
434
- label: "ODM · Entity Name"
435
- },
436
- "@ODM.oid": {
437
- type: "string",
438
- label: "ODM · OID"
439
- },
440
- "@ODM.oidReference.entityName": {
441
- type: "string",
442
- label: "ODM · OID Reference Entity"
443
- },
444
- "@Aggregation.default": {
445
- type: "object",
446
- label: "Default Aggregation"
447
- },
448
- "@EntityRelationship.entityType": {
449
- type: "string",
450
- label: "Entity Relationship · Type"
451
- },
452
- "@EntityRelationship.entityIds": {
453
- type: "array",
454
- label: "Entity Relationship · IDs"
455
- },
456
- "@EntityRelationship.propertyType": {
457
- type: "string",
458
- label: "Entity Relationship · Property Type"
459
- },
460
- "@EntityRelationship.compositeReferences": {
461
- type: "array",
462
- label: "Entity Relationship · Composite References"
463
- },
464
- "@EntityRelationship.reference": {
465
- type: "array",
466
- label: "Entity Relationship · Reference"
467
- },
468
- "@DataIntegration.dataUnavailable": {
469
- type: "boolean",
470
- label: "Data Integration · Unavailable"
471
- }
472
- }
473
- };
474
- //#endregion
475
312
  //#region src/lib/csn/index.tsx
476
313
  function buildAnnotationLinkCallbacks(configs) {
477
314
  const callbacks = {};
@@ -481,7 +318,7 @@ function buildAnnotationLinkCallbacks(configs) {
481
318
  }
482
319
  return callbacks;
483
320
  }
484
- function CsnRenderer({ content, config, showCustomAttributes = true, customAttributes, className, theme }) {
321
+ function CsnRenderer({ content, config, customAttributes, className, theme }) {
485
322
  const [state, setState] = useState({ kind: "idle" });
486
323
  useEffect(() => {
487
324
  if (!content) {
@@ -500,9 +337,10 @@ function CsnRenderer({ content, config, showCustomAttributes = true, customAttri
500
337
  });
501
338
  return;
502
339
  }
503
- const activeConfigs = customAttributes ?? [sapCsnAttributesConfig];
504
- const parsedDoc = showCustomAttributes ? loadObject(content) : null;
505
- const linkCallbacks = showCustomAttributes ? buildAnnotationLinkCallbacks(activeConfigs) : {};
340
+ const activeConfigs = customAttributes ?? [];
341
+ const isEnabled = customAttributes !== void 0;
342
+ const parsedDoc = isEnabled ? loadObject(content) : null;
343
+ const linkCallbacks = isEnabled ? buildAnnotationLinkCallbacks(activeConfigs) : {};
506
344
  const rendererConfig = {
507
345
  ...config,
508
346
  annotationLinkCallbacks: {
@@ -511,7 +349,7 @@ function CsnRenderer({ content, config, showCustomAttributes = true, customAttri
511
349
  }
512
350
  };
513
351
  generateHtml(parsed, rendererConfig).then((html) => {
514
- const processed = showCustomAttributes ? applyAnnotationRenderers(html, activeConfigs, parsedDoc) : html;
352
+ const processed = isEnabled ? applyAnnotationRenderers(html, activeConfigs, parsedDoc) : html;
515
353
  if (!cancelled) setState({
516
354
  kind: "ready",
517
355
  html: processed
@@ -528,7 +366,6 @@ function CsnRenderer({ content, config, showCustomAttributes = true, customAttri
528
366
  }, [
529
367
  content,
530
368
  config,
531
- showCustomAttributes,
532
369
  customAttributes
533
370
  ]);
534
371
  return /* @__PURE__ */ jsxs("div", {
@@ -545,4 +382,4 @@ function CsnRenderer({ content, config, showCustomAttributes = true, customAttri
545
382
  });
546
383
  }
547
384
  //#endregion
548
- export { sapCsnAttributesConfig as n, CsnRenderer as t };
385
+ export { CsnRenderer as t };