@kubb/react-fabric 0.9.5 → 0.11.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 (108) hide show
  1. package/dist/{Fabric-DitK3IEP.d.ts → Fabric-BELBf-bX.d.cts} +5 -5
  2. package/dist/{Fabric-C61uYmUy.d.cts → Fabric-DbJhvsCq.d.ts} +5 -5
  3. package/dist/{devtools-D6dZodXp.js → devtools-8_UKWDTl.js} +1 -1
  4. package/dist/{devtools-D6dZodXp.js.map → devtools-8_UKWDTl.js.map} +1 -1
  5. package/dist/{devtools-CRkwwngz.cjs → devtools-BOpUJhc_.cjs} +1 -1
  6. package/dist/{devtools-CRkwwngz.cjs.map → devtools-BOpUJhc_.cjs.map} +1 -1
  7. package/dist/devtools.cjs +1 -1
  8. package/dist/devtools.js +1 -1
  9. package/dist/globals.d.cts +2 -2
  10. package/dist/globals.d.ts +2 -2
  11. package/dist/index.cjs +166 -73
  12. package/dist/index.cjs.map +1 -1
  13. package/dist/index.d.cts +3 -359
  14. package/dist/index.d.ts +3 -359
  15. package/dist/index.js +151 -68
  16. package/dist/index.js.map +1 -1
  17. package/dist/jsx-dev-runtime.d.cts +5 -5
  18. package/dist/jsx-dev-runtime.d.ts +3 -3
  19. package/dist/{jsx-namespace-BAkGpU6g.d.ts → jsx-namespace-CBOEkCmJ.d.ts} +2 -2
  20. package/dist/{jsx-namespace-CCPa1Nut.d.cts → jsx-namespace-od7sqrmY.d.cts} +2 -2
  21. package/dist/{jsx-runtime-BEVcoJUm.cjs → jsx-runtime-Cq39dA50.cjs} +1 -1
  22. package/dist/{jsx-runtime-BEVcoJUm.cjs.map → jsx-runtime-Cq39dA50.cjs.map} +1 -1
  23. package/dist/{jsx-runtime-DDu0mFTI.js → jsx-runtime-Isgf9orn.js} +1 -1
  24. package/dist/{jsx-runtime-DDu0mFTI.js.map → jsx-runtime-Isgf9orn.js.map} +1 -1
  25. package/dist/jsx-runtime.cjs +1 -1
  26. package/dist/jsx-runtime.d.cts +5 -5
  27. package/dist/jsx-runtime.d.ts +3 -3
  28. package/dist/jsx-runtime.js +1 -1
  29. package/dist/parsers.d.cts +1 -1
  30. package/dist/parsers.d.ts +1 -1
  31. package/dist/plugins.cjs +2 -2
  32. package/dist/plugins.d.cts +2 -2
  33. package/dist/plugins.d.ts +2 -2
  34. package/dist/plugins.js +2 -2
  35. package/dist/{reactPlugin-CXaAO13f.cjs → reactPlugin-B8F6jVb5.cjs} +77 -64
  36. package/dist/reactPlugin-B8F6jVb5.cjs.map +1 -0
  37. package/dist/{reactPlugin-ixOr00MK.js → reactPlugin-CAtVV84d.js} +78 -53
  38. package/dist/reactPlugin-CAtVV84d.js.map +1 -0
  39. package/dist/types-C3ODUOKN.d.cts +675 -0
  40. package/dist/types-DwaohVJS.d.ts +675 -0
  41. package/dist/types.d.cts +3 -3
  42. package/dist/types.d.ts +3 -3
  43. package/package.json +3 -3
  44. package/src/Runtime.tsx +22 -12
  45. package/src/components/App.tsx +24 -15
  46. package/src/components/Const.tsx +19 -3
  47. package/src/components/File.tsx +107 -31
  48. package/src/components/Function.tsx +36 -5
  49. package/src/components/Indent.tsx +3 -0
  50. package/src/components/Root.tsx +26 -20
  51. package/src/components/Type.tsx +19 -2
  52. package/src/components/__snapshots__/arrow_function.ts +3 -0
  53. package/src/components/__snapshots__/arrow_function_default.ts +3 -0
  54. package/src/components/__snapshots__/arrow_function_generics.ts +3 -0
  55. package/src/components/__snapshots__/arrow_function_single_line.ts +1 -0
  56. package/src/components/__snapshots__/arrow_function_with_generics.ts +3 -0
  57. package/src/components/__snapshots__/async_arrow_function.ts +3 -0
  58. package/src/components/__snapshots__/async_function.ts +3 -0
  59. package/src/components/__snapshots__/async_function_with_Promise_return_type.ts +3 -0
  60. package/src/components/__snapshots__/basic_arrow_function.ts +3 -0
  61. package/src/components/__snapshots__/basic_const.ts +1 -0
  62. package/src/components/__snapshots__/basic_export.ts +1 -0
  63. package/src/components/__snapshots__/basic_function.ts +3 -0
  64. package/src/components/__snapshots__/basic_import.ts +1 -0
  65. package/src/components/__snapshots__/basic_type.ts +1 -0
  66. package/src/components/__snapshots__/const_with_JSDoc.ts +4 -0
  67. package/src/components/__snapshots__/const_with_as_const.ts +1 -0
  68. package/src/components/__snapshots__/const_with_type.ts +1 -0
  69. package/src/components/__snapshots__/default_exported_arrow_function.ts +3 -0
  70. package/src/components/__snapshots__/default_exported_function.ts +3 -0
  71. package/src/components/__snapshots__/exported_arrow_function.ts +3 -0
  72. package/src/components/__snapshots__/exported_const.ts +1 -0
  73. package/src/components/__snapshots__/exported_function.ts +3 -0
  74. package/src/components/__snapshots__/exported_type.ts +1 -0
  75. package/src/components/__snapshots__/function_generics.ts +3 -0
  76. package/src/components/__snapshots__/function_with_JSDoc.ts +6 -0
  77. package/src/components/__snapshots__/function_with_comments.ts +6 -0
  78. package/src/components/__snapshots__/function_with_generics.ts +3 -0
  79. package/src/components/__snapshots__/function_with_parameters.ts +3 -0
  80. package/src/components/__snapshots__/function_with_params.ts +3 -0
  81. package/src/components/__snapshots__/function_with_returnType.ts +3 -0
  82. package/src/components/__snapshots__/function_with_return_type.ts +3 -0
  83. package/src/components/__snapshots__/matches_with_root_import.ts +1 -0
  84. package/src/components/__snapshots__/multiple_functions.ts +3 -0
  85. package/src/components/__snapshots__/named_export.ts +1 -0
  86. package/src/components/__snapshots__/named_export_(object_advanced).ts +1 -0
  87. package/src/components/__snapshots__/named_import.ts +1 -0
  88. package/src/components/__snapshots__/named_import_(object).ts +1 -0
  89. package/src/components/__snapshots__/named_import_(object_advanced).ts +1 -0
  90. package/src/components/__snapshots__/named_typed_export.ts +1 -0
  91. package/src/components/__snapshots__/named_typed_import.ts +1 -0
  92. package/src/components/__snapshots__/single_line_arrow_function.ts +1 -0
  93. package/src/components/__snapshots__/type_with_JSDoc.ts +4 -0
  94. package/src/components/__snapshots__/typed_export.ts +1 -0
  95. package/src/components/__snapshots__/typed_import.ts +1 -0
  96. package/src/composables/useApp.ts +1 -15
  97. package/src/composables/useFile.ts +1 -12
  98. package/src/composables/useLifecycle.tsx +7 -8
  99. package/src/index.ts +5 -1
  100. package/src/plugins/reactPlugin.ts +7 -6
  101. package/src/types.ts +0 -4
  102. package/src/utils/createJSDoc.ts +1 -8
  103. package/dist/reactPlugin-4-kcMKwZ.d.ts +0 -31
  104. package/dist/reactPlugin-B4xarQJX.d.cts +0 -31
  105. package/dist/reactPlugin-CXaAO13f.cjs.map +0 -1
  106. package/dist/reactPlugin-ixOr00MK.js.map +0 -1
  107. package/dist/types-CSUzVTpn.d.ts +0 -104
  108. package/dist/types-DP2mgqeb.d.cts +0 -104
@@ -0,0 +1,3 @@
1
+ function myFunc(a: string, b: number) {
2
+ return true
3
+ }
@@ -0,0 +1,3 @@
1
+ function myFunc(a: string, b: number) {
2
+ return true;
3
+ }
@@ -0,0 +1,3 @@
1
+ function myFunc(): boolean {
2
+ return true;
3
+ }
@@ -0,0 +1,3 @@
1
+ function myFunc(): boolean {
2
+ return true
3
+ }
@@ -0,0 +1 @@
1
+ import fabric from "./fabric/@kubb/react-fabric";
@@ -0,0 +1,3 @@
1
+ export async function getData<TData>(): Promise<number> {
2
+ 2;
3
+ }
@@ -0,0 +1 @@
1
+ export type { createFabric } from "@kubb/react-fabric";
@@ -0,0 +1 @@
1
+ export { App, createFrabric } from "@kubb/react-fabric";
@@ -0,0 +1 @@
1
+ import type { createFabric } from "@kubb/react-fabric";
@@ -0,0 +1 @@
1
+ import { createFabric as create } from "@kubb/react-fabric";
@@ -0,0 +1 @@
1
+ import { App, createFabric as create } from "@kubb/react-fabric";
@@ -0,0 +1 @@
1
+ export type { Fabric } from "@kubb/react-fabric";
@@ -0,0 +1 @@
1
+ import type { Fabric } from "@kubb/react-fabric";
@@ -0,0 +1 @@
1
+ const myFunc = () => true
@@ -0,0 +1,4 @@
1
+ /**
2
+ * This is a variable
3
+ */
4
+ type MyType = { a: string }
@@ -0,0 +1 @@
1
+ export type * from "@kubb/react-fabric";
@@ -0,0 +1 @@
1
+ import type fabric from "@kubb/react-fabric";
@@ -1,15 +1 @@
1
- import { useContext } from 'react'
2
- import { App, type AppContextProps } from '../components/App.tsx'
3
-
4
- /**
5
- * `useApp` will return the current App with plugin, pluginManager, fileManager and mode.
6
- */
7
- export function useApp<TMeta = unknown>(): AppContextProps<TMeta> {
8
- const app = useContext(App.Context)
9
-
10
- if (!app) {
11
- throw new Error('<App /> should be set')
12
- }
13
-
14
- return app as AppContextProps<TMeta>
15
- }
1
+ export { useApp } from '@kubb/fabric-core'
@@ -1,12 +1 @@
1
- import { useContext } from 'react'
2
- import type { FileContextProps } from '../components/File.tsx'
3
- import { File } from '../components/File.tsx'
4
-
5
- /**
6
- * `useFile` will return the current file when <File/> is used.
7
- */
8
- export function useFile(): FileContextProps {
9
- const file = useContext(File.Context)
10
-
11
- return file as FileContextProps
12
- }
1
+ export { useFile } from '@kubb/fabric-core'
@@ -1,18 +1,17 @@
1
- import { useContext } from 'react'
2
-
3
- import { Root } from '../components/Root.tsx'
1
+ import { RootContext, useContext } from '@kubb/fabric-core'
4
2
 
5
3
  /**
6
- * `useLifecycle` will return some helpers to exit/restart the generation.
4
+ * Provides lifecycle helpers that integrate with the Fabric runtime. The
5
+ * `exit` helper schedules a call to the RootContext exit function on the
6
+ * next tick to allow React to complete its render cycle first.
7
7
  */
8
8
  export function useLifecycle() {
9
- const { exit } = useContext(Root.Context)
9
+ const { exit } = useContext(RootContext)
10
10
 
11
11
  return {
12
12
  exit: () => {
13
- const timeout = setTimeout(() => {
14
- clearTimeout(timeout)
15
-
13
+ // need this to let React finish its current render cycle
14
+ setTimeout(() => {
16
15
  exit()
17
16
  }, 0)
18
17
  },
package/src/index.ts CHANGED
@@ -14,16 +14,20 @@ export const useContext = React.useContext
14
14
  export const useEffect = React.useEffect
15
15
  export const useReducer = React.useReducer
16
16
  export const useRef = React.useRef
17
- // // components
17
+ // components
18
18
  export { App } from './components/App.tsx'
19
19
  export { Const } from './components/Const.tsx'
20
20
  export { File } from './components/File.tsx'
21
21
  export { Function } from './components/Function.tsx'
22
22
  export { Indent } from './components/Indent.tsx'
23
23
  export { Type } from './components/Type.tsx'
24
+
25
+ // composables
24
26
  export { useApp } from './composables/useApp.ts'
25
27
  export { useFile } from './composables/useFile.ts'
26
28
  export { useLifecycle } from './composables/useLifecycle.tsx'
29
+
30
+ // factories
27
31
  export { createReactFabric } from './createReactFabric.ts'
28
32
  export { Runtime } from './Runtime.tsx'
29
33
  // utils
@@ -1,6 +1,7 @@
1
1
  import { definePlugin } from '@kubb/fabric-core/plugins'
2
2
  import { createElement, type ElementType } from 'react'
3
3
  import { Runtime } from '../Runtime.tsx'
4
+ import type { KubbElement } from '../types'
4
5
 
5
6
  export type Options = {
6
7
  stdout?: NodeJS.WriteStream
@@ -13,16 +14,16 @@ export type Options = {
13
14
  }
14
15
 
15
16
  type ExtendOptions = {
16
- render(App: ElementType): Promise<void>
17
- renderToString(App: ElementType): Promise<string>
17
+ render(App: KubbElement | ElementType): Promise<void>
18
+ renderToString(App: KubbElement | ElementType): Promise<string>
18
19
  waitUntilExit(): Promise<void>
19
20
  }
20
21
 
21
22
  declare global {
22
23
  namespace Kubb {
23
24
  interface Fabric {
24
- render(App: ElementType): Promise<void>
25
- renderToString(App: ElementType): Promise<string>
25
+ render(App: KubbElement | ElementType): Promise<void>
26
+ renderToString(App: KubbElement | ElementType): Promise<string>
26
27
  waitUntilExit(): Promise<void>
27
28
  }
28
29
  }
@@ -37,11 +38,11 @@ export const reactPlugin = definePlugin<Options, ExtendOptions>({
37
38
  return {
38
39
  async render(App) {
39
40
  await ctx.emit('lifecycle:start')
40
- await runtime.render(createElement(App))
41
+ await runtime.render(createElement(App as unknown as ElementType))
41
42
  },
42
43
  async renderToString(App) {
43
44
  await ctx.emit('lifecycle:start')
44
- return runtime.renderToString(createElement(App))
45
+ return runtime.renderToString(createElement(App as unknown as ElementType))
45
46
  },
46
47
  async waitUntilExit() {
47
48
  await runtime.waitUntilExit()
package/src/types.ts CHANGED
@@ -50,10 +50,6 @@ export type KubbElement = JSX.Element
50
50
 
51
51
  export type { Key } from 'react'
52
52
 
53
- export type JSDoc = {
54
- comments: string[]
55
- }
56
-
57
53
  export type KubbTextProps = {
58
54
  children?: KubbNode
59
55
  }
@@ -1,8 +1 @@
1
- export function createJSDoc({ comments }: { comments: Array<string> }): string {
2
- const filtered = comments.filter((c) => c.trim())
3
- if (!filtered.length) {
4
- return ''
5
- }
6
-
7
- return `/**\n * ${filtered.join('\n * ')}\n */`
8
- }
1
+ export { createJSDoc } from '@kubb/fabric-core'
@@ -1,31 +0,0 @@
1
- import { o as Plugin } from "./Fabric-DitK3IEP.js";
2
- import { ElementType } from "react";
3
-
4
- //#region src/plugins/reactPlugin.d.ts
5
- type Options = {
6
- stdout?: NodeJS.WriteStream;
7
- stdin?: NodeJS.ReadStream;
8
- stderr?: NodeJS.WriteStream;
9
- /**
10
- * Set this to true to always see the result of the render in the console(line per render)
11
- */
12
- debug?: boolean;
13
- };
14
- type ExtendOptions = {
15
- render(App: ElementType): Promise<void>;
16
- renderToString(App: ElementType): Promise<string>;
17
- waitUntilExit(): Promise<void>;
18
- };
19
- declare global {
20
- namespace Kubb {
21
- interface Fabric {
22
- render(App: ElementType): Promise<void>;
23
- renderToString(App: ElementType): Promise<string>;
24
- waitUntilExit(): Promise<void>;
25
- }
26
- }
27
- }
28
- declare const reactPlugin: Plugin<Options, ExtendOptions>;
29
- //#endregion
30
- export { reactPlugin as n, Options as t };
31
- //# sourceMappingURL=reactPlugin-4-kcMKwZ.d.ts.map
@@ -1,31 +0,0 @@
1
- import { o as Plugin } from "./Fabric-C61uYmUy.cjs";
2
- import { ElementType } from "react";
3
-
4
- //#region src/plugins/reactPlugin.d.ts
5
- type Options = {
6
- stdout?: NodeJS.WriteStream;
7
- stdin?: NodeJS.ReadStream;
8
- stderr?: NodeJS.WriteStream;
9
- /**
10
- * Set this to true to always see the result of the render in the console(line per render)
11
- */
12
- debug?: boolean;
13
- };
14
- type ExtendOptions = {
15
- render(App: ElementType): Promise<void>;
16
- renderToString(App: ElementType): Promise<string>;
17
- waitUntilExit(): Promise<void>;
18
- };
19
- declare global {
20
- namespace Kubb {
21
- interface Fabric {
22
- render(App: ElementType): Promise<void>;
23
- renderToString(App: ElementType): Promise<string>;
24
- waitUntilExit(): Promise<void>;
25
- }
26
- }
27
- }
28
- declare const reactPlugin: Plugin<Options, ExtendOptions>;
29
- //#endregion
30
- export { reactPlugin as n, Options as t };
31
- //# sourceMappingURL=reactPlugin-B4xarQJX.d.cts.map