@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 +35 -48
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +37 -51
- package/dist/index.mjs.map +1 -1
- package/package.json +15 -15
package/dist/index.mjs
CHANGED
@@ -3,12 +3,11 @@ var __name = (target, value) => __defProp(target, "name", { value, configurable:
|
|
3
3
|
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
4
4
|
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
5
5
|
}) : x)(function(x) {
|
6
|
-
if (typeof require !== "undefined")
|
7
|
-
return require.apply(this, arguments);
|
6
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
8
7
|
throw Error('Dynamic require of "' + x + '" is not supported');
|
9
8
|
});
|
10
9
|
|
11
|
-
// ../../../../node_modules/.pnpm/tsup@8.
|
10
|
+
// ../../../../node_modules/.pnpm/tsup@8.2.4_@microsoft+api-extractor@7.43.8_@types+node@20.16.1__@swc+core@1.3.57_@swc+helpers_ww5ypu3n2haukmlxcrky22ydmq/node_modules/tsup/assets/esm_shims.js
|
12
11
|
import { fileURLToPath } from "url";
|
13
12
|
import path from "path";
|
14
13
|
var getFilename = /* @__PURE__ */ __name(() => fileURLToPath(import.meta.url), "getFilename");
|
@@ -163,8 +162,7 @@ function extractSpecFromTypeScriptInfo({
|
|
163
162
|
exportName
|
164
163
|
}) {
|
165
164
|
try {
|
166
|
-
if (!results)
|
167
|
-
return false;
|
165
|
+
if (!results) return false;
|
168
166
|
const spec = {
|
169
167
|
props: {
|
170
168
|
$schema: "http://json-schema.org/draft-07/schema",
|
@@ -180,8 +178,7 @@ function extractSpecFromTypeScriptInfo({
|
|
180
178
|
};
|
181
179
|
const isDefaultExport = !exportName || exportName === "default";
|
182
180
|
const result = isDefaultExport ? results.pop() : results.find((r) => r.displayName === exportName);
|
183
|
-
if (!result)
|
184
|
-
return false;
|
181
|
+
if (!result) return false;
|
185
182
|
const { displayName } = result;
|
186
183
|
Object.entries(result?.props || {}).forEach(([propName, propDef]) => {
|
187
184
|
const { name, description, defaultValue, required, type, parent } = propDef;
|
@@ -266,8 +263,7 @@ function extractSpecFromTypeScriptInfo({
|
|
266
263
|
}
|
267
264
|
}
|
268
265
|
if (spec.props.properties[propName]) {
|
269
|
-
if (required)
|
270
|
-
spec.props.required.push(propName);
|
266
|
+
if (required) spec.props.required.push(propName);
|
271
267
|
if (description && !spec.props.properties[propName].description) {
|
272
268
|
spec.props.properties[propName].description = description;
|
273
269
|
}
|
@@ -354,8 +350,7 @@ function extractSpecFromPropTypesInfo({
|
|
354
350
|
};
|
355
351
|
}
|
356
352
|
if (spec.props.properties[propName]) {
|
357
|
-
if (required)
|
358
|
-
spec.props.required.push(propName);
|
353
|
+
if (required) spec.props.required.push(propName);
|
359
354
|
if (description && !spec.props.properties[propName].description) {
|
360
355
|
spec.props.properties[propName].description = description;
|
361
356
|
}
|
@@ -381,8 +376,7 @@ __name(extractSpecFromPropTypesInfo, "extractSpecFromPropTypesInfo");
|
|
381
376
|
function cleanUpSpec({
|
382
377
|
spec
|
383
378
|
}) {
|
384
|
-
if (spec === false)
|
385
|
-
return spec;
|
379
|
+
if (spec === false) return spec;
|
386
380
|
Object.entries(spec?.props?.properties || {}).forEach(([propName, prop]) => {
|
387
381
|
if (isOptionsProp(prop)) {
|
388
382
|
if (!prop.enum.includes(prop.default)) {
|
@@ -417,8 +411,7 @@ async function getReactModuleInfoUncached({
|
|
417
411
|
path: unknownSrc,
|
418
412
|
resolveFromDir
|
419
413
|
});
|
420
|
-
if (!jsInfo.exists)
|
421
|
-
return { type: "unknown" };
|
414
|
+
if (!jsInfo.exists) return { type: "unknown" };
|
422
415
|
const { ext } = path2.parse(jsInfo.absolutePath);
|
423
416
|
switch (ext) {
|
424
417
|
case ".jsx": {
|
@@ -610,7 +603,7 @@ var createReactPattern = createCreator({
|
|
610
603
|
id: "react-patterns",
|
611
604
|
title: "React Ks Patterns",
|
612
605
|
description: "Adds React templates as Knapsack Patterns",
|
613
|
-
getQuestions: async () => ({
|
606
|
+
getQuestions: /* @__PURE__ */ __name(async () => ({
|
614
607
|
pkgPath: {
|
615
608
|
type: "text",
|
616
609
|
title: "Package path"
|
@@ -619,8 +612,8 @@ var createReactPattern = createCreator({
|
|
619
612
|
type: "text",
|
620
613
|
title: "Import Prefix to Remove"
|
621
614
|
}
|
622
|
-
}),
|
623
|
-
getTasks: async ({ answers: { pkgPath, importPrefix = "" }, config }) => {
|
615
|
+
}), "getQuestions"),
|
616
|
+
getTasks: /* @__PURE__ */ __name(async ({ answers: { pkgPath, importPrefix = "" }, config }) => {
|
624
617
|
const dataDir = config.dest;
|
625
618
|
const currentPatterns = await readKsPatternConfigs({
|
626
619
|
dataDir
|
@@ -639,12 +632,12 @@ var createReactPattern = createCreator({
|
|
639
632
|
return [
|
640
633
|
{
|
641
634
|
title: "Pick Imports to add",
|
642
|
-
task: (_, task) => tasks.runSubCreator({
|
635
|
+
task: /* @__PURE__ */ __name((_, task) => tasks.runSubCreator({
|
643
636
|
task,
|
644
637
|
config,
|
645
638
|
creator: createCreator({
|
646
639
|
id: "react-pattern-import-names",
|
647
|
-
getQuestions: async () => ({
|
640
|
+
getQuestions: /* @__PURE__ */ __name(async () => ({
|
648
641
|
importNames: {
|
649
642
|
type: "choices",
|
650
643
|
choices: allImports.filter(
|
@@ -653,8 +646,8 @@ var createReactPattern = createCreator({
|
|
653
646
|
value: importName
|
654
647
|
}))
|
655
648
|
}
|
656
|
-
}),
|
657
|
-
getTasks: async ({ answers: { importNames } }) => {
|
649
|
+
}), "getQuestions"),
|
650
|
+
getTasks: /* @__PURE__ */ __name(async ({ answers: { importNames } }) => {
|
658
651
|
const patterns = importNames.map((importName) => ({
|
659
652
|
importName,
|
660
653
|
patternId: importName.startsWith(importPrefix) ? importName.slice(importPrefix.length).toLowerCase() : importName.toLowerCase()
|
@@ -663,7 +656,7 @@ var createReactPattern = createCreator({
|
|
663
656
|
...patterns.map(
|
664
657
|
({ importName, patternId }) => ({
|
665
658
|
title: `Add ${importName} React Template`,
|
666
|
-
task: async (__, subTask) => {
|
659
|
+
task: /* @__PURE__ */ __name(async (__, subTask) => {
|
667
660
|
const initialDemo = {
|
668
661
|
type: "data",
|
669
662
|
id: makeShortId(),
|
@@ -692,23 +685,20 @@ var createReactPattern = createCreator({
|
|
692
685
|
data: pattern
|
693
686
|
})
|
694
687
|
]);
|
695
|
-
}
|
688
|
+
}, "task")
|
696
689
|
})
|
697
690
|
),
|
698
691
|
{
|
699
692
|
title: `Updating Nav`,
|
700
|
-
task: async (__, subTask) => {
|
693
|
+
task: /* @__PURE__ */ __name(async (__, subTask) => {
|
701
694
|
const { byId } = await readKsNavConfig({
|
702
695
|
dataDir
|
703
696
|
});
|
704
697
|
const componentsGroup = Object.values(byId).find(
|
705
698
|
({ path: path3, name, id }) => {
|
706
|
-
if (path3)
|
707
|
-
|
708
|
-
if (name.toLowerCase() === "
|
709
|
-
return true;
|
710
|
-
if (name.toLowerCase() === "components")
|
711
|
-
return true;
|
699
|
+
if (path3) return false;
|
700
|
+
if (name.toLowerCase() === "patterns") return true;
|
701
|
+
if (name.toLowerCase() === "components") return true;
|
712
702
|
return false;
|
713
703
|
}
|
714
704
|
);
|
@@ -720,15 +710,15 @@ var createReactPattern = createCreator({
|
|
720
710
|
navParent: componentsGroup?.id || "root"
|
721
711
|
}))
|
722
712
|
});
|
723
|
-
}
|
713
|
+
}, "task")
|
724
714
|
}
|
725
715
|
];
|
726
|
-
}
|
716
|
+
}, "getTasks")
|
727
717
|
})
|
728
|
-
})
|
718
|
+
}), "task")
|
729
719
|
}
|
730
720
|
];
|
731
|
-
}
|
721
|
+
}, "getTasks")
|
732
722
|
});
|
733
723
|
|
734
724
|
// src/renderer-react.ts
|
@@ -774,7 +764,7 @@ var KnapsackReactRenderer = class _KnapsackReactRenderer extends KnapsackRendere
|
|
774
764
|
);
|
775
765
|
}
|
776
766
|
}
|
777
|
-
getMeta = () => ({
|
767
|
+
getMeta = /* @__PURE__ */ __name(() => ({
|
778
768
|
id: this.id,
|
779
769
|
title: "React",
|
780
770
|
aliasUse: "optional",
|
@@ -802,7 +792,7 @@ var KnapsackReactRenderer = class _KnapsackReactRenderer extends KnapsackRendere
|
|
802
792
|
}
|
803
793
|
}
|
804
794
|
}
|
805
|
-
});
|
795
|
+
}), "getMeta");
|
806
796
|
changeCase(str) {
|
807
797
|
return pascalCase(str);
|
808
798
|
}
|
@@ -1098,10 +1088,8 @@ ${errorHtmlMsg}
|
|
1098
1088
|
const slotItemsUsages = await Promise.all(
|
1099
1089
|
slotItems.filter((slotItem) => {
|
1100
1090
|
if (!isSlottedText(slotItem)) {
|
1101
|
-
if (!slotItem.patternId)
|
1102
|
-
|
1103
|
-
if (!slotItem.templateId)
|
1104
|
-
return false;
|
1091
|
+
if (!slotItem.patternId) return false;
|
1092
|
+
if (!slotItem.templateId) return false;
|
1105
1093
|
if (isSlottedTemplateDemo(slotItem) && !slotItem.demoId) {
|
1106
1094
|
return false;
|
1107
1095
|
}
|
@@ -1249,7 +1237,7 @@ ${errorHtmlMsg}
|
|
1249
1237
|
const { usage } = await this.getUsageAndImports(opt);
|
1250
1238
|
return usage;
|
1251
1239
|
}
|
1252
|
-
inferSpec = async ({
|
1240
|
+
inferSpec = /* @__PURE__ */ __name(async ({
|
1253
1241
|
template,
|
1254
1242
|
templatePath
|
1255
1243
|
}) => {
|
@@ -1266,14 +1254,14 @@ ${errorHtmlMsg}
|
|
1266
1254
|
}
|
1267
1255
|
}
|
1268
1256
|
return spec;
|
1269
|
-
};
|
1257
|
+
}, "inferSpec");
|
1270
1258
|
async watch(opt) {
|
1271
1259
|
await super.watch(opt);
|
1272
1260
|
knapsackEvents.onPatternTemplateChanged(() => {
|
1273
1261
|
clearInferSpecCache();
|
1274
1262
|
});
|
1275
1263
|
}
|
1276
|
-
getTemplateMeta = async ({
|
1264
|
+
getTemplateMeta = /* @__PURE__ */ __name(async ({
|
1277
1265
|
pattern,
|
1278
1266
|
template
|
1279
1267
|
}) => {
|
@@ -1290,8 +1278,7 @@ ${errorHtmlMsg}
|
|
1290
1278
|
)}` : info.description
|
1291
1279
|
};
|
1292
1280
|
schema.required = schema.required ?? [];
|
1293
|
-
if (info.isRequired)
|
1294
|
-
schema.required.push(id);
|
1281
|
+
if (info.isRequired) schema.required.push(id);
|
1295
1282
|
});
|
1296
1283
|
}
|
1297
1284
|
const typeDefs = await _KnapsackReactRenderer.convertSchemaToTypeScriptDefs({
|
@@ -1315,8 +1302,8 @@ ${errorHtmlMsg}
|
|
1315
1302
|
});
|
1316
1303
|
}
|
1317
1304
|
return files;
|
1318
|
-
};
|
1319
|
-
alterTemplateMetaFiles = async ({ files, metaDir }) => {
|
1305
|
+
}, "getTemplateMeta");
|
1306
|
+
alterTemplateMetaFiles = /* @__PURE__ */ __name(async ({ files, metaDir }) => {
|
1320
1307
|
const imports = [];
|
1321
1308
|
const ext = ".spec.d.ts";
|
1322
1309
|
files.forEach((file) => {
|
@@ -1342,7 +1329,7 @@ ${errorHtmlMsg}
|
|
1342
1329
|
path: join(metaDir, "react.d.ts")
|
1343
1330
|
}
|
1344
1331
|
];
|
1345
|
-
};
|
1332
|
+
}, "alterTemplateMetaFiles");
|
1346
1333
|
async getTemplateSuggestions({
|
1347
1334
|
newPath
|
1348
1335
|
}) {
|
@@ -1362,8 +1349,7 @@ ${errorHtmlMsg}
|
|
1362
1349
|
];
|
1363
1350
|
const allSuggestions = await Promise.all(
|
1364
1351
|
allPaths.map(async (path3) => {
|
1365
|
-
if (!path3)
|
1366
|
-
return [];
|
1352
|
+
if (!path3) return [];
|
1367
1353
|
try {
|
1368
1354
|
const { exports, errorMsg } = await getJsExportNames2({
|
1369
1355
|
path: path3,
|