Skip to content

Commit aa07f1d

Browse files
committed
script rendering (fix build)
1 parent d48e564 commit aa07f1d

File tree

6 files changed

+154
-147
lines changed

6 files changed

+154
-147
lines changed

src/components/LanguageButtons.tsx

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,24 @@ import Swift from '@site/static/img/docusaurus/swift.png';
1010
import SwiftDark from '@site/static/img/docusaurus/swift-dark.png';
1111

1212
export const LanguageButtons = () => {
13-
const {colorMode} = useColorMode();
14-
const isDark = colorMode === 'dark';
13+
const {colorMode} = useColorMode();
14+
const isDark = colorMode === 'dark';
1515

16-
return (
17-
<BrowserOnly>
18-
{() =>
19-
<div style={{gap: "1rem", display: "flex", marginBottom: "1rem"}}>
20-
<img src={Typescript} onClick={() => setCookie("ts")} style={{maxHeight: "1.2rem", cursor: "pointer"}}/>
21-
<img src={isDark ? KotlinDark : Kotlin} onClick={() => setCookie("kt")} style={{maxHeight: "1.1rem", cursor: "pointer"}}/>
22-
<img src={isDark ? FlutterDark : Flutter} onClick={() => setCookie("dart")} style={{maxHeight: "1.2rem", cursor: "pointer"}}/>
23-
<img src={isDark ? SwiftDark : Swift} onClick={() => setCookie("swift")} style={{maxHeight: "1.2rem", cursor: "pointer"}}/>
24-
</div>
25-
}
26-
</BrowserOnly>
27-
);
16+
return (
17+
<BrowserOnly>
18+
{() =>
19+
<div style={{gap: "1rem", display: "flex", marginBottom: "1rem"}}>
20+
<img src={Typescript} onClick={() => setCookie("ts")} style={{maxHeight: "1.2rem", cursor: "pointer"}}/>
21+
<img src={isDark ? KotlinDark : Kotlin} onClick={() => setCookie("kt")} style={{maxHeight: "1.1rem", cursor: "pointer"}}/>
22+
<img src={isDark ? FlutterDark : Flutter} onClick={() => setCookie("dart")} style={{maxHeight: "1.2rem", cursor: "pointer"}}/>
23+
<img src={isDark ? SwiftDark : Swift} onClick={() => setCookie("swift")} style={{maxHeight: "1.2rem", cursor: "pointer"}}/>
24+
</div>
25+
}
26+
</BrowserOnly>
27+
);
2828
};
2929

3030
const setCookie = (str: String) => {
31-
document.cookie = `selected_language=${ str }; SameSite=Strict; expires=Fri, 31 Dec 9999 23:59:59 GMT; Secure`;
32-
window.location.reload();
31+
document.cookie = `selected_language=${ str }; SameSite=Strict; expires=Fri, 31 Dec 9999 23:59:59 GMT; Secure`;
32+
window.location.reload();
3333
};

src/components/LanguageSpecific.tsx

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,51 +2,51 @@ import React from "react";
22
import BrowserOnly from '@docusaurus/BrowserOnly';
33

44
type LanguageProps = {
5-
kt?: JSX.Element;
6-
ts?: JSX.Element;
7-
flutter?: JSX.Element;
8-
swift?: JSX.Element;
9-
fallback?: JSX.Element;
5+
kt?: JSX.Element;
6+
ts?: JSX.Element;
7+
flutter?: JSX.Element;
8+
swift?: JSX.Element;
9+
fallback?: JSX.Element;
1010
};
1111

1212
export const walletDefaultLang = "ts";
1313

1414
export const LanguageSpecific: React.FC<LanguageProps> = (props) => (
15-
<BrowserOnly fallback={props.fallback || getToShow(props, null)}>
16-
{() => getToShow(props, getCookie())}
17-
</BrowserOnly>
18-
);
15+
<BrowserOnly fallback={props.fallback || getToShow(props, null)}>
16+
{() => getToShow(props, getCookie())}
17+
</BrowserOnly>
18+
);
1919

2020
const getToShow = (props: LanguageProps, cookie: String) => {
21-
let toShow = <></>;
22-
23-
if (cookie == null) {
24-
cookie = walletDefaultLang;
25-
}
26-
27-
if (cookie == "kt") {
28-
toShow = props.kt || <></>;
29-
} else if (cookie == "ts") {
30-
toShow = props.ts || <></>;
31-
} else if (cookie == "dart") {
32-
toShow = props.flutter || <></>;
33-
} else if (cookie == "swift") {
34-
toShow = props.swift || <></>;
35-
}
36-
37-
return toShow;
21+
let toShow = <></>;
22+
23+
if (cookie == null) {
24+
cookie = walletDefaultLang;
25+
}
26+
27+
if (cookie == "kt") {
28+
toShow = props.kt || <></>;
29+
} else if (cookie == "ts") {
30+
toShow = props.ts || <></>;
31+
} else if (cookie == "dart") {
32+
toShow = props.flutter || <></>;
33+
} else if (cookie == "swift") {
34+
toShow = props.swift || <></>;
35+
}
36+
37+
return toShow;
3838
};
3939

4040
export function getCookie() {
41-
const name = "selected_language=";
42-
const decodedCookie = decodeURIComponent(document.cookie);
43-
const ca = decodedCookie.split(';');
44-
for (let i = 0; i < ca.length; i++) {
45-
const ind = ca[i].indexOf(name);
46-
if (ind != -1) {
47-
const val = ca[i].indexOf("=");
48-
return ca[i].substring(val + 1, ca[i].length);
49-
}
41+
const name = "selected_language=";
42+
const decodedCookie = decodeURIComponent(document.cookie);
43+
const ca = decodedCookie.split(';');
44+
for (let i = 0; i < ca.length; i++) {
45+
const ind = ca[i].indexOf(name);
46+
if (ind != -1) {
47+
const val = ca[i].indexOf("=");
48+
return ca[i].substring(val + 1, ca[i].length);
5049
}
51-
return null;
50+
}
51+
return null;
5252
}

src/components/RpcMethod.tsx

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
1-
import Method from "@stellar/open-rpc-docs-react";
21
import React from "react";
2+
import BrowserOnly from "@docusaurus/BrowserOnly";
33
import type { MethodObject } from "@open-rpc/meta-schema";
44

5-
const CodeBlock = require('@theme/CodeBlock').default;
6-
const Tabs = require('@theme/Tabs').default;
7-
const TabItem = require('@theme/TabItem').default;
8-
95
export const RpcMethod = ({ method }: { method: MethodObject}) => {
10-
return (<Method method={method} components={{CodeBlock, Tabs, TabItem}} />);
6+
return (
7+
<BrowserOnly fallback={<div>Loading method details…</div>}>
8+
{() => {
9+
const Method = require("@stellar/open-rpc-docs-react").default;
10+
const CodeBlock = require("@theme/CodeBlock").default;
11+
const Tabs = require("@theme/Tabs").default;
12+
const TabItem = require("@theme/TabItem").default;
13+
14+
return <Method method={method} components={{ CodeBlock, Tabs, TabItem }} />;
15+
}}
16+
</BrowserOnly>
17+
);
1118
};

src/components/SepBadge.tsx

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
import React from "react";
22

33
type ProductProps = {
4-
tags: string;
4+
tags: string;
55
};
66

77
export const SepBadge: React.FC<ProductProps> = (props) => {
8-
const tags = props.tags.split(",");
9-
const seps = tags.filter(w => w.toLowerCase().includes("sep")).sort();
8+
const tags = props.tags.split(",");
9+
const seps = tags.filter(w => w.toLowerCase().includes("sep")).sort();
1010

11-
if (seps.length === 0) {
12-
return <></>;
13-
}
11+
if (seps.length === 0) {
12+
return <></>;
13+
}
1414

15-
return (<div style={{marginBottom: "var(--ifm-spacing-vertical)"}}>
16-
{seps.map((sep) => (
17-
<span style={{borderRadius: "var(--ifm-global-radius)", marginRight: "var(--ifm-global-spacing"}}
18-
className="badge badge--primary">{sep}</span>
19-
))}
20-
</div>);
15+
return (<div style={{marginBottom: "var(--ifm-spacing-vertical)"}}>
16+
{seps.map((sep) => (
17+
<span style={{borderRadius: "var(--ifm-global-radius)", marginRight: "var(--ifm-global-spacing"}}
18+
className="badge badge--primary">{sep}</span>
19+
))}
20+
</div>);
2121
};

src/components/WalletCodeExample.tsx

Lines changed: 63 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -15,87 +15,87 @@ const SHOW_ALL = false;
1515
const WALLET_LANGS = ["kt", "ts", "dart", "swift"];
1616

1717
type WalletCodeExampleProps = {
18-
children: React.ReactElement;
18+
children: React.ReactElement;
1919
};
2020

2121
export const WalletCodeExample: React.FC<WalletCodeExampleProps> = ({children}) => <BrowserOnly fallback={getTabs(children, walletDefaultLang)}>
22-
{() => getTabs(children, getCookie())}
23-
</BrowserOnly>;
22+
{() => getTabs(children, getCookie())}
23+
</BrowserOnly>;
2424

2525
const getTabs = (children: React.ReactElement, targetLanguage: string) => {
26-
const defaultVal = CODE_LANGS[targetLanguage];
26+
const defaultVal = CODE_LANGS[targetLanguage];
2727

28-
const tabs = React.Children.map(children, (child, index) => {
29-
const codeProps = child.props.children.props;
30-
const {className = ''} = codeProps;
28+
const tabs = React.Children.map(children, (child, index) => {
29+
const codeProps = child.props.children.props;
30+
const {className = ''} = codeProps;
3131

32-
let [, language] = className.split('-');
32+
let [, language] = className.split('-');
3333

34-
if (language === "flutter") {
35-
language = "dart";
36-
}
34+
if (language === "flutter") {
35+
language = "dart";
36+
}
3737

38-
return (
39-
<TabItem
40-
key={language || index}
41-
value={CODE_LANGS[language] || language || index}
42-
label={CODE_LANGS[language] ||
43-
<Translate
44-
id='components.CodeExample.NoLanguageTabTitle'
45-
description='The tab title for a code example where no programming language was specified'>
46-
Example
47-
</Translate>
48-
}
49-
default={defaultVal === CODE_LANGS[language]}
50-
>
51-
<CodeBlock language={language} showLineNumbers>
52-
{codeProps.children}
53-
</CodeBlock>
54-
</TabItem>
55-
);
56-
});
38+
return (
39+
<TabItem
40+
key={language || index}
41+
value={CODE_LANGS[language] || language || index}
42+
label={CODE_LANGS[language] ||
43+
<Translate
44+
id='components.CodeExample.NoLanguageTabTitle'
45+
description='The tab title for a code example where no programming language was specified'>
46+
Example
47+
</Translate>
48+
}
49+
default={defaultVal === CODE_LANGS[language]}
50+
>
51+
<CodeBlock language={language} showLineNumbers>
52+
{codeProps.children}
53+
</CodeBlock>
54+
</TabItem>
55+
);
56+
});
5757

58-
for (let i = 0; i < WALLET_LANGS.length; i++) {
59-
const language = CODE_LANGS[WALLET_LANGS[i]];
58+
for (let i = 0; i < WALLET_LANGS.length; i++) {
59+
const language = CODE_LANGS[WALLET_LANGS[i]];
6060

61-
if (tabs.filter((x) => x.props.value === language).length === 0) {
62-
if (ALLOW_EMPTY_DOCS) {
63-
tabs.push(<TabItem
64-
key={language}
65-
value={language}
66-
label={language}
67-
default={defaultVal === language}
68-
>
69-
<CodeBlock language={language} showLineNumbers>
70-
<Translate
71-
id="components.CodeExample.MissingCodeExample"
72-
description='In the Wallet-SDK code example component, this message will display when the selected programming language has no accompanying example'
73-
values={{language: language}}>
74-
{'// There is no code example for {language} yet'}
75-
</Translate>
76-
</CodeBlock>
77-
</TabItem>);
78-
} else {
79-
throw Error(`Missing ${ language } documentation`);
80-
}
81-
}
61+
if (tabs.filter((x) => x.props.value === language).length === 0) {
62+
if (ALLOW_EMPTY_DOCS) {
63+
tabs.push(<TabItem
64+
key={language}
65+
value={language}
66+
label={language}
67+
default={defaultVal === language}
68+
>
69+
<CodeBlock language={language} showLineNumbers>
70+
<Translate
71+
id="components.CodeExample.MissingCodeExample"
72+
description='In the Wallet-SDK code example component, this message will display when the selected programming language has no accompanying example'
73+
values={{language: language}}>
74+
{'// There is no code example for {language} yet'}
75+
</Translate>
76+
</CodeBlock>
77+
</TabItem>);
78+
} else {
79+
throw Error(`Missing ${ language } documentation`);
80+
}
8281
}
82+
}
8383

8484
let toShowTabs = tabs;
8585

8686
if (!SHOW_ALL) {
87-
for (let i = 0; i < tabs.length; i++) {
88-
const language = CODE_LANGS[targetLanguage];
89-
if (tabs[i].props.value === language) {
90-
toShowTabs = [tabs[i]];
91-
}
87+
for (let i = 0; i < tabs.length; i++) {
88+
const language = CODE_LANGS[targetLanguage];
89+
if (tabs[i].props.value === language) {
90+
toShowTabs = [tabs[i]];
9291
}
92+
}
9393
}
9494

95-
const gid = `wallet-lang${ defaultVal}`;
96-
// const gid = "p-wallet" + defaultVal + Math.random()
95+
const gid = `wallet-lang${ defaultVal}`;
96+
// const gid = "p-wallet" + defaultVal + Math.random()
9797

98-
return (<Tabs groupId={gid}>
99-
{toShowTabs}
100-
</Tabs>);
98+
return (<Tabs groupId={gid}>
99+
{toShowTabs}
100+
</Tabs>);
101101
};

src/components/WalletGuideWarn.tsx

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,23 @@ import {CODE_LANGS} from "@site/config/constants";
66
import Translate from "@docusaurus/Translate";
77

88
type WalletGuideWarnProps = {
9-
WIPLangs?: String[];
9+
WIPLangs?: String[];
1010
};
1111

1212
export const WalletGuideWarn: React.FC<WalletGuideWarnProps> = (props) => {
13-
const langs = (props.WIPLangs || []).map(v => CODE_LANGS[v.toLowerCase()]);
14-
const admonition = <Admonition type="danger" title="Important">
15-
<Translate
16-
id="components.WalletGuideWarn.WorkInProgress"
17-
description="For the Wallets SDK, if a given programming language is incomplete, display an admonition warning the user">
18-
Documentation for this language is currently work in progress. Some of information may not be applicable for this language, or missing. Code samples may be incomplete.
19-
</Translate>
20-
</Admonition>;
13+
const langs = (props.WIPLangs || []).map(v => CODE_LANGS[v.toLowerCase()]);
14+
const admonition = <Admonition type="danger" title="Important">
15+
<Translate
16+
id="components.WalletGuideWarn.WorkInProgress"
17+
description="For the Wallets SDK, if a given programming language is incomplete, display an admonition warning the user">
18+
Documentation for this language is currently work in progress. Some of information may not be applicable for this language, or missing. Code samples may be incomplete.
19+
</Translate>
20+
</Admonition>;
2121

22-
const kt = langs.indexOf("Kotlin") != -1 ? admonition : <></>;
23-
const ts = langs.indexOf("TypeScript") != -1 ? admonition: <></>;
24-
const flutter = langs.indexOf("Flutter") != -1 ? admonition : <></>;
25-
const swift = langs.indexOf("Swift") != -1 ? admonition : <></>;
22+
const kt = langs.indexOf("Kotlin") != -1 ? admonition : <></>;
23+
const ts = langs.indexOf("TypeScript") != -1 ? admonition: <></>;
24+
const flutter = langs.indexOf("Flutter") != -1 ? admonition : <></>;
25+
const swift = langs.indexOf("Swift") != -1 ? admonition : <></>;
2626

27-
return <LanguageSpecific kt={kt} ts={ts} flutter={flutter} swift={swift} fallback={<></>}/>;
27+
return <LanguageSpecific kt={kt} ts={ts} flutter={flutter} swift={swift} fallback={<></>}/>;
2828
};

0 commit comments

Comments
 (0)