@azerion/bunosaurus-theme-live-codeblock 0.0.0-stage → 4.0.0

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.
Files changed (58) hide show
  1. package/README.md +44 -2
  2. package/lib/client/context.d.ts +16 -0
  3. package/lib/client/context.js +18 -0
  4. package/lib/client/index.d.ts +7 -0
  5. package/lib/client/index.js +7 -0
  6. package/lib/index.d.ts +9 -0
  7. package/lib/index.js +31 -0
  8. package/lib/theme/CodeBlock/index.d.ts +14 -0
  9. package/lib/theme/CodeBlock/index.js +22 -0
  10. package/lib/theme/LiveCodeBlock/index.d.ts +9 -0
  11. package/lib/theme/LiveCodeBlock/index.js +11 -0
  12. package/lib/theme/Playground/Buttons/ResetButton/index.d.ts +9 -0
  13. package/lib/theme/Playground/Buttons/ResetButton/index.js +45 -0
  14. package/lib/theme/Playground/Buttons/ResetButton/styles.module.css +36 -0
  15. package/lib/theme/Playground/Container/index.d.ts +9 -0
  16. package/lib/theme/Playground/Container/index.js +10 -0
  17. package/lib/theme/Playground/Container/styles.module.css +13 -0
  18. package/lib/theme/Playground/Editor/index.d.ts +8 -0
  19. package/lib/theme/Playground/Editor/index.js +32 -0
  20. package/lib/theme/Playground/Editor/styles.module.css +17 -0
  21. package/lib/theme/Playground/Header/index.d.ts +9 -0
  22. package/lib/theme/Playground/Header/index.js +18 -0
  23. package/lib/theme/Playground/Header/styles.module.css +29 -0
  24. package/lib/theme/Playground/Layout/index.d.ts +9 -0
  25. package/lib/theme/Playground/Layout/index.js +32 -0
  26. package/lib/theme/Playground/Preview/index.d.ts +8 -0
  27. package/lib/theme/Playground/Preview/index.js +53 -0
  28. package/lib/theme/Playground/Preview/styles.module.css +11 -0
  29. package/lib/theme/Playground/Provider/index.d.ts +9 -0
  30. package/lib/theme/Playground/Provider/index.js +37 -0
  31. package/lib/theme/Playground/index.d.ts +9 -0
  32. package/lib/theme/Playground/index.js +23 -0
  33. package/lib/theme/ReactLiveScope/index.d.ts +8 -0
  34. package/lib/theme/ReactLiveScope/index.js +13 -0
  35. package/lib/validateThemeConfig.d.ts +13 -0
  36. package/lib/validateThemeConfig.js +26 -0
  37. package/package.json +56 -4
  38. package/src/client/context.tsx +32 -0
  39. package/src/client/index.ts +8 -0
  40. package/src/index.ts +35 -0
  41. package/src/theme/CodeBlock/index.tsx +38 -0
  42. package/src/theme/LiveCodeBlock/index.tsx +15 -0
  43. package/src/theme/Playground/Buttons/ResetButton/index.tsx +51 -0
  44. package/src/theme/Playground/Buttons/ResetButton/styles.module.css +36 -0
  45. package/src/theme/Playground/Container/index.tsx +16 -0
  46. package/src/theme/Playground/Container/styles.module.css +13 -0
  47. package/src/theme/Playground/Editor/index.tsx +35 -0
  48. package/src/theme/Playground/Editor/styles.module.css +17 -0
  49. package/src/theme/Playground/Header/index.tsx +26 -0
  50. package/src/theme/Playground/Header/styles.module.css +29 -0
  51. package/src/theme/Playground/Layout/index.tsx +39 -0
  52. package/src/theme/Playground/Preview/index.tsx +59 -0
  53. package/src/theme/Playground/Preview/styles.module.css +11 -0
  54. package/src/theme/Playground/Provider/index.tsx +43 -0
  55. package/src/theme/Playground/index.tsx +28 -0
  56. package/src/theme/ReactLiveScope/index.tsx +16 -0
  57. package/src/theme-live-codeblock.d.ts +142 -0
  58. package/src/validateThemeConfig.ts +33 -0
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ import type {ReactNode} from 'react';
9
+ import PlaygroundProvider from '@theme/Playground/Provider';
10
+ import PlaygroundContainer from '@theme/Playground/Container';
11
+ import PlaygroundLayout from '@theme/Playground/Layout';
12
+
13
+ import type {Props} from '@theme/Playground';
14
+
15
+ export default function Playground({
16
+ children,
17
+ transformCode,
18
+ position,
19
+ ...props
20
+ }: Props): ReactNode {
21
+ return (
22
+ <PlaygroundContainer>
23
+ <PlaygroundProvider code={children} {...props}>
24
+ <PlaygroundLayout position={position} />
25
+ </PlaygroundProvider>
26
+ </PlaygroundContainer>
27
+ );
28
+ }
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ import React from 'react';
9
+
10
+ // Add react-live imports you need here
11
+ const ReactLiveScope: unknown = {
12
+ React,
13
+ ...React,
14
+ };
15
+
16
+ export default ReactLiveScope;
@@ -0,0 +1,142 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ /// <reference types="@docusaurus/theme-classic" />
9
+ /// <reference types="@docusaurus/module-type-aliases" />
10
+
11
+ declare module '@docusaurus/theme-live-codeblock' {
12
+ import type {PlaygroundPosition} from '@theme/Playground';
13
+
14
+ export type ThemeConfig = {
15
+ liveCodeBlock: {
16
+ playgroundPosition: PlaygroundPosition;
17
+ };
18
+ };
19
+ }
20
+
21
+ declare module '@theme/LiveCodeBlock' {
22
+ import type {ReactNode} from 'react';
23
+ import type {Props as BaseProps} from '@theme/CodeBlock';
24
+
25
+ type CodeBlockProps = Omit<BaseProps, 'children'>;
26
+
27
+ export interface Props extends CodeBlockProps {
28
+ children?: string;
29
+ }
30
+
31
+ export default function LiveCodeBlock(props: Props): ReactNode;
32
+ }
33
+
34
+ declare module '@theme/Playground' {
35
+ import type {ReactNode} from 'react';
36
+ import type {Props as BaseProps} from '@theme/CodeBlock';
37
+ import type {LiveProvider} from 'react-live';
38
+
39
+ type CodeBlockProps = Omit<
40
+ BaseProps,
41
+ 'children' | 'className' | 'language' | 'title'
42
+ >;
43
+ type LiveProviderProps = React.ComponentProps<typeof LiveProvider>;
44
+
45
+ export type PlaygroundPosition = 'top' | 'bottom';
46
+
47
+ export interface Props extends CodeBlockProps, LiveProviderProps {
48
+ // Allow empty live playgrounds
49
+ children?: string;
50
+ position?: PlaygroundPosition;
51
+ }
52
+
53
+ export default function Playground(props: Props): ReactNode;
54
+ }
55
+
56
+ declare module '@theme/Playground/Provider' {
57
+ import type {ReactNode} from 'react';
58
+ import type {Props as PlaygroundProps} from '@theme/Playground';
59
+
60
+ export interface Props extends Omit<PlaygroundProps, 'children'> {
61
+ code: string | undefined;
62
+ children: ReactNode;
63
+ }
64
+
65
+ export interface ResetContextValue {
66
+ resetKey: number;
67
+ reset: () => void;
68
+ }
69
+
70
+ export const PlaygroundResetContext: React.Context<ResetContextValue | null>;
71
+ export function usePlaygroundReset(): ResetContextValue;
72
+ export default function PlaygroundProvider(props: Props): ReactNode;
73
+ }
74
+
75
+ declare module '@theme/Playground/Container' {
76
+ import type {ReactNode} from 'react';
77
+
78
+ export interface Props {
79
+ children: ReactNode;
80
+ }
81
+
82
+ export default function PlaygroundContainer(props: Props): ReactNode;
83
+ }
84
+
85
+ declare module '@theme/Playground/Layout' {
86
+ import type {ReactNode} from 'react';
87
+ import type {PlaygroundPosition} from '@theme/Playground';
88
+
89
+ export interface Props {
90
+ position?: PlaygroundPosition;
91
+ }
92
+
93
+ export default function PlaygroundLayout(props: Props): ReactNode;
94
+ }
95
+
96
+ declare module '@theme/Playground/Preview' {
97
+ import type {ReactNode} from 'react';
98
+
99
+ // eslint-disable-next-line @typescript-eslint/no-empty-interface
100
+ export interface Props {}
101
+
102
+ export default function PlaygroundPreview(props: Props): ReactNode;
103
+ }
104
+
105
+ declare module '@theme/Playground/Editor' {
106
+ import type {ReactNode} from 'react';
107
+
108
+ // eslint-disable-next-line @typescript-eslint/no-empty-interface
109
+ export interface Props {}
110
+
111
+ export default function PlaygroundEditor(props: Props): ReactNode;
112
+ }
113
+
114
+ declare module '@theme/Playground/Header' {
115
+ import type {ReactNode} from 'react';
116
+
117
+ export interface Props {
118
+ children: ReactNode;
119
+ buttons?: ReactNode;
120
+ }
121
+
122
+ export default function PlaygroundHeader(props: Props): ReactNode;
123
+ }
124
+
125
+ declare module '@theme/Playground/Buttons/ResetButton' {
126
+ import type {ReactNode} from 'react';
127
+
128
+ export interface Props {
129
+ className?: string;
130
+ }
131
+
132
+ export default function ResetButton(props: Props): ReactNode;
133
+ }
134
+
135
+ declare module '@theme/ReactLiveScope' {
136
+ type Scope = {
137
+ [key: string]: unknown;
138
+ };
139
+
140
+ const ReactLiveScope: Scope;
141
+ export default ReactLiveScope;
142
+ }
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ import {Joi} from '@docusaurus/utils-validation';
9
+ import type {
10
+ ThemeConfig,
11
+ ThemeConfigValidationContext,
12
+ } from '@docusaurus/types';
13
+
14
+ export const DEFAULT_CONFIG = {
15
+ playgroundPosition: 'bottom',
16
+ };
17
+
18
+ export const Schema = Joi.object<ThemeConfig>({
19
+ liveCodeBlock: Joi.object({
20
+ playgroundPosition: Joi.string()
21
+ .equal('top', 'bottom')
22
+ .default(DEFAULT_CONFIG.playgroundPosition),
23
+ })
24
+ .label('themeConfig.liveCodeBlock')
25
+ .default(DEFAULT_CONFIG),
26
+ });
27
+
28
+ export function validateThemeConfig({
29
+ validate,
30
+ themeConfig,
31
+ }: ThemeConfigValidationContext<ThemeConfig>): ThemeConfig {
32
+ return validate(Schema, themeConfig);
33
+ }