@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.
@@ -1,9 +1,9 @@
1
1
  import { i as loadObject } from "./utils-BC3WF3-9.js";
2
2
  /* empty css */
3
- import { createElement, useEffect, useId, useMemo, useRef, useState } from "react";
3
+ import { createElement, useEffect, useId, useMemo, useRef } from "react";
4
4
  import { ApiReferenceReact } from "@scalar/api-reference-react";
5
5
  import Markdown from "react-markdown";
6
- import { Fragment, jsx, jsxs } from "react/jsx-runtime";
6
+ import { jsx, jsxs } from "react/jsx-runtime";
7
7
  import { ReactRenderer } from "@scalar/react-renderer";
8
8
  //#region src/lib/openApi/utils/context.ts
9
9
  var openApiContext = {
@@ -522,316 +522,6 @@ function buildScalarThemeStyles(id, theme) {
522
522
  })()].filter(Boolean).join("\n\n");
523
523
  }
524
524
  //#endregion
525
- //#region src/lib/openApi/customAttributes/sapAttributes/root/typeCheckXxtOverview.ts
526
- function typeCheckExSapExtOverviewExSapExtOverview(obj) {
527
- if (typeof obj !== "object" || obj === null) return false;
528
- if (!("xSapExtOverview" in obj) || !Array.isArray(obj.xSapExtOverview)) return false;
529
- return obj.xSapExtOverview.every((xSapExtOverview) => {
530
- if (typeof xSapExtOverview !== "object" || xSapExtOverview === null) return false;
531
- if (!("name" in xSapExtOverview) || !("values" in xSapExtOverview)) return false;
532
- if (typeof xSapExtOverview.name !== "string") return false;
533
- if (typeof xSapExtOverview.values === "string") return true;
534
- if (!Array.isArray(xSapExtOverview.values)) return false;
535
- if (xSapExtOverview.values.every((value) => typeof value === "string")) return true;
536
- return xSapExtOverview.values.every((value) => {
537
- if (typeof value !== "object" || value === null) return false;
538
- if (!("text" in value) || typeof value.text !== "string") return false;
539
- return "format" in value && (value.format === "plain" || value.format === "markdown");
540
- });
541
- });
542
- }
543
- //#endregion
544
- //#region src/lib/openApi/customAttributes/sapAttributes/root/extOverview.tsx
545
- function extOverview(props) {
546
- if (!typeCheckExSapExtOverviewExSapExtOverview(props)) return null;
547
- const { xSapExtOverview } = props;
548
- return /* @__PURE__ */ jsxs("div", {
549
- className: "sap-api-container",
550
- children: [/* @__PURE__ */ jsxs("div", {
551
- className: "sap-api-label sap-api-label--root",
552
- children: ["SAP Extensibility Overview ", /* @__PURE__ */ jsx(attributeLink, { attributeName: "x-sap-ext-overview" })]
553
- }), /* @__PURE__ */ jsx("div", {
554
- className: "sap-api-value sap-api-value--root",
555
- children: xSapExtOverview.map((extension) => /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("strong", { children: extension.name }), /* @__PURE__ */ jsx("ul", {
556
- className: "sap-api-list",
557
- children: typeof extension.values === "string" ? /* @__PURE__ */ jsx("li", { children: extension.values }) : extension.values.map((value) => typeof value === "string" ? /* @__PURE__ */ jsx("li", { children: value }, value) : /* @__PURE__ */ jsx("li", { children: value.format === "plain" ? value.text : /* @__PURE__ */ jsx(Markdown, { children: value.text }) }, value.text))
558
- })] }, extension.name))
559
- })]
560
- });
561
- }
562
- //#endregion
563
- //#region src/lib/openApi/customAttributes/sapAttributes/root/stateInfo.tsx
564
- var background = {
565
- ACTIVE: "color-mix(in srgb, var(--scalar-color-green) 15%, transparent)",
566
- BETA: "color-mix(in srgb, var(--scalar-color-blue) 15%, transparent)",
567
- DEPRECATED: "color-mix(in srgb, var(--scalar-color-orange) 15%, transparent)",
568
- DECOMMISSIONED: "color-mix(in srgb, var(--scalar-color-red) 15%, transparent)"
569
- };
570
- var color = {
571
- ACTIVE: "var(--scalar-color-green)",
572
- BETA: "var(--scalar-color-blue)",
573
- DEPRECATED: "var(--scalar-color-orange)",
574
- DECOMMISSIONED: "var(--scalar-color-red)"
575
- };
576
- function StateInfo({ xSapStateInfo }) {
577
- if (!xSapStateInfo) return null;
578
- const status = xSapStateInfo.state?.toUpperCase();
579
- const badge = /* @__PURE__ */ jsx("span", {
580
- style: {
581
- display: "inline-block",
582
- borderRadius: "10px",
583
- padding: "0 6px",
584
- background: background[status] || "",
585
- color: color[status] || ""
586
- },
587
- children: status
588
- });
589
- const dateFormatter = new Intl.DateTimeFormat("en-GB", { dateStyle: "long" });
590
- const formatDate = (d) => {
591
- const parsed = new Date(d);
592
- return isNaN(parsed.getTime()) ? d : dateFormatter.format(parsed);
593
- };
594
- return /* @__PURE__ */ jsxs("div", {
595
- className: "sap-api-container",
596
- children: [/* @__PURE__ */ jsxs("div", {
597
- className: "sap-api-label",
598
- children: ["API State ", /* @__PURE__ */ jsx(attributeLink, { attributeName: "x-sap-stateInfo" })]
599
- }), /* @__PURE__ */ jsxs("div", {
600
- className: "sap-api-value",
601
- children: [
602
- badge,
603
- xSapStateInfo.deprecationDate && /* @__PURE__ */ jsxs("div", { children: ["Deprecated on ", formatDate(xSapStateInfo.deprecationDate)] }),
604
- xSapStateInfo.decommissionedDate && /* @__PURE__ */ jsxs("div", { children: ["Decommissioned on ", formatDate(xSapStateInfo.decommissionedDate)] }),
605
- xSapStateInfo.successorApi && /* @__PURE__ */ jsxs("div", { children: ["Successor API: ", /* @__PURE__ */ jsx("a", {
606
- href: xSapStateInfo.successorApi,
607
- target: "_blank",
608
- rel: "noreferrer",
609
- className: "sap-api-link",
610
- children: xSapStateInfo.successorApi
611
- })] })
612
- ]
613
- })]
614
- });
615
- }
616
- //#endregion
617
- //#region src/lib/openApi/customAttributes/sapAttributes/root/ordId.tsx
618
- function CopyIcon() {
619
- return /* @__PURE__ */ jsxs("svg", {
620
- viewBox: "0 0 24 24",
621
- width: "1em",
622
- height: "1em",
623
- fill: "none",
624
- stroke: "currentColor",
625
- strokeWidth: "2",
626
- "aria-hidden": "true",
627
- children: [/* @__PURE__ */ jsx("rect", {
628
- x: "9",
629
- y: "9",
630
- width: "13",
631
- height: "13",
632
- rx: "2"
633
- }), /* @__PURE__ */ jsx("path", { d: "M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1" })]
634
- });
635
- }
636
- function CheckIcon() {
637
- return /* @__PURE__ */ jsx("svg", {
638
- viewBox: "0 0 24 24",
639
- width: "1em",
640
- height: "1em",
641
- fill: "none",
642
- stroke: "currentColor",
643
- strokeWidth: "2",
644
- "aria-hidden": "true",
645
- children: /* @__PURE__ */ jsx("path", { d: "M20 6 9 17l-5-5" })
646
- });
647
- }
648
- function ordId({ xSapOrdId }) {
649
- const [copied, setCopied] = useState(false);
650
- if (!xSapOrdId) return null;
651
- const copy = () => {
652
- navigator.clipboard?.writeText(xSapOrdId).then(() => {
653
- setCopied(true);
654
- setTimeout(() => setCopied(false), 1500);
655
- });
656
- };
657
- return /* @__PURE__ */ jsxs("div", {
658
- className: "sap-api-container",
659
- children: [/* @__PURE__ */ jsxs("div", {
660
- className: "sap-api-label",
661
- children: ["ORD ID ", /* @__PURE__ */ jsx(attributeLink, { attributeName: "x-sap-ord-id" })]
662
- }), /* @__PURE__ */ jsxs("div", {
663
- className: "sap-api-value sap-api-ord-id",
664
- children: [/* @__PURE__ */ jsx("span", {
665
- className: "sap-api-ord-id-text",
666
- children: xSapOrdId
667
- }), /* @__PURE__ */ jsx("button", {
668
- type: "button",
669
- className: "sap-api-copy-btn",
670
- onClick: copy,
671
- "aria-label": "Copy ORD ID",
672
- title: copied ? "Copied" : "Copy",
673
- children: copied ? /* @__PURE__ */ jsx(CheckIcon, {}) : /* @__PURE__ */ jsx(CopyIcon, {})
674
- })]
675
- })]
676
- });
677
- }
678
- //#endregion
679
- //#region src/lib/openApi/customAttributes/sapAttributes/operation/deprecatedOperation.tsx
680
- function deprecatedOperation({ xSapDeprecatedOperation }) {
681
- const deprecationDate = new Intl.DateTimeFormat("en-GB", { dateStyle: "long" }).format(new Date(xSapDeprecatedOperation.deprecationDate));
682
- return /* @__PURE__ */ jsxs("div", {
683
- className: "sap-api-container",
684
- children: [/* @__PURE__ */ jsxs("div", {
685
- className: "sap-api-label",
686
- children: ["SAP Deprecated Operation ", /* @__PURE__ */ jsx(attributeLink, { attributeName: "x-sap-deprecated-operation" })]
687
- }), /* @__PURE__ */ jsxs("div", {
688
- className: "sap-api-value",
689
- children: [
690
- "Deprecated on ",
691
- deprecationDate,
692
- " ",
693
- /* @__PURE__ */ jsx("br", {}),
694
- !xSapDeprecatedOperation.successorOperationRef && !xSapDeprecatedOperation.successorOperationId ? null : /* @__PURE__ */ jsxs(Fragment, { children: [
695
- " Successor ",
696
- xSapDeprecatedOperation.successorOperationRef ? /* @__PURE__ */ jsx("a", {
697
- href: xSapDeprecatedOperation.successorOperationRef,
698
- rel: "noreferrer, noopener",
699
- children: xSapDeprecatedOperation.successorOperationRef
700
- }) : null,
701
- xSapDeprecatedOperation.successorOperationId ? /* @__PURE__ */ jsx("span", { children: xSapDeprecatedOperation.successorOperationId }) : null
702
- ] })
703
- ]
704
- })]
705
- });
706
- }
707
- //#endregion
708
- //#region src/lib/openApi/customAttributes/sapAttributes/schema/odmEntityName.tsx
709
- function odmEntityName({ xSapOdmEntityName }) {
710
- return /* @__PURE__ */ jsxs("div", {
711
- className: "sap-api-container",
712
- children: [/* @__PURE__ */ jsxs("div", {
713
- className: "sap-api-label",
714
- children: ["ODM entity name ", /* @__PURE__ */ jsx(attributeLink, { attributeName: "x-sap-odm-entity-name" })]
715
- }), /* @__PURE__ */ jsx("div", {
716
- className: "sap-api-value",
717
- children: xSapOdmEntityName
718
- })]
719
- });
720
- }
721
- //#endregion
722
- //#region src/lib/openApi/customAttributes/sapAttributes/schema/odmSemanticKey.tsx
723
- function odmSemanticKey({ xSapOdmSemanticKey }) {
724
- return /* @__PURE__ */ jsxs("div", {
725
- className: "sap-api-container",
726
- children: [/* @__PURE__ */ jsxs("div", {
727
- className: "sap-api-label",
728
- children: ["ODM Semantic Key ", /* @__PURE__ */ jsx(attributeLink, { attributeName: "x-sap-odm-semantic-key" })]
729
- }), /* @__PURE__ */ jsx("div", {
730
- className: "sap-api-value",
731
- children: xSapOdmSemanticKey.map((entry) => /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("strong", { children: entry.name }), /* @__PURE__ */ jsx("ul", {
732
- className: "sap-api-list",
733
- children: entry.values.map((v) => /* @__PURE__ */ jsx("li", { children: v }, v))
734
- })] }, entry.name))
735
- })]
736
- });
737
- }
738
- //#endregion
739
- //#region src/lib/openApi/customAttributes/sapAttributes/sapPreset.ts
740
- function component(fn) {
741
- return { component: fn };
742
- }
743
- var sapOpenApiAttributesConfig = {
744
- prefixStartsWith: "x-sap-",
745
- documentationUrl: (name, { version }) => `https://github.com/SAP/openapi-specification/tree/main/sap-schemas/v${version}#${name}`,
746
- extensions: {
747
- "x-sap-compliance-level": {
748
- type: "link",
749
- label: "SAP Compliance Level",
750
- callback: (v) => {
751
- return {
752
- "sap:base:v1": "https://github.com/open-resource-discovery/specification/blob/main/docs/spec-extensions/policy-levels/sap-base-v1.md",
753
- "sap:core:v1": "https://github.com/open-resource-discovery/specification/blob/main/docs/spec-extensions/policy-levels/sap-core-v1.md",
754
- "sap:core:v2": "https://github.com/open-resource-discovery/specification/blob/main/docs/spec-extensions/policy-levels/sap-core-v1.md"
755
- }[String(v)];
756
- }
757
- },
758
- "x-sap-shortText": {
759
- type: "string",
760
- label: "SAP Short Text"
761
- },
762
- "x-sap-software-min-version": {
763
- type: "string",
764
- label: "SAP Software Version"
765
- },
766
- "x-sap-api-type": {
767
- type: "string",
768
- label: "SAP API Type"
769
- },
770
- "x-sap-direction": {
771
- type: "string",
772
- label: "SAP Direction"
773
- },
774
- "x-sap-ord-id": component(ordId),
775
- "x-sap-operation-intent": {
776
- type: "string",
777
- label: "SAP Operation Intent"
778
- },
779
- "x-sap-odm-oid": {
780
- type: "string",
781
- label: "ODM OID"
782
- },
783
- "x-sap-odm-oid-reference-entity-name": {
784
- type: "string",
785
- label: "ODM OID Reference Entity Name"
786
- },
787
- "x-sap-precision": {
788
- type: "number",
789
- label: "SAP Precision"
790
- },
791
- "x-sap-scale": {
792
- type: "number",
793
- label: "SAP Scale"
794
- },
795
- "x-sap-root-entity": {
796
- type: "boolean",
797
- label: "SAP Root Entity"
798
- },
799
- "x-sap-dpp-entity-semantics": {
800
- type: "string",
801
- label: "SAP DPP: Entity Semantics"
802
- },
803
- "x-sap-dpp-data-subject-role": {
804
- type: "string",
805
- label: "SAP DPP: Data Subject Role"
806
- },
807
- "x-sap-dpp-data-subject-role-description": {
808
- type: "string",
809
- label: "SAP DPP: Data Subject Role Description"
810
- },
811
- "x-sap-dpp-field-semantics": {
812
- type: "string",
813
- label: "SAP DPP: Field Semantics"
814
- },
815
- "x-sap-dpp-is-potentially-personal": {
816
- type: "boolean",
817
- label: "SAP DPP: Potentially Personal"
818
- },
819
- "x-sap-dpp-is-potentially-sensitive": {
820
- type: "boolean",
821
- label: "SAP DPP: Potentially Sensitive"
822
- },
823
- "x-sap-ext-overview": component(extOverview),
824
- "x-sap-stateInfo": component(StateInfo),
825
- "x-sap-extensible": {
826
- type: "object",
827
- label: "SAP Extensible"
828
- },
829
- "x-sap-deprecated-operation": component(deprecatedOperation),
830
- "x-sap-odm-entity-name": component(odmEntityName),
831
- "x-sap-odm-semantic-key": component(odmSemanticKey)
832
- }
833
- };
834
- //#endregion
835
525
  //#region src/lib/openApi/styles.ts
836
526
  var styles_default = `
837
527
  .sap-api-container {
@@ -1028,11 +718,12 @@ a:hover {
1028
718
  `;
1029
719
  //#endregion
1030
720
  //#region src/lib/openApi/index.tsx
1031
- function OpenApiRenderer({ content, showCustomAttributes = true, customAttributes, className, theme }) {
721
+ function OpenApiRenderer({ content, customAttributes, className, theme }) {
1032
722
  const id = useId();
1033
723
  const containerRef = useRef(null);
1034
724
  const isDark = className?.split(/\s+/).includes("dark") ?? false;
1035
- const activeConfigs = customAttributes ?? [sapOpenApiAttributesConfig];
725
+ const activeConfigs = useMemo(() => customAttributes ?? [], [customAttributes]);
726
+ const isEnabled = customAttributes !== void 0;
1036
727
  useEffect(() => {
1037
728
  const el = containerRef.current;
1038
729
  if (!el) return;
@@ -1046,23 +737,23 @@ function OpenApiRenderer({ content, showCustomAttributes = true, customAttribute
1046
737
  };
1047
738
  }, []);
1048
739
  const customAttributesKey = useMemo(() => {
1049
- if (!showCustomAttributes) return "";
740
+ if (!isEnabled) return "";
1050
741
  const parsed = loadObject(content);
1051
742
  if (!parsed) return "";
1052
743
  return activeConfigs.flatMap((config) => extractCustomAttributeValues(parsed, config.prefixStartsWith ?? "").map(([k, v]) => `${k}=${JSON.stringify(v)}`)).join("|");
1053
744
  }, [
1054
745
  content,
1055
- showCustomAttributes,
746
+ isEnabled,
1056
747
  activeConfigs
1057
748
  ]);
1058
749
  const configuration = useMemo(() => {
1059
750
  openApiContext.version = getVersion(content);
1060
- openApiContext.configs = showCustomAttributes ? activeConfigs : [];
751
+ openApiContext.configs = isEnabled ? activeConfigs : [];
1061
752
  const parsed = loadObject(content);
1062
753
  const prefixes = activeConfigs.map((c) => c.prefixStartsWith).filter(Boolean);
1063
754
  return {
1064
- content: showCustomAttributes && parsed && prefixes.length ? injectSchemaExtensions(parsed, prefixes) : parsed ?? content,
1065
- plugins: showCustomAttributes ? [buildCustomAttributesPlugin(parsed, activeConfigs)] : [],
755
+ content: isEnabled && parsed && prefixes.length ? injectSchemaExtensions(parsed, prefixes) : parsed ?? content,
756
+ plugins: isEnabled ? [buildCustomAttributesPlugin(parsed, activeConfigs)] : [],
1066
757
  forceDarkModeState: isDark ? "dark" : "light",
1067
758
  hideDarkModeToggle: true,
1068
759
  hideClientButton: true,
@@ -1071,7 +762,7 @@ function OpenApiRenderer({ content, showCustomAttributes = true, customAttribute
1071
762
  }, [
1072
763
  content,
1073
764
  isDark,
1074
- showCustomAttributes,
765
+ isEnabled,
1075
766
  activeConfigs
1076
767
  ]);
1077
768
  return /* @__PURE__ */ jsxs("div", {
@@ -1084,9 +775,9 @@ function OpenApiRenderer({ content, showCustomAttributes = true, customAttribute
1084
775
  children: [
1085
776
  /* @__PURE__ */ jsx("style", { children: styles_default }),
1086
777
  theme && /* @__PURE__ */ jsx("style", { children: buildScalarThemeStyles(id, theme) }),
1087
- /* @__PURE__ */ jsx(ApiReferenceReact, { configuration }, `${isDark ? "dark" : "light"}-${showCustomAttributes}-${customAttributesKey}`)
778
+ /* @__PURE__ */ jsx(ApiReferenceReact, { configuration }, `${isDark ? "dark" : "light"}-${isEnabled}-${customAttributesKey}`)
1088
779
  ]
1089
780
  });
1090
781
  }
1091
782
  //#endregion
1092
- export { sapOpenApiAttributesConfig as n, OpenApiRenderer as t };
783
+ export { attributeLink as n, OpenApiRenderer as t };
@@ -0,0 +1,3 @@
1
+ import { MetaType } from './utils';
2
+ import { MetadataRendererOptions } from '../types';
3
+ export declare function buildRendererExtraProps(metaType: MetaType, options: MetadataRendererOptions | undefined): Record<string, unknown>;
@@ -0,0 +1 @@
1
+ export {};
@@ -4,9 +4,8 @@ import { CsnCustomAttributesConfig } from './customAttributes/types';
4
4
  export type CsnRendererProps = {
5
5
  content: string;
6
6
  config?: CsnRendererConfig;
7
- showCustomAttributes?: boolean;
8
7
  customAttributes?: CsnCustomAttributesConfig[];
9
8
  className?: string;
10
9
  theme?: RendererTheme;
11
10
  };
12
- export declare function CsnRenderer({ content, config, showCustomAttributes, customAttributes, className, theme, }: CsnRendererProps): import("react").JSX.Element;
11
+ export declare function CsnRenderer({ content, config, customAttributes, className, theme }: CsnRendererProps): import("react").JSX.Element;
package/dist/csn.js CHANGED
@@ -1,2 +1,2 @@
1
- import { t as CsnRenderer } from "./chunks/csn-D4GBs8tC.js";
1
+ import { t as CsnRenderer } from "./chunks/csn-3ek2O4d6.js";
2
2
  export { CsnRenderer };