@kubb/react-fabric 0.0.0 → 0.1.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 (50) hide show
  1. package/dist/devtools.cjs +154 -85
  2. package/dist/devtools.cjs.map +1 -1
  3. package/dist/devtools.js +154 -85
  4. package/dist/devtools.js.map +1 -1
  5. package/dist/{globals-C6rGETh5.d.ts → globals-BQ_tJj2b.d.ts} +3 -3
  6. package/dist/{globals-CnATk-Sl.d.cts → globals-C-9ezLk9.d.cts} +3 -3
  7. package/dist/globals.d.cts +2 -2
  8. package/dist/globals.d.ts +2 -2
  9. package/dist/index.cjs +47 -73
  10. package/dist/index.cjs.map +1 -1
  11. package/dist/index.d.cts +63 -52
  12. package/dist/index.d.ts +63 -52
  13. package/dist/index.js +47 -72
  14. package/dist/index.js.map +1 -1
  15. package/dist/jsx-runtime.cjs +15 -7
  16. package/dist/jsx-runtime.cjs.map +1 -0
  17. package/dist/{jsx-dev-runtime.d.ts → jsx-runtime.d.cts} +3 -3
  18. package/dist/{jsx-dev-runtime.d.cts → jsx-runtime.d.ts} +3 -3
  19. package/dist/jsx-runtime.js +12 -4
  20. package/dist/jsx-runtime.js.map +1 -0
  21. package/dist/{types-C3p0Ljxf.d.cts → types-CUKR3KZn.d.cts} +1 -1
  22. package/dist/{types-DEroxUW0.d.ts → types-D9OfSq91.d.ts} +1 -1
  23. package/dist/types.d.cts +1 -1
  24. package/dist/types.d.ts +1 -1
  25. package/package.json +9 -7
  26. package/src/ReactTemplate.tsx +22 -24
  27. package/src/components/Const.tsx +4 -17
  28. package/src/components/File.tsx +1 -1
  29. package/src/components/Function.tsx +6 -38
  30. package/src/components/Root.tsx +5 -9
  31. package/src/components/Type.tsx +1 -7
  32. package/src/{hooks → composables}/useApp.ts +2 -2
  33. package/src/createApp.ts +4 -9
  34. package/src/dom.ts +5 -3
  35. package/src/globals.ts +1 -1
  36. package/src/index.ts +3 -4
  37. package/src/utils/processFiles.ts +1 -1
  38. package/src/utils/squashExportNodes.ts +1 -1
  39. package/src/utils/squashImportNodes.ts +1 -1
  40. package/src/utils/squashSourceNodes.ts +1 -1
  41. package/dist/jsx-dev-runtime.cjs +0 -9
  42. package/dist/jsx-dev-runtime.js +0 -6
  43. package/dist/jsx-runtime-DmD5u6a-.js +0 -13
  44. package/dist/jsx-runtime-DmD5u6a-.js.map +0 -1
  45. package/dist/jsx-runtime-zKfRQHQD.cjs +0 -36
  46. package/dist/jsx-runtime-zKfRQHQD.cjs.map +0 -1
  47. package/src/components/Text.tsx +0 -31
  48. package/src/utils/throttle.ts +0 -30
  49. /package/src/{hooks → composables}/useFile.ts +0 -0
  50. /package/src/{hooks → composables}/useLifecycle.tsx +0 -0
package/dist/index.js CHANGED
@@ -2,8 +2,8 @@ import { n as __commonJS, r as __toESM, t as require_react } from "./react-BBkwF
2
2
  import "./globals-Df5klKjG.js";
3
3
  import { t as require_jsx_runtime } from "./jsx-runtime-BPQkRAg2.js";
4
4
  import dedent from "dedent";
5
- import process$1 from "node:process";
6
5
  import { defineApp } from "@kubb/fabric-core";
6
+ import process$1 from "node:process";
7
7
  import { onExit } from "signal-exit";
8
8
  import { createExport, createImport, print } from "@kubb/fabric-core/parsers/typescript";
9
9
  import { orderBy } from "natural-orderby";
@@ -70,21 +70,15 @@ var ErrorBoundary = class extends import_react.Component {
70
70
  }
71
71
  };
72
72
  _defineProperty(ErrorBoundary, "displayName", "KubbErrorBoundary");
73
- const RootContext = (0, import_react.createContext)({
74
- exit: () => {},
75
- meta: {}
76
- });
77
- function Root({ onError, onExit: onExit$1, meta, children }) {
73
+ const RootContext = (0, import_react.createContext)({ exit: () => {} });
74
+ function Root({ onError, onExit: onExit$1, children }) {
78
75
  try {
79
76
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ErrorBoundary, {
80
77
  onError: (error) => {
81
78
  onError(error);
82
79
  },
83
80
  children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RootContext.Provider, {
84
- value: {
85
- meta,
86
- exit: onExit$1
87
- },
81
+ value: { exit: onExit$1 },
88
82
  children
89
83
  })
90
84
  });
@@ -111,21 +105,6 @@ function App({ meta, children }) {
111
105
  App.Context = AppContext;
112
106
  App.displayName = "KubbApp";
113
107
 
114
- //#endregion
115
- //#region src/components/Text.tsx
116
- /**
117
- * @deprecated
118
- */
119
- function Text({ children }) {
120
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("kubb-text", { children });
121
- }
122
- Text.displayName = "KubbText";
123
- function Space({}) {
124
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("kubb-text", { children: " " });
125
- }
126
- Space.displayName = "KubbSpace";
127
- Text.Space = Space;
128
-
129
108
  //#endregion
130
109
  //#region src/utils/createJSDoc.ts
131
110
  function createJSDoc({ comments }) {
@@ -139,18 +118,18 @@ function createJSDoc({ comments }) {
139
118
  function Const({ name, export: canExport, type, JSDoc, asConst, children }) {
140
119
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
141
120
  (JSDoc === null || JSDoc === void 0 ? void 0 : JSDoc.comments) && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [createJSDoc({ comments: JSDoc === null || JSDoc === void 0 ? void 0 : JSDoc.comments }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("br", {})] }),
142
- canExport && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: ["export", /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Space, {})] }),
121
+ canExport && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: "export " }),
143
122
  "const ",
144
123
  name,
145
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Space, {}),
124
+ " ",
146
125
  type && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
147
126
  ":",
148
127
  type,
149
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Space, {})
128
+ " "
150
129
  ] }),
151
130
  "= ",
152
131
  children,
153
- asConst && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Space, {}), "as const"] })
132
+ asConst && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: " as const" })
154
133
  ] });
155
134
  }
156
135
  Const.displayName = "KubbConst";
@@ -256,9 +235,9 @@ function Indent({ size = 2, children }) {
256
235
  function Function({ name, default: isDefault, export: canExport, async, generics, params, returnType, JSDoc, children }) {
257
236
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
258
237
  (JSDoc === null || JSDoc === void 0 ? void 0 : JSDoc.comments) && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [createJSDoc({ comments: JSDoc === null || JSDoc === void 0 ? void 0 : JSDoc.comments }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("br", {})] }),
259
- canExport && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: ["export", /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Space, {})] }),
260
- isDefault && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: ["default", /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Space, {})] }),
261
- async && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: ["async", /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Space, {})] }),
238
+ canExport && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: "export " }),
239
+ isDefault && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: "default " }),
240
+ async && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: "async " }),
262
241
  "function ",
263
242
  name,
264
243
  generics && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
@@ -290,13 +269,12 @@ Function.displayName = "KubbFunction";
290
269
  function ArrowFunction({ name, default: isDefault, export: canExport, async, generics, params, returnType, JSDoc, singleLine, children }) {
291
270
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
292
271
  (JSDoc === null || JSDoc === void 0 ? void 0 : JSDoc.comments) && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [createJSDoc({ comments: JSDoc === null || JSDoc === void 0 ? void 0 : JSDoc.comments }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("br", {})] }),
293
- canExport && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: ["export", /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Space, {})] }),
294
- isDefault && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: ["default", /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Space, {})] }),
272
+ canExport && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: "export " }),
273
+ isDefault && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: "default " }),
295
274
  "const ",
296
275
  name,
297
- " =",
298
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Space, {}),
299
- async && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: ["async", /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Space, {})] }),
276
+ " = ",
277
+ async && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: "async " }),
300
278
  generics && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
301
279
  "<",
302
280
  Array.isArray(generics) ? generics.join(", ").trim() : generics,
@@ -339,7 +317,7 @@ function Type({ name, export: canExport, JSDoc, children }) {
339
317
  if (name.charAt(0).toUpperCase() !== name.charAt(0)) throw new Error("Name should start with a capital letter(see TypeScript types)");
340
318
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
341
319
  (JSDoc === null || JSDoc === void 0 ? void 0 : JSDoc.comments) && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [createJSDoc({ comments: JSDoc === null || JSDoc === void 0 ? void 0 : JSDoc.comments }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("br", {})] }),
342
- canExport && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: ["export", /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Space, {})] }),
320
+ canExport && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: "export " }),
343
321
  "type ",
344
322
  name,
345
323
  " = ",
@@ -382,8 +360,10 @@ const createNode = (nodeName) => {
382
360
  };
383
361
  const appendChildNode = (node, childNode) => {
384
362
  if (childNode.parentNode) removeChildNode(childNode.parentNode, childNode);
385
- childNode.parentNode = node;
386
- node.childNodes.push(childNode);
363
+ if (node.nodeName !== "#text") {
364
+ childNode.parentNode = node;
365
+ node.childNodes.push(childNode);
366
+ }
387
367
  };
388
368
  const insertBeforeNode = (node, newChildNode, beforeChildNode) => {
389
369
  if (newChildNode.parentNode) removeChildNode(newChildNode.parentNode, newChildNode);
@@ -15612,15 +15592,15 @@ function _classPrivateFieldSet2(s, a, r) {
15612
15592
  //#endregion
15613
15593
  //#region src/ReactTemplate.tsx
15614
15594
  var import_constants = /* @__PURE__ */ __toESM(require_constants());
15615
- var _options = /* @__PURE__ */ new WeakMap();
15595
+ var _context = /* @__PURE__ */ new WeakMap();
15616
15596
  var _isUnmounted = /* @__PURE__ */ new WeakMap();
15617
15597
  var _container = /* @__PURE__ */ new WeakMap();
15618
15598
  var _rootNode = /* @__PURE__ */ new WeakMap();
15619
15599
  var _ReactTemplate_brand = /* @__PURE__ */ new WeakSet();
15620
15600
  var ReactTemplate = class {
15621
- constructor(options) {
15601
+ constructor(context) {
15622
15602
  _classPrivateMethodInitSpec(this, _ReactTemplate_brand);
15623
- _classPrivateFieldInitSpec(this, _options, void 0);
15603
+ _classPrivateFieldInitSpec(this, _context, void 0);
15624
15604
  _classPrivateFieldInitSpec(this, _isUnmounted, void 0);
15625
15605
  _defineProperty(this, "exitPromise", void 0);
15626
15606
  _classPrivateFieldInitSpec(this, _container, void 0);
@@ -15629,22 +15609,23 @@ var ReactTemplate = class {
15629
15609
  _defineProperty(this, "rejectExitPromise", () => {});
15630
15610
  _defineProperty(this, "unsubscribeExit", () => {});
15631
15611
  _defineProperty(this, "onRender", async () => {
15612
+ var _classPrivateFieldGet2$1, _classPrivateFieldGet3, _classPrivateFieldGet4, _classPrivateFieldGet5;
15632
15613
  if (_classPrivateFieldGet2(_isUnmounted, this)) return;
15633
- _classPrivateFieldGet2(_options, this).context.clear();
15634
- processFiles(_classPrivateFieldGet2(_rootNode, this), _classPrivateFieldGet2(_options, this).context);
15635
- if (!_classPrivateFieldGet2(_options, this).debug && !_classPrivateFieldGet2(_options, this).stdout) return;
15636
- const output = await _assertClassBrand(_ReactTemplate_brand, this, _getOutput).call(this, _classPrivateFieldGet2(_rootNode, this), _classPrivateFieldGet2(_options, this).context);
15637
- if (_classPrivateFieldGet2(_options, this).debug) {
15614
+ _classPrivateFieldGet2(_context, this).clear();
15615
+ processFiles(_classPrivateFieldGet2(_rootNode, this), _classPrivateFieldGet2(_context, this));
15616
+ if (!((_classPrivateFieldGet2$1 = _classPrivateFieldGet2(_context, this).options) === null || _classPrivateFieldGet2$1 === void 0 ? void 0 : _classPrivateFieldGet2$1.debug) && !((_classPrivateFieldGet3 = _classPrivateFieldGet2(_context, this).options) === null || _classPrivateFieldGet3 === void 0 ? void 0 : _classPrivateFieldGet3.stdout)) return;
15617
+ const output = await _assertClassBrand(_ReactTemplate_brand, this, _getOutput).call(this, _classPrivateFieldGet2(_rootNode, this), _classPrivateFieldGet2(_context, this));
15618
+ if ((_classPrivateFieldGet4 = _classPrivateFieldGet2(_context, this).options) === null || _classPrivateFieldGet4 === void 0 ? void 0 : _classPrivateFieldGet4.debug) {
15638
15619
  console.log("Rendering: \n");
15639
15620
  console.log(output);
15640
15621
  }
15641
- if (_classPrivateFieldGet2(_options, this).stdout) {
15642
- _classPrivateFieldGet2(_options, this).stdout.clearLine(0);
15643
- _classPrivateFieldGet2(_options, this).stdout.cursorTo(0);
15644
- _classPrivateFieldGet2(_options, this).stdout.write(output);
15622
+ if (((_classPrivateFieldGet5 = _classPrivateFieldGet2(_context, this).options) === null || _classPrivateFieldGet5 === void 0 ? void 0 : _classPrivateFieldGet5.stdout) && process$1.env.NODE_ENV !== "test") {
15623
+ _classPrivateFieldGet2(_context, this).options.stdout.clearLine(0);
15624
+ _classPrivateFieldGet2(_context, this).options.stdout.cursorTo(0);
15625
+ _classPrivateFieldGet2(_context, this).options.stdout.write(output);
15645
15626
  }
15646
15627
  });
15647
- _classPrivateFieldSet2(_options, this, { ...options });
15628
+ _classPrivateFieldSet2(_context, this, context);
15648
15629
  _classPrivateFieldSet2(_rootNode, this, createNode("kubb-root"));
15649
15630
  _classPrivateFieldGet2(_rootNode, this).onRender = this.onRender;
15650
15631
  _classPrivateFieldGet2(_rootNode, this).onImmediateRender = this.onRender;
@@ -15686,9 +15667,8 @@ var ReactTemplate = class {
15686
15667
  onExit(error) {
15687
15668
  this.unmount(error);
15688
15669
  }
15689
- render(node, { meta = {} } = { meta: {} }) {
15670
+ render(node) {
15690
15671
  const element = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Root, {
15691
- meta,
15692
15672
  onExit: this.onExit.bind(this),
15693
15673
  onError: this.onError.bind(this),
15694
15674
  children: node
@@ -15696,21 +15676,21 @@ var ReactTemplate = class {
15696
15676
  KubbRenderer.updateContainerSync(element, _classPrivateFieldGet2(_container, this), null, null);
15697
15677
  KubbRenderer.flushSyncWork();
15698
15678
  }
15699
- async renderToString(node, { meta = {} } = { meta: {} }) {
15679
+ async renderToString(node) {
15700
15680
  const element = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Root, {
15701
- meta,
15702
15681
  onExit: this.onExit.bind(this),
15703
15682
  onError: this.onError.bind(this),
15704
15683
  children: node
15705
15684
  });
15706
15685
  KubbRenderer.updateContainerSync(element, _classPrivateFieldGet2(_container, this), null, null);
15707
15686
  KubbRenderer.flushSyncWork();
15708
- _classPrivateFieldGet2(_options, this).context.clear();
15709
- return _assertClassBrand(_ReactTemplate_brand, this, _getOutput).call(this, _classPrivateFieldGet2(_rootNode, this), _classPrivateFieldGet2(_options, this).context);
15687
+ _classPrivateFieldGet2(_context, this).clear();
15688
+ return _assertClassBrand(_ReactTemplate_brand, this, _getOutput).call(this, _classPrivateFieldGet2(_rootNode, this), _classPrivateFieldGet2(_context, this));
15710
15689
  }
15711
15690
  unmount(error) {
15691
+ var _classPrivateFieldGet6;
15712
15692
  if (_classPrivateFieldGet2(_isUnmounted, this)) return;
15713
- if (_classPrivateFieldGet2(_options, this).debug) console.log("Unmount", error);
15693
+ if ((_classPrivateFieldGet6 = _classPrivateFieldGet2(_context, this).options) === null || _classPrivateFieldGet6 === void 0 ? void 0 : _classPrivateFieldGet6.debug) console.log("Unmount", error);
15714
15694
  this.onRender();
15715
15695
  this.unsubscribeExit();
15716
15696
  _classPrivateFieldSet2(_isUnmounted, this, true);
@@ -15738,18 +15718,13 @@ async function _getOutput(node, context) {
15738
15718
  //#endregion
15739
15719
  //#region src/createApp.ts
15740
15720
  const createApp = defineApp((app, context) => {
15741
- const template = process$1.env.NODE_ENV === "test" ? new ReactTemplate({ context }) : new ReactTemplate({
15742
- context,
15743
- stdout: process$1.stdout,
15744
- stderr: process$1.stderr,
15745
- stdin: process$1.stdin
15746
- });
15721
+ const template = new ReactTemplate(context);
15747
15722
  return {
15748
15723
  render() {
15749
- template.render(createElement(app));
15724
+ template.render((0, import_react.createElement)(app));
15750
15725
  },
15751
15726
  async renderToString() {
15752
- return template.renderToString(createElement(app));
15727
+ return template.renderToString((0, import_react.createElement)(app));
15753
15728
  },
15754
15729
  waitUntilExit() {
15755
15730
  return template.waitUntilExit();
@@ -15758,7 +15733,7 @@ const createApp = defineApp((app, context) => {
15758
15733
  });
15759
15734
 
15760
15735
  //#endregion
15761
- //#region src/hooks/useApp.ts
15736
+ //#region src/composables/useApp.ts
15762
15737
  /**
15763
15738
  * `useApp` will return the current App with plugin, pluginManager, fileManager and mode.
15764
15739
  */
@@ -15769,7 +15744,7 @@ function useApp() {
15769
15744
  }
15770
15745
 
15771
15746
  //#endregion
15772
- //#region src/hooks/useFile.ts
15747
+ //#region src/composables/useFile.ts
15773
15748
  /**
15774
15749
  * `useFile` will return the current file when <File/> is used.
15775
15750
  */
@@ -15778,7 +15753,7 @@ function useFile() {
15778
15753
  }
15779
15754
 
15780
15755
  //#endregion
15781
- //#region src/hooks/useLifecycle.tsx
15756
+ //#region src/composables/useLifecycle.tsx
15782
15757
  /**
15783
15758
  * `useLifecycle` will return some helpers to exit/restart the generation.
15784
15759
  */
@@ -15917,5 +15892,5 @@ const use = import_react.use;
15917
15892
  const useReducer = import_react.useReducer;
15918
15893
 
15919
15894
  //#endregion
15920
- export { App, Const, File, Function, FunctionParams, Indent, Text, Type, createApp, createContext, createElement, createFunctionParams, use, useApp, useContext, useEffect, useFile, useLifecycle, useReducer, useRef, useState };
15895
+ export { App, Const, File, Function, FunctionParams, Indent, Type, createApp, createContext, createElement, createFunctionParams, use, useApp, useContext, useEffect, useFile, useLifecycle, useReducer, useRef, useState };
15921
15896
  //# sourceMappingURL=index.js.map