@knapsack/renderer-react 4.68.5 → 4.68.6--canary.4549.dbe7f16.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.
package/dist/index.js CHANGED
@@ -164,8 +164,7 @@ function extractSpecFromTypeScriptInfo({
164
164
  exportName
165
165
  }) {
166
166
  try {
167
- if (!results)
168
- return false;
167
+ if (!results) return false;
169
168
  const spec = {
170
169
  props: {
171
170
  $schema: "http://json-schema.org/draft-07/schema",
@@ -181,8 +180,7 @@ function extractSpecFromTypeScriptInfo({
181
180
  };
182
181
  const isDefaultExport = !exportName || exportName === "default";
183
182
  const result = isDefaultExport ? results.pop() : results.find((r) => r.displayName === exportName);
184
- if (!result)
185
- return false;
183
+ if (!result) return false;
186
184
  const { displayName } = result;
187
185
  Object.entries(result?.props || {}).forEach(([propName, propDef]) => {
188
186
  const { name, description, defaultValue, required, type, parent } = propDef;
@@ -267,8 +265,7 @@ function extractSpecFromTypeScriptInfo({
267
265
  }
268
266
  }
269
267
  if (spec.props.properties[propName]) {
270
- if (required)
271
- spec.props.required.push(propName);
268
+ if (required) spec.props.required.push(propName);
272
269
  if (description && !spec.props.properties[propName].description) {
273
270
  spec.props.properties[propName].description = description;
274
271
  }
@@ -355,8 +352,7 @@ function extractSpecFromPropTypesInfo({
355
352
  };
356
353
  }
357
354
  if (spec.props.properties[propName]) {
358
- if (required)
359
- spec.props.required.push(propName);
355
+ if (required) spec.props.required.push(propName);
360
356
  if (description && !spec.props.properties[propName].description) {
361
357
  spec.props.properties[propName].description = description;
362
358
  }
@@ -382,8 +378,7 @@ __name(extractSpecFromPropTypesInfo, "extractSpecFromPropTypesInfo");
382
378
  function cleanUpSpec({
383
379
  spec
384
380
  }) {
385
- if (spec === false)
386
- return spec;
381
+ if (spec === false) return spec;
387
382
  Object.entries(spec?.props?.properties || {}).forEach(([propName, prop]) => {
388
383
  if ((0, import_types.isOptionsProp)(prop)) {
389
384
  if (!prop.enum.includes(prop.default)) {
@@ -418,8 +413,7 @@ async function getReactModuleInfoUncached({
418
413
  path: unknownSrc,
419
414
  resolveFromDir
420
415
  });
421
- if (!jsInfo.exists)
422
- return { type: "unknown" };
416
+ if (!jsInfo.exists) return { type: "unknown" };
423
417
  const { ext } = import_path.default.parse(jsInfo.absolutePath);
424
418
  switch (ext) {
425
419
  case ".jsx": {
@@ -605,7 +599,7 @@ var createReactPattern = (0, import_creator_utils.createCreator)({
605
599
  id: "react-patterns",
606
600
  title: "React Ks Patterns",
607
601
  description: "Adds React templates as Knapsack Patterns",
608
- getQuestions: async () => ({
602
+ getQuestions: /* @__PURE__ */ __name(async () => ({
609
603
  pkgPath: {
610
604
  type: "text",
611
605
  title: "Package path"
@@ -614,8 +608,8 @@ var createReactPattern = (0, import_creator_utils.createCreator)({
614
608
  type: "text",
615
609
  title: "Import Prefix to Remove"
616
610
  }
617
- }),
618
- getTasks: async ({ answers: { pkgPath, importPrefix = "" }, config }) => {
611
+ }), "getQuestions"),
612
+ getTasks: /* @__PURE__ */ __name(async ({ answers: { pkgPath, importPrefix = "" }, config }) => {
619
613
  const dataDir = config.dest;
620
614
  const currentPatterns = await (0, import_ks_file_utils.readKsPatternConfigs)({
621
615
  dataDir
@@ -634,12 +628,12 @@ var createReactPattern = (0, import_creator_utils.createCreator)({
634
628
  return [
635
629
  {
636
630
  title: "Pick Imports to add",
637
- task: (_, task) => import_creator_utils.tasks.runSubCreator({
631
+ task: /* @__PURE__ */ __name((_, task) => import_creator_utils.tasks.runSubCreator({
638
632
  task,
639
633
  config,
640
634
  creator: (0, import_creator_utils.createCreator)({
641
635
  id: "react-pattern-import-names",
642
- getQuestions: async () => ({
636
+ getQuestions: /* @__PURE__ */ __name(async () => ({
643
637
  importNames: {
644
638
  type: "choices",
645
639
  choices: allImports.filter(
@@ -648,8 +642,8 @@ var createReactPattern = (0, import_creator_utils.createCreator)({
648
642
  value: importName
649
643
  }))
650
644
  }
651
- }),
652
- getTasks: async ({ answers: { importNames } }) => {
645
+ }), "getQuestions"),
646
+ getTasks: /* @__PURE__ */ __name(async ({ answers: { importNames } }) => {
653
647
  const patterns = importNames.map((importName) => ({
654
648
  importName,
655
649
  patternId: importName.startsWith(importPrefix) ? importName.slice(importPrefix.length).toLowerCase() : importName.toLowerCase()
@@ -658,7 +652,7 @@ var createReactPattern = (0, import_creator_utils.createCreator)({
658
652
  ...patterns.map(
659
653
  ({ importName, patternId }) => ({
660
654
  title: `Add ${importName} React Template`,
661
- task: async (__, subTask) => {
655
+ task: /* @__PURE__ */ __name(async (__, subTask) => {
662
656
  const initialDemo = {
663
657
  type: "data",
664
658
  id: (0, import_utils2.makeShortId)(),
@@ -687,23 +681,20 @@ var createReactPattern = (0, import_creator_utils.createCreator)({
687
681
  data: pattern
688
682
  })
689
683
  ]);
690
- }
684
+ }, "task")
691
685
  })
692
686
  ),
693
687
  {
694
688
  title: `Updating Nav`,
695
- task: async (__, subTask) => {
689
+ task: /* @__PURE__ */ __name(async (__, subTask) => {
696
690
  const { byId } = await (0, import_ks_file_utils.readKsNavConfig)({
697
691
  dataDir
698
692
  });
699
693
  const componentsGroup = Object.values(byId).find(
700
694
  ({ path: path2, name, id }) => {
701
- if (path2)
702
- return false;
703
- if (name.toLowerCase() === "patterns")
704
- return true;
705
- if (name.toLowerCase() === "components")
706
- return true;
695
+ if (path2) return false;
696
+ if (name.toLowerCase() === "patterns") return true;
697
+ if (name.toLowerCase() === "components") return true;
707
698
  return false;
708
699
  }
709
700
  );
@@ -715,15 +706,15 @@ var createReactPattern = (0, import_creator_utils.createCreator)({
715
706
  navParent: componentsGroup?.id || "root"
716
707
  }))
717
708
  });
718
- }
709
+ }, "task")
719
710
  }
720
711
  ];
721
- }
712
+ }, "getTasks")
722
713
  })
723
- })
714
+ }), "task")
724
715
  }
725
716
  ];
726
- }
717
+ }, "getTasks")
727
718
  });
728
719
 
729
720
  // src/renderer-react.ts
@@ -769,7 +760,7 @@ var KnapsackReactRenderer = class _KnapsackReactRenderer extends import_renderer
769
760
  );
770
761
  }
771
762
  }
772
- getMeta = () => ({
763
+ getMeta = /* @__PURE__ */ __name(() => ({
773
764
  id: this.id,
774
765
  title: "React",
775
766
  aliasUse: "optional",
@@ -797,7 +788,7 @@ var KnapsackReactRenderer = class _KnapsackReactRenderer extends import_renderer
797
788
  }
798
789
  }
799
790
  }
800
- });
791
+ }), "getMeta");
801
792
  changeCase(str) {
802
793
  return (0, import_utils3.pascalCase)(str);
803
794
  }
@@ -1093,10 +1084,8 @@ ${errorHtmlMsg}
1093
1084
  const slotItemsUsages = await Promise.all(
1094
1085
  slotItems.filter((slotItem) => {
1095
1086
  if (!(0, import_types2.isSlottedText)(slotItem)) {
1096
- if (!slotItem.patternId)
1097
- return false;
1098
- if (!slotItem.templateId)
1099
- return false;
1087
+ if (!slotItem.patternId) return false;
1088
+ if (!slotItem.templateId) return false;
1100
1089
  if ((0, import_types2.isSlottedTemplateDemo)(slotItem) && !slotItem.demoId) {
1101
1090
  return false;
1102
1091
  }
@@ -1244,7 +1233,7 @@ ${errorHtmlMsg}
1244
1233
  const { usage } = await this.getUsageAndImports(opt);
1245
1234
  return usage;
1246
1235
  }
1247
- inferSpec = async ({
1236
+ inferSpec = /* @__PURE__ */ __name(async ({
1248
1237
  template,
1249
1238
  templatePath
1250
1239
  }) => {
@@ -1261,14 +1250,14 @@ ${errorHtmlMsg}
1261
1250
  }
1262
1251
  }
1263
1252
  return spec;
1264
- };
1253
+ }, "inferSpec");
1265
1254
  async watch(opt) {
1266
1255
  await super.watch(opt);
1267
1256
  import_app2.knapsackEvents.onPatternTemplateChanged(() => {
1268
1257
  clearInferSpecCache();
1269
1258
  });
1270
1259
  }
1271
- getTemplateMeta = async ({
1260
+ getTemplateMeta = /* @__PURE__ */ __name(async ({
1272
1261
  pattern,
1273
1262
  template
1274
1263
  }) => {
@@ -1285,8 +1274,7 @@ ${errorHtmlMsg}
1285
1274
  )}` : info.description
1286
1275
  };
1287
1276
  schema.required = schema.required ?? [];
1288
- if (info.isRequired)
1289
- schema.required.push(id);
1277
+ if (info.isRequired) schema.required.push(id);
1290
1278
  });
1291
1279
  }
1292
1280
  const typeDefs = await _KnapsackReactRenderer.convertSchemaToTypeScriptDefs({
@@ -1310,8 +1298,8 @@ ${errorHtmlMsg}
1310
1298
  });
1311
1299
  }
1312
1300
  return files;
1313
- };
1314
- alterTemplateMetaFiles = async ({ files, metaDir }) => {
1301
+ }, "getTemplateMeta");
1302
+ alterTemplateMetaFiles = /* @__PURE__ */ __name(async ({ files, metaDir }) => {
1315
1303
  const imports = [];
1316
1304
  const ext = ".spec.d.ts";
1317
1305
  files.forEach((file) => {
@@ -1337,7 +1325,7 @@ ${errorHtmlMsg}
1337
1325
  path: (0, import_path2.join)(metaDir, "react.d.ts")
1338
1326
  }
1339
1327
  ];
1340
- };
1328
+ }, "alterTemplateMetaFiles");
1341
1329
  async getTemplateSuggestions({
1342
1330
  newPath
1343
1331
  }) {
@@ -1357,8 +1345,7 @@ ${errorHtmlMsg}
1357
1345
  ];
1358
1346
  const allSuggestions = await Promise.all(
1359
1347
  allPaths.map(async (path2) => {
1360
- if (!path2)
1361
- return [];
1348
+ if (!path2) return [];
1362
1349
  try {
1363
1350
  const { exports: exports2, errorMsg } = await (0, import_file_utils3.getJsExportNames)({
1364
1351
  path: path2,