Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: non-react playgrounds for docs #171

Open
wants to merge 8 commits into
base: integration/docs-site
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Playground } from '@site/src/components/playground';

# Demo

See the [docusaurus docs](https://docusaurus.io/docs/markdown-features) for full feature set.
Expand Down Expand Up @@ -25,7 +27,7 @@ type Day = 'Monday' | 'Tuesday' | 'Wednesday' | 'Thursday' | 'Friday' | 'Saturda
// some other thing and stuff
```

## live playground
## Playground (React)

```jsx live
function Clock(props) {
Expand Down Expand Up @@ -55,3 +57,18 @@ function Clock(props) {
$$
I = \int_0^{2\pi} \sin(x)\,dx
$$


## Playground (Non-React)

<Playground
code={`import { booleanToNumber } from '@accelint/converters';

console.log(booleanToNumber(true));
// 1

console.log(booleanToNumber(false));
// 0`}
dependencies={['@accelint/converters']}
/>

42 changes: 42 additions & 0 deletions apps/docs/lib/playground-plugin-hypergiant.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright 2025 Hypergiant Galactic Systems Inc. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/

/**
* TypeDoc plugin for replacing @playground blocks with our custom playground component,
*
* @param {import('typedoc').Application} app
*/
export function load(app) {
app.converter.on('createSignature', convertPlaygroundBlockToComponent);
}

function convertPlaygroundBlockToComponent(context, reflection) {
const playgroundTag = reflection?.comment?.blockTags?.find(
({ tag }) => tag === '@playground',
);

if (playgroundTag) {
const code = playgroundTag.content[0].text.trim();
playgroundTag.content = [
{
kind: 'text',
text: `import { Playground } from '@site/src/components/playground';

<Playground
code={\`${code}\`}
dependencies={['${context.project.name}']}
/>
`,
},
];
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ended up being fairly simple

  • look for the @playground tag
  • if it's there, replace the content w/ our playground component, passing the original content of the block as the code prop

}
1 change: 1 addition & 0 deletions apps/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"@accelint/design-system": "workspace:*",
"@accelint/typescript-config": "workspace:*",
"@biomejs/biome": "1.9.3",
"@codesandbox/sandpack-react": "2.19.10",
"@docusaurus/core": "3.7.0",
"@docusaurus/module-type-aliases": "3.7.0",
"@docusaurus/preset-classic": "3.7.0",
Expand Down
35 changes: 35 additions & 0 deletions apps/docs/src/components/playground.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright 2025 Hypergiant Galactic Systems Inc. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/

import { Sandpack } from '@codesandbox/sandpack-react';

type PlaygroundProps = {
code: string;
dependencies?: string[];
};

export function Playground({ code, dependencies = [] }: PlaygroundProps) {
return (
<Sandpack
template='vanilla-ts'
customSetup={{
dependencies: Object.fromEntries(
dependencies.map((dep) => [dep, 'latest']),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i just pinned to latest... i'm open to a more complex/flexible structure for the dependencies prop, if that's preferable

),
}}
files={{ 'index.ts': code }}
options={{
layout: 'console',
}}
/>
);
}
9 changes: 8 additions & 1 deletion apps/docs/typedoc.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
* governing permissions and limitations under the License.
*/

import { OptionDefaults } from 'typedoc';

/** @type {Partial<import("typedoc").TypeDocOptions>} */
export default {
disableSources: true,
Expand All @@ -27,7 +29,12 @@ export default {
pageTitleTemplates: {
member: (args) => args.name, // simpler page titles for member pages
},
plugin: ['typedoc-plugin-markdown', './lib/typedoc-plugin-hypergiant.mjs'],
plugin: [
'typedoc-plugin-markdown',
'./lib/typedoc-plugin-hypergiant.mjs',
'./lib/playground-plugin-hypergiant.mjs',
orteth01 marked this conversation as resolved.
Show resolved Hide resolved
],
requiredToBeDocumented: ['Class', 'Function', 'Interface'],
theme: 'markdown',
blockTags: [...OptionDefaults.blockTags, '@playground'], // https://typedoc.org/documents/Options.Comments.html#blocktags
};
16 changes: 16 additions & 0 deletions packages/constants/typedoc.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Copyright 2025 Hypergiant Galactic Systems Inc. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/

/** @type {Partial<import("typedoc").TypeDocOptions>} */
export default {
name: '@accelint/constants',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think there may be a bug in typedoc related to using the 'packages' entry point strategy. for whatever reason, context.project.name in the createSignature event was an empty string, unless we explicitly set the name like this in each package. in theory, it should just be getting this from package.json....

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting. Not too surprising.

};
8 changes: 5 additions & 3 deletions packages/converters/src/boolean-to-number/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@
* @remarks
* pure function
*
* @example
* booleanToNumber(true);
* @playground
* import { booleanToNumber } from '@accelint/converters';
*
* console.log(booleanToNumber(true));
* // 1
*
* booleanToNumber(false);
* console.log(booleanToNumber(false));
* // 0
Comment on lines +19 to 26
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

example @playground block

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is awesome.

*/
export function booleanToNumber(val: boolean) {
Expand Down
16 changes: 16 additions & 0 deletions packages/converters/typedoc.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Copyright 2025 Hypergiant Galactic Systems Inc. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/

/** @type {Partial<import("typedoc").TypeDocOptions>} */
export default {
name: '@accelint/converters',
};
16 changes: 16 additions & 0 deletions packages/core/typedoc.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Copyright 2025 Hypergiant Galactic Systems Inc. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/

/** @type {Partial<import("typedoc").TypeDocOptions>} */
export default {
name: '@accelint/core',
};
16 changes: 16 additions & 0 deletions packages/design-system/typedoc.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Copyright 2025 Hypergiant Galactic Systems Inc. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/

/** @type {Partial<import("typedoc").TypeDocOptions>} */
export default {
name: '@accelint/design-system',
};
16 changes: 16 additions & 0 deletions packages/formatters/typedoc.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Copyright 2025 Hypergiant Galactic Systems Inc. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/

/** @type {Partial<import("typedoc").TypeDocOptions>} */
export default {
name: '@accelint/formatters',
};
16 changes: 16 additions & 0 deletions packages/geo/typedoc.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Copyright 2025 Hypergiant Galactic Systems Inc. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/

/** @type {Partial<import("typedoc").TypeDocOptions>} */
export default {
name: '@accelint/geo',
};
16 changes: 16 additions & 0 deletions packages/math/typedoc.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Copyright 2025 Hypergiant Galactic Systems Inc. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/

/** @type {Partial<import("typedoc").TypeDocOptions>} */
export default {
name: '@accelint/constants',
orteth01 marked this conversation as resolved.
Show resolved Hide resolved
};
16 changes: 16 additions & 0 deletions packages/predicates/typedoc.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Copyright 2025 Hypergiant Galactic Systems Inc. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/

/** @type {Partial<import("typedoc").TypeDocOptions>} */
export default {
name: '@accelint/predicates',
};
16 changes: 16 additions & 0 deletions packages/temporal/typedoc.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Copyright 2025 Hypergiant Galactic Systems Inc. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/

/** @type {Partial<import("typedoc").TypeDocOptions>} */
export default {
name: '@accelint/temporal',
};
16 changes: 16 additions & 0 deletions packages/web-worker/typedoc.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Copyright 2025 Hypergiant Galactic Systems Inc. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/

/** @type {Partial<import("typedoc").TypeDocOptions>} */
export default {
name: '@accelint/web-worker',
};
16 changes: 16 additions & 0 deletions packages/websocket/typedoc.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Copyright 2025 Hypergiant Galactic Systems Inc. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/

/** @type {Partial<import("typedoc").TypeDocOptions>} */
export default {
name: '@accelint/websocket',
};
Loading
Loading