@kubb/react-fabric 0.0.0 → 0.0.1

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.
package/dist/index.cjs CHANGED
@@ -3,10 +3,10 @@ require('./globals-8sJ940pg.cjs');
3
3
  const require_jsx_runtime$1 = require('./jsx-runtime-B3MMb3PL.cjs');
4
4
  let dedent = require("dedent");
5
5
  dedent = require_react$1.__toESM(dedent);
6
- let node_process = require("node:process");
7
- node_process = require_react$1.__toESM(node_process);
8
6
  let __kubb_fabric_core = require("@kubb/fabric-core");
9
7
  __kubb_fabric_core = require_react$1.__toESM(__kubb_fabric_core);
8
+ let node_process = require("node:process");
9
+ node_process = require_react$1.__toESM(node_process);
10
10
  let signal_exit = require("signal-exit");
11
11
  signal_exit = require_react$1.__toESM(signal_exit);
12
12
  let __kubb_fabric_core_parsers_typescript = require("@kubb/fabric-core/parsers/typescript");
@@ -76,21 +76,15 @@ var ErrorBoundary = class extends import_react.Component {
76
76
  }
77
77
  };
78
78
  _defineProperty(ErrorBoundary, "displayName", "KubbErrorBoundary");
79
- const RootContext = (0, import_react.createContext)({
80
- exit: () => {},
81
- meta: {}
82
- });
83
- function Root({ onError, onExit: onExit$1, meta, children }) {
79
+ const RootContext = (0, import_react.createContext)({ exit: () => {} });
80
+ function Root({ onError, onExit: onExit$1, children }) {
84
81
  try {
85
82
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ErrorBoundary, {
86
83
  onError: (error) => {
87
84
  onError(error);
88
85
  },
89
86
  children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RootContext.Provider, {
90
- value: {
91
- meta,
92
- exit: onExit$1
93
- },
87
+ value: { exit: onExit$1 },
94
88
  children
95
89
  })
96
90
  });
@@ -117,21 +111,6 @@ function App({ meta, children }) {
117
111
  App.Context = AppContext;
118
112
  App.displayName = "KubbApp";
119
113
 
120
- //#endregion
121
- //#region src/components/Text.tsx
122
- /**
123
- * @deprecated
124
- */
125
- function Text({ children }) {
126
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("kubb-text", { children });
127
- }
128
- Text.displayName = "KubbText";
129
- function Space({}) {
130
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("kubb-text", { children: " " });
131
- }
132
- Space.displayName = "KubbSpace";
133
- Text.Space = Space;
134
-
135
114
  //#endregion
136
115
  //#region src/utils/createJSDoc.ts
137
116
  function createJSDoc({ comments }) {
@@ -145,18 +124,18 @@ function createJSDoc({ comments }) {
145
124
  function Const({ name, export: canExport, type, JSDoc, asConst, children }) {
146
125
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
147
126
  (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", {})] }),
148
- canExport && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: ["export", /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Space, {})] }),
127
+ canExport && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: "export " }),
149
128
  "const ",
150
129
  name,
151
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Space, {}),
130
+ " ",
152
131
  type && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
153
132
  ":",
154
133
  type,
155
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Space, {})
134
+ " "
156
135
  ] }),
157
136
  "= ",
158
137
  children,
159
- asConst && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Space, {}), "as const"] })
138
+ asConst && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: " as const" })
160
139
  ] });
161
140
  }
162
141
  Const.displayName = "KubbConst";
@@ -262,9 +241,9 @@ function Indent({ size = 2, children }) {
262
241
  function Function({ name, default: isDefault, export: canExport, async, generics, params, returnType, JSDoc, children }) {
263
242
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
264
243
  (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", {})] }),
265
- canExport && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: ["export", /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Space, {})] }),
266
- isDefault && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: ["default", /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Space, {})] }),
267
- async && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: ["async", /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Space, {})] }),
244
+ canExport && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: "export " }),
245
+ isDefault && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: "default " }),
246
+ async && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: "async " }),
268
247
  "function ",
269
248
  name,
270
249
  generics && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
@@ -296,13 +275,12 @@ Function.displayName = "KubbFunction";
296
275
  function ArrowFunction({ name, default: isDefault, export: canExport, async, generics, params, returnType, JSDoc, singleLine, children }) {
297
276
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
298
277
  (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", {})] }),
299
- canExport && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: ["export", /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Space, {})] }),
300
- isDefault && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: ["default", /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Space, {})] }),
278
+ canExport && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: "export " }),
279
+ isDefault && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: "default " }),
301
280
  "const ",
302
281
  name,
303
- " =",
304
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Space, {}),
305
- async && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: ["async", /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Space, {})] }),
282
+ " = ",
283
+ async && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: "async " }),
306
284
  generics && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
307
285
  "<",
308
286
  Array.isArray(generics) ? generics.join(", ").trim() : generics,
@@ -345,7 +323,7 @@ function Type({ name, export: canExport, JSDoc, children }) {
345
323
  if (name.charAt(0).toUpperCase() !== name.charAt(0)) throw new Error("Name should start with a capital letter(see TypeScript types)");
346
324
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
347
325
  (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", {})] }),
348
- canExport && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: ["export", /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Space, {})] }),
326
+ canExport && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: "export " }),
349
327
  "type ",
350
328
  name,
351
329
  " = ",
@@ -388,8 +366,10 @@ const createNode = (nodeName) => {
388
366
  };
389
367
  const appendChildNode = (node, childNode) => {
390
368
  if (childNode.parentNode) removeChildNode(childNode.parentNode, childNode);
391
- childNode.parentNode = node;
392
- node.childNodes.push(childNode);
369
+ if (node.nodeName !== "#text") {
370
+ childNode.parentNode = node;
371
+ node.childNodes.push(childNode);
372
+ }
393
373
  };
394
374
  const insertBeforeNode = (node, newChildNode, beforeChildNode) => {
395
375
  if (newChildNode.parentNode) removeChildNode(newChildNode.parentNode, newChildNode);
@@ -15618,15 +15598,15 @@ function _classPrivateFieldSet2(s, a, r) {
15618
15598
  //#endregion
15619
15599
  //#region src/ReactTemplate.tsx
15620
15600
  var import_constants = /* @__PURE__ */ require_react$1.__toESM(require_constants());
15621
- var _options = /* @__PURE__ */ new WeakMap();
15601
+ var _context = /* @__PURE__ */ new WeakMap();
15622
15602
  var _isUnmounted = /* @__PURE__ */ new WeakMap();
15623
15603
  var _container = /* @__PURE__ */ new WeakMap();
15624
15604
  var _rootNode = /* @__PURE__ */ new WeakMap();
15625
15605
  var _ReactTemplate_brand = /* @__PURE__ */ new WeakSet();
15626
15606
  var ReactTemplate = class {
15627
- constructor(options) {
15607
+ constructor(context) {
15628
15608
  _classPrivateMethodInitSpec(this, _ReactTemplate_brand);
15629
- _classPrivateFieldInitSpec(this, _options, void 0);
15609
+ _classPrivateFieldInitSpec(this, _context, void 0);
15630
15610
  _classPrivateFieldInitSpec(this, _isUnmounted, void 0);
15631
15611
  _defineProperty(this, "exitPromise", void 0);
15632
15612
  _classPrivateFieldInitSpec(this, _container, void 0);
@@ -15635,22 +15615,23 @@ var ReactTemplate = class {
15635
15615
  _defineProperty(this, "rejectExitPromise", () => {});
15636
15616
  _defineProperty(this, "unsubscribeExit", () => {});
15637
15617
  _defineProperty(this, "onRender", async () => {
15618
+ var _classPrivateFieldGet2$1, _classPrivateFieldGet3, _classPrivateFieldGet4, _classPrivateFieldGet5;
15638
15619
  if (_classPrivateFieldGet2(_isUnmounted, this)) return;
15639
- _classPrivateFieldGet2(_options, this).context.clear();
15640
- processFiles(_classPrivateFieldGet2(_rootNode, this), _classPrivateFieldGet2(_options, this).context);
15641
- if (!_classPrivateFieldGet2(_options, this).debug && !_classPrivateFieldGet2(_options, this).stdout) return;
15642
- const output = await _assertClassBrand(_ReactTemplate_brand, this, _getOutput).call(this, _classPrivateFieldGet2(_rootNode, this), _classPrivateFieldGet2(_options, this).context);
15643
- if (_classPrivateFieldGet2(_options, this).debug) {
15620
+ _classPrivateFieldGet2(_context, this).clear();
15621
+ processFiles(_classPrivateFieldGet2(_rootNode, this), _classPrivateFieldGet2(_context, this));
15622
+ 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;
15623
+ const output = await _assertClassBrand(_ReactTemplate_brand, this, _getOutput).call(this, _classPrivateFieldGet2(_rootNode, this), _classPrivateFieldGet2(_context, this));
15624
+ if ((_classPrivateFieldGet4 = _classPrivateFieldGet2(_context, this).options) === null || _classPrivateFieldGet4 === void 0 ? void 0 : _classPrivateFieldGet4.debug) {
15644
15625
  console.log("Rendering: \n");
15645
15626
  console.log(output);
15646
15627
  }
15647
- if (_classPrivateFieldGet2(_options, this).stdout) {
15648
- _classPrivateFieldGet2(_options, this).stdout.clearLine(0);
15649
- _classPrivateFieldGet2(_options, this).stdout.cursorTo(0);
15650
- _classPrivateFieldGet2(_options, this).stdout.write(output);
15628
+ if (((_classPrivateFieldGet5 = _classPrivateFieldGet2(_context, this).options) === null || _classPrivateFieldGet5 === void 0 ? void 0 : _classPrivateFieldGet5.stdout) && node_process.default.env.NODE_ENV !== "test") {
15629
+ _classPrivateFieldGet2(_context, this).options.stdout.clearLine(0);
15630
+ _classPrivateFieldGet2(_context, this).options.stdout.cursorTo(0);
15631
+ _classPrivateFieldGet2(_context, this).options.stdout.write(output);
15651
15632
  }
15652
15633
  });
15653
- _classPrivateFieldSet2(_options, this, { ...options });
15634
+ _classPrivateFieldSet2(_context, this, context);
15654
15635
  _classPrivateFieldSet2(_rootNode, this, createNode("kubb-root"));
15655
15636
  _classPrivateFieldGet2(_rootNode, this).onRender = this.onRender;
15656
15637
  _classPrivateFieldGet2(_rootNode, this).onImmediateRender = this.onRender;
@@ -15692,9 +15673,8 @@ var ReactTemplate = class {
15692
15673
  onExit(error) {
15693
15674
  this.unmount(error);
15694
15675
  }
15695
- render(node, { meta = {} } = { meta: {} }) {
15676
+ render(node) {
15696
15677
  const element = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Root, {
15697
- meta,
15698
15678
  onExit: this.onExit.bind(this),
15699
15679
  onError: this.onError.bind(this),
15700
15680
  children: node
@@ -15702,21 +15682,21 @@ var ReactTemplate = class {
15702
15682
  KubbRenderer.updateContainerSync(element, _classPrivateFieldGet2(_container, this), null, null);
15703
15683
  KubbRenderer.flushSyncWork();
15704
15684
  }
15705
- async renderToString(node, { meta = {} } = { meta: {} }) {
15685
+ async renderToString(node) {
15706
15686
  const element = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Root, {
15707
- meta,
15708
15687
  onExit: this.onExit.bind(this),
15709
15688
  onError: this.onError.bind(this),
15710
15689
  children: node
15711
15690
  });
15712
15691
  KubbRenderer.updateContainerSync(element, _classPrivateFieldGet2(_container, this), null, null);
15713
15692
  KubbRenderer.flushSyncWork();
15714
- _classPrivateFieldGet2(_options, this).context.clear();
15715
- return _assertClassBrand(_ReactTemplate_brand, this, _getOutput).call(this, _classPrivateFieldGet2(_rootNode, this), _classPrivateFieldGet2(_options, this).context);
15693
+ _classPrivateFieldGet2(_context, this).clear();
15694
+ return _assertClassBrand(_ReactTemplate_brand, this, _getOutput).call(this, _classPrivateFieldGet2(_rootNode, this), _classPrivateFieldGet2(_context, this));
15716
15695
  }
15717
15696
  unmount(error) {
15697
+ var _classPrivateFieldGet6;
15718
15698
  if (_classPrivateFieldGet2(_isUnmounted, this)) return;
15719
- if (_classPrivateFieldGet2(_options, this).debug) console.log("Unmount", error);
15699
+ if ((_classPrivateFieldGet6 = _classPrivateFieldGet2(_context, this).options) === null || _classPrivateFieldGet6 === void 0 ? void 0 : _classPrivateFieldGet6.debug) console.log("Unmount", error);
15720
15700
  this.onRender();
15721
15701
  this.unsubscribeExit();
15722
15702
  _classPrivateFieldSet2(_isUnmounted, this, true);
@@ -15744,18 +15724,13 @@ async function _getOutput(node, context) {
15744
15724
  //#endregion
15745
15725
  //#region src/createApp.ts
15746
15726
  const createApp = (0, __kubb_fabric_core.defineApp)((app, context) => {
15747
- const template = node_process.default.env.NODE_ENV === "test" ? new ReactTemplate({ context }) : new ReactTemplate({
15748
- context,
15749
- stdout: node_process.default.stdout,
15750
- stderr: node_process.default.stderr,
15751
- stdin: node_process.default.stdin
15752
- });
15727
+ const template = new ReactTemplate(context);
15753
15728
  return {
15754
15729
  render() {
15755
- template.render(createElement(app));
15730
+ template.render((0, import_react.createElement)(app));
15756
15731
  },
15757
15732
  async renderToString() {
15758
- return template.renderToString(createElement(app));
15733
+ return template.renderToString((0, import_react.createElement)(app));
15759
15734
  },
15760
15735
  waitUntilExit() {
15761
15736
  return template.waitUntilExit();
@@ -15764,7 +15739,7 @@ const createApp = (0, __kubb_fabric_core.defineApp)((app, context) => {
15764
15739
  });
15765
15740
 
15766
15741
  //#endregion
15767
- //#region src/hooks/useApp.ts
15742
+ //#region src/composables/useApp.ts
15768
15743
  /**
15769
15744
  * `useApp` will return the current App with plugin, pluginManager, fileManager and mode.
15770
15745
  */
@@ -15775,7 +15750,7 @@ function useApp() {
15775
15750
  }
15776
15751
 
15777
15752
  //#endregion
15778
- //#region src/hooks/useFile.ts
15753
+ //#region src/composables/useFile.ts
15779
15754
  /**
15780
15755
  * `useFile` will return the current file when <File/> is used.
15781
15756
  */
@@ -15784,7 +15759,7 @@ function useFile() {
15784
15759
  }
15785
15760
 
15786
15761
  //#endregion
15787
- //#region src/hooks/useLifecycle.tsx
15762
+ //#region src/composables/useLifecycle.tsx
15788
15763
  /**
15789
15764
  * `useLifecycle` will return some helpers to exit/restart the generation.
15790
15765
  */
@@ -15929,7 +15904,6 @@ exports.File = File;
15929
15904
  exports.Function = Function;
15930
15905
  exports.FunctionParams = FunctionParams;
15931
15906
  exports.Indent = Indent;
15932
- exports.Text = Text;
15933
15907
  exports.Type = Type;
15934
15908
  exports.createApp = createApp;
15935
15909
  exports.createContext = createContext;