@knapsack/renderer-react 4.71.15 → 4.71.16--canary.5224.facfa79.0
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +0 -29
- package/ava.config.cjs +7 -1
- package/dist/analyze/infer-spec.test.d.ts +2 -0
- package/dist/analyze/infer-spec.test.d.ts.map +1 -0
- package/dist/analyze/infer-spec.test.js +112 -0
- package/dist/analyze/infer-spec.test.js.map +1 -0
- package/dist/analyze/mui.test.d.ts +2 -0
- package/dist/analyze/mui.test.d.ts.map +1 -0
- package/dist/analyze/mui.test.js +60 -0
- package/dist/analyze/mui.test.js.map +1 -0
- package/dist/analyze/pkg-basic.test.d.ts +2 -0
- package/dist/analyze/pkg-basic.test.d.ts.map +1 -0
- package/dist/analyze/pkg-basic.test.js +33 -0
- package/dist/analyze/pkg-basic.test.js.map +1 -0
- package/dist/analyze/pkg-diff-types.test.d.ts +2 -0
- package/dist/analyze/pkg-diff-types.test.d.ts.map +1 -0
- package/dist/analyze/pkg-diff-types.test.js +43 -0
- package/dist/analyze/pkg-diff-types.test.js.map +1 -0
- package/dist/client/init.d.mts +2 -2
- package/dist/client/init.d.mts.map +1 -0
- package/dist/client/init.mjs +39 -3
- package/dist/client/init.mjs.map +1 -1
- package/dist/index.d.ts +3 -45
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +16 -31
- package/dist/index.js.map +1 -1
- package/dist/react-creators.d.ts +20 -0
- package/dist/react-creators.d.ts.map +1 -0
- package/dist/react-creators.js +170 -0
- package/dist/react-creators.js.map +1 -0
- package/dist/{index.d.mts → renderer-react.d.ts} +2 -5
- package/dist/renderer-react.d.ts.map +1 -0
- package/dist/renderer-react.js +569 -0
- package/dist/renderer-react.js.map +1 -0
- package/dist/types.d.ts +19 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +5 -0
- package/dist/types.js.map +1 -0
- package/dist/utils.d.ts +28 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +500 -0
- package/dist/utils.js.map +1 -0
- package/dist/utils.test.d.ts +2 -0
- package/dist/utils.test.d.ts.map +1 -0
- package/dist/utils.test.js +59 -0
- package/dist/utils.test.js.map +1 -0
- package/package.json +23 -27
- package/prototype-template.d.mts +3 -0
- package/prototype-template.mjs +3 -0
- package/test-fixtures/pkg-diff-types/button.js +10 -0
- package/test-fixtures/pkg-diff-types/package.json +4 -0
- package/test-fixtures/pkg-diff-types/readme.md +1 -0
- package/test-fixtures/pkg-diff-types/types/button.d.ts +5 -0
- package/tsconfig.json +2 -2
- package/dist/client/init.d.ts +0 -2
- package/dist/client/init.js +0 -5
- package/dist/client/init.js.map +0 -1
- package/dist/demo-wrapper.d.mts +0 -7
- package/dist/demo-wrapper.d.ts +0 -7
- package/dist/demo-wrapper.js +0 -2
- package/dist/demo-wrapper.js.map +0 -1
- package/dist/demo-wrapper.mjs +0 -2
- package/dist/demo-wrapper.mjs.map +0 -1
- package/dist/error-catcher.d.mts +0 -20
- package/dist/error-catcher.d.ts +0 -20
- package/dist/error-catcher.js +0 -2
- package/dist/error-catcher.js.map +0 -1
- package/dist/error-catcher.mjs +0 -2
- package/dist/error-catcher.mjs.map +0 -1
- package/dist/index.mjs +0 -33
- package/dist/index.mjs.map +0 -1
- package/dist/prototype-template.d.mts +0 -7
- package/dist/prototype-template.d.ts +0 -7
- package/dist/prototype-template.js +0 -2
- package/dist/prototype-template.js.map +0 -1
- package/dist/prototype-template.mjs +0 -2
- package/dist/prototype-template.mjs.map +0 -1
- package/dist/types-CivTHEEo.d.mts +0 -10
- package/dist/types-CivTHEEo.d.ts +0 -10
- package/tsup.config.cjs +0 -5
package/CHANGELOG.md
CHANGED
@@ -1,32 +1,3 @@
|
|
1
|
-
# v4.71.13 (Wed Dec 04 2024)
|
2
|
-
|
3
|
-
#### 🐛 Bug Fix
|
4
|
-
|
5
|
-
- Merge branch 'feature/ksp-5777-gsk-sso-issues' into feature/sso-config-via-db ([@EvanLovely](https://github.com/EvanLovely))
|
6
|
-
- Merge branch 'latest' into feature/ksp-5777-gsk-sso-issues ([@illepic](https://github.com/illepic))
|
7
|
-
- Bump version to: v4.71.12 \[skip ci\] ([@KnapsackBot](https://github.com/KnapsackBot))
|
8
|
-
- Update CHANGELOG.md \[skip ci\] ([@KnapsackBot](https://github.com/KnapsackBot))
|
9
|
-
- Bump version to: v4.71.11 \[skip ci\] ([@KnapsackBot](https://github.com/KnapsackBot))
|
10
|
-
|
11
|
-
#### 🏠 Internal
|
12
|
-
|
13
|
-
- refactor Cypress user login [#5225](https://github.com/knapsack-labs/app-monorepo/pull/5225) ([@EvanLovely](https://github.com/EvanLovely))
|
14
|
-
- Update Node.js to v20.18.1 [#5197](https://github.com/knapsack-labs/app-monorepo/pull/5197) ([@renovate[bot]](https://github.com/renovate[bot]))
|
15
|
-
- adds evt handlers for design src logs [#5194](https://github.com/knapsack-labs/app-monorepo/pull/5194) ([@mabry1985](https://github.com/mabry1985))
|
16
|
-
- setup login w popup [#5209](https://github.com/knapsack-labs/app-monorepo/pull/5209) ([@GormanDesign](https://github.com/GormanDesign) [@mabry1985](https://github.com/mabry1985) [@EvanLovely](https://github.com/EvanLovely) [@KnapsackBot](https://github.com/KnapsackBot) [@illepic](https://github.com/illepic))
|
17
|
-
- migrate to new Figma oAuth endpoints and configuration [#5206](https://github.com/knapsack-labs/app-monorepo/pull/5206) ([@mabry1985](https://github.com/mabry1985))
|
18
|
-
|
19
|
-
#### Authors: 6
|
20
|
-
|
21
|
-
- [@renovate[bot]](https://github.com/renovate[bot])
|
22
|
-
- Christopher Bloom ([@illepic](https://github.com/illepic))
|
23
|
-
- Evan Lovely ([@EvanLovely](https://github.com/EvanLovely))
|
24
|
-
- Josh Mabry ([@mabry1985](https://github.com/mabry1985))
|
25
|
-
- KnapsackBot ([@KnapsackBot](https://github.com/KnapsackBot))
|
26
|
-
- Matt Gorman ([@GormanDesign](https://github.com/GormanDesign))
|
27
|
-
|
28
|
-
---
|
29
|
-
|
30
1
|
# v4.71.12 (Thu Nov 21 2024)
|
31
2
|
|
32
3
|
#### 🐛 Bug Fix
|
package/ava.config.cjs
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"infer-spec.test.d.ts","sourceRoot":"","sources":["../../src/analyze/infer-spec.test.ts"],"names":[],"mappings":""}
|
@@ -0,0 +1,112 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
const ava_1 = __importDefault(require("ava"));
|
7
|
+
const types_1 = require("@knapsack/types");
|
8
|
+
const renderers_1 = require("@knapsack/app/renderers");
|
9
|
+
const utils_1 = require("../utils");
|
10
|
+
(0, ava_1.default)('infer types in packages with different files name for types', async (t) => {
|
11
|
+
const spec = await (0, utils_1.getReactDocs)({
|
12
|
+
src: '@knapsack/sandbox-components/react',
|
13
|
+
exportName: 'Button',
|
14
|
+
resolveFromDir: __dirname,
|
15
|
+
});
|
16
|
+
if (spec === false) {
|
17
|
+
t.fail(`Spec could not be inferred`);
|
18
|
+
return;
|
19
|
+
}
|
20
|
+
t.truthy(spec);
|
21
|
+
t.deepEqual(Object.keys(spec.props.properties).sort(), ['label', 'mode', 'size', 'type'].sort());
|
22
|
+
if ((0, types_1.isOptionsProp)(spec.props.properties.size)) {
|
23
|
+
t.deepEqual(spec.props.properties.size.enum, ['small', 'medium', 'large']);
|
24
|
+
}
|
25
|
+
else {
|
26
|
+
t.log(spec.props.properties.size);
|
27
|
+
t.fail(`size prop should be an options prop`);
|
28
|
+
}
|
29
|
+
if ((0, types_1.isOptionsProp)(spec.props.properties.type)) {
|
30
|
+
t.deepEqual(spec.props.properties.type.enum, ['filled', 'outlined']);
|
31
|
+
}
|
32
|
+
else {
|
33
|
+
t.log(spec.props.properties.type);
|
34
|
+
t.fail(`type prop should be an options prop`);
|
35
|
+
}
|
36
|
+
if ((0, types_1.isOptionsProp)(spec.props.properties.mode)) {
|
37
|
+
t.deepEqual(spec.props.properties.mode.enum, [
|
38
|
+
'default',
|
39
|
+
'success',
|
40
|
+
'error',
|
41
|
+
'warning',
|
42
|
+
]);
|
43
|
+
}
|
44
|
+
else {
|
45
|
+
t.log(spec.props.properties.mode);
|
46
|
+
t.fail(`mode prop should be an options prop`);
|
47
|
+
}
|
48
|
+
});
|
49
|
+
(0, ava_1.default)('inferDocs card.tsx with types', async (t) => {
|
50
|
+
const spec = await (0, utils_1.getReactDocs)({
|
51
|
+
src: '@knapsack/renderer-react-components/test-fixtures',
|
52
|
+
exportName: 'Card',
|
53
|
+
resolveFromDir: process.cwd(),
|
54
|
+
});
|
55
|
+
const expectedSpec = {
|
56
|
+
props: {
|
57
|
+
$schema: 'http://json-schema.org/draft-07/schema',
|
58
|
+
type: 'object',
|
59
|
+
required: ['cardBody', 'items'],
|
60
|
+
properties: {
|
61
|
+
textAlign: {
|
62
|
+
type: 'string',
|
63
|
+
enum: ['left', 'center', 'right'],
|
64
|
+
// @todo We lost proper default value when the source switched from `.tsx` to being from a package, which results in analyzing a `.d.ts` files... which doesn't have default values.
|
65
|
+
// default: 'left',
|
66
|
+
default: undefined,
|
67
|
+
},
|
68
|
+
imgSrc: {
|
69
|
+
type: 'string',
|
70
|
+
},
|
71
|
+
isDark: {
|
72
|
+
type: 'boolean',
|
73
|
+
// @todo We lost proper default value when the source switched from `.tsx` to being from a package, which results in analyzing a `.d.ts` files... which doesn't have default values.
|
74
|
+
// default: true,
|
75
|
+
},
|
76
|
+
cardTitle: {
|
77
|
+
type: 'string',
|
78
|
+
},
|
79
|
+
cardSubTitle: {
|
80
|
+
type: 'string',
|
81
|
+
},
|
82
|
+
cardBody: {
|
83
|
+
type: 'string',
|
84
|
+
},
|
85
|
+
handleIt: {
|
86
|
+
typeof: 'function',
|
87
|
+
tsType: '(x: string) => boolean',
|
88
|
+
},
|
89
|
+
items: {
|
90
|
+
tsType: '{ id: string; title: string; description?: string; }[]',
|
91
|
+
},
|
92
|
+
},
|
93
|
+
},
|
94
|
+
slots: {
|
95
|
+
children: {
|
96
|
+
description: 'Goes in footer',
|
97
|
+
title: 'children',
|
98
|
+
},
|
99
|
+
header: {
|
100
|
+
title: 'header',
|
101
|
+
},
|
102
|
+
},
|
103
|
+
};
|
104
|
+
if (spec === false) {
|
105
|
+
t.fail('Spec could not be inferred');
|
106
|
+
return;
|
107
|
+
}
|
108
|
+
const { ok, message } = (0, renderers_1.validateSpec)(spec);
|
109
|
+
t.is(ok, true, message);
|
110
|
+
t.deepEqual(spec, expectedSpec);
|
111
|
+
});
|
112
|
+
//# sourceMappingURL=infer-spec.test.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"infer-spec.test.js","sourceRoot":"","sources":["../../src/analyze/infer-spec.test.ts"],"names":[],"mappings":";;;;;AAAA,8CAAuB;AACvB,2CAAgE;AAChE,uDAAuD;AACvD,oCAAwC;AAExC,IAAA,aAAI,EAAC,6DAA6D,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE;IAC9E,MAAM,IAAI,GAAG,MAAM,IAAA,oBAAY,EAAC;QAC9B,GAAG,EAAE,oCAAoC;QACzC,UAAU,EAAE,QAAQ;QACpB,cAAc,EAAE,SAAS;KAC1B,CAAC,CAAC;IACH,IAAI,IAAI,KAAK,KAAK,EAAE,CAAC;QACnB,CAAC,CAAC,IAAI,CAAC,4BAA4B,CAAC,CAAC;QACrC,OAAO;IACT,CAAC;IAED,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACf,CAAC,CAAC,SAAS,CACT,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,IAAI,EAAE,EACzC,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,IAAI,EAAE,CACzC,CAAC;IACF,IAAI,IAAA,qBAAa,EAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;QAC9C,CA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AAC,CAAC;IAE3C,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;IACxB,CAAC,CAAC,SAAS,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC;AAClC,CAAC,CAAC,CAAC"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"mui.test.d.ts","sourceRoot":"","sources":["../../src/analyze/mui.test.ts"],"names":[],"mappings":""}
|
@@ -0,0 +1,60 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
const ava_1 = __importDefault(require("ava"));
|
7
|
+
const types_1 = require("@knapsack/types");
|
8
|
+
const utils_1 = require("../utils");
|
9
|
+
ava_1.default.serial('MUI strings with extra quotes', async (t) => {
|
10
|
+
const results = await (0, utils_1.getReactDocs)({
|
11
|
+
src: '@mui/x-data-grid',
|
12
|
+
exportName: 'DataGrid',
|
13
|
+
resolveFromDir: process.cwd(),
|
14
|
+
});
|
15
|
+
if (results === false) {
|
16
|
+
t.fail('Could not infer spec');
|
17
|
+
return;
|
18
|
+
}
|
19
|
+
Object.entries(results.props.properties).forEach(([propName, prop]) => {
|
20
|
+
if ((0, types_1.isStringProp)(prop) || (0, types_1.isOptionsProp)(prop)) {
|
21
|
+
if (typeof prop.default === 'string') {
|
22
|
+
t.true(!prop.default.startsWith('"') && !prop.default.endsWith('"'), `prop "${propName}" has a default that should not be quoted: ${prop.default} - ${JSON.stringify(prop)}`);
|
23
|
+
}
|
24
|
+
}
|
25
|
+
if ((0, types_1.isOptionsProp)(prop)) {
|
26
|
+
if (prop.default) {
|
27
|
+
t.true(prop.enum.includes(prop.default), `For prop "${propName}", the default value "${prop.default}" is not in the enum: ${prop.enum}`);
|
28
|
+
}
|
29
|
+
prop.enum.forEach((option) => {
|
30
|
+
t.true(!option.startsWith('"') && !option.endsWith('"'), `option should not be quoted: ${prop.default}`);
|
31
|
+
});
|
32
|
+
}
|
33
|
+
if ((0, types_1.isNumberProp)(prop) && prop.default) {
|
34
|
+
const ok = t.is(typeof prop.default, 'number', `prop "${propName}" default should be a number: ${prop.default}`);
|
35
|
+
if (!ok) {
|
36
|
+
t.log(prop);
|
37
|
+
}
|
38
|
+
}
|
39
|
+
if ((0, types_1.isBooleanProp)(prop) && prop.default) {
|
40
|
+
const ok = t.is(typeof prop.default, 'boolean', `prop "${propName}" should be a boolean: ${prop.default}`);
|
41
|
+
if (!ok) {
|
42
|
+
t.log(prop);
|
43
|
+
}
|
44
|
+
}
|
45
|
+
});
|
46
|
+
});
|
47
|
+
ava_1.default.failing('infer types for MUI Component', async (t) => {
|
48
|
+
const spec = await (0, utils_1.getReactDocs)({
|
49
|
+
src: '@mui/material',
|
50
|
+
exportName: 'Button',
|
51
|
+
resolveFromDir: process.cwd(),
|
52
|
+
});
|
53
|
+
if (spec === false) {
|
54
|
+
t.fail('Spec could not be inferred for MUI Component');
|
55
|
+
}
|
56
|
+
else {
|
57
|
+
t.pass('Spec was successfully inferred for MUI Component');
|
58
|
+
}
|
59
|
+
});
|
60
|
+
//# sourceMappingURL=mui.test.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"mui.test.js","sourceRoot":"","sources":["../../src/analyze/mui.test.ts"],"names":[],"mappings":";;;;;AAAA,8CAAuB;AACvB,2CAKyB;AACzB,oCAAwC;AAExC,aAAI,CAAC,MAAM,CAAC,+BAA+B,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE;IACvD,MAAM,OAAO,GAAG,MAAM,IAAA,oBAAY,EAAC;QACjC,GAAG,EAAE,kBAAkB;QACvB,UAAU,EAAE,UAAU;QACtB,cAAc,EAAE,OAAO,CAAC,GAAG,EAAE;KAC9B,CAAC,CAAC;IACH,IAAI,OAAO,KAAK,KAAK,EAAE,CAAC;QACtB,CAAC,CAAC,IAA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@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
const ava_1 = __importDefault(require("ava"));
|
7
|
+
const types_1 = require("@knapsack/types");
|
8
|
+
const utils_1 = require("../utils");
|
9
|
+
(0, ava_1.default)('infer types in basic packages', async (t) => {
|
10
|
+
const spec = await (0, utils_1.getReactDocs)({
|
11
|
+
src: '@knapsack/renderer-react-components/test-fixtures',
|
12
|
+
exportName: 'Button',
|
13
|
+
resolveFromDir: __dirname,
|
14
|
+
});
|
15
|
+
if (spec === false) {
|
16
|
+
t.fail(`Spec could not be inferred`);
|
17
|
+
return;
|
18
|
+
}
|
19
|
+
t.deepEqual(Object.keys(spec.props.properties).sort(), ['size', 'text'].sort());
|
20
|
+
if (!(0, types_1.isStringProp)(spec.props.properties.text)) {
|
21
|
+
t.log(spec.props.properties.text);
|
22
|
+
t.fail(`text prop should be a string`);
|
23
|
+
return;
|
24
|
+
}
|
25
|
+
if (!(0, types_1.isOptionsProp)(spec.props.properties.size)) {
|
26
|
+
t.log(spec.props.properties.size);
|
27
|
+
t.fail(`size prop should be an options prop`);
|
28
|
+
return;
|
29
|
+
}
|
30
|
+
t.deepEqual(spec.props.properties.size.enum, ['small', 'medium', 'large']);
|
31
|
+
t.is(spec.slots.children.title, 'children', `Should detect "children" slot`);
|
32
|
+
});
|
33
|
+
//# sourceMappingURL=pkg-basic.test.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"pkg-basic.test.js","sourceRoot":"","sources":["../../src/analyze/pkg-basic.test.ts"],"names":[],"mappings":";;;;;AAAA,8CAAuB;AACvB,2CAA8D;AAC9D,oCAAwC;AAExC,IAAA,aAAI,EAAC,+BAA+B,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE;IAChD,MAAM,IAAI,GAAG,MAAM,IAAA,o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":"pkg-diff-types.test.d.ts","sourceRoot":"","sources":["../../src/analyze/pkg-diff-types.test.ts"],"names":[],"mappings":""}
|
@@ -0,0 +1,43 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
const ava_1 = __importDefault(require("ava"));
|
7
|
+
const path_1 = require("path");
|
8
|
+
const types_1 = require("@knapsack/types");
|
9
|
+
const utils_1 = require("../utils");
|
10
|
+
(0, ava_1.default)('infer types in packages with different files name for types', async (t) => {
|
11
|
+
const spec = await (0, utils_1.getReactDocs)({
|
12
|
+
src: (0, path_1.join)(__dirname, '../../test-fixtures/pkg-diff-types'),
|
13
|
+
exportName: 'Button',
|
14
|
+
resolveFromDir: __dirname,
|
15
|
+
});
|
16
|
+
if (spec === false) {
|
17
|
+
t.fail(`Spec could not be inferred`);
|
18
|
+
return;
|
19
|
+
}
|
20
|
+
t.truthy(spec);
|
21
|
+
if (!spec.props) {
|
22
|
+
t.fail(`Spec should have props`);
|
23
|
+
return;
|
24
|
+
}
|
25
|
+
if (!spec.slots) {
|
26
|
+
t.fail(`Spec should have slots`);
|
27
|
+
return;
|
28
|
+
}
|
29
|
+
t.deepEqual(Object.keys(spec.props.properties).sort(), ['size', 'text'].sort());
|
30
|
+
if (!(0, types_1.isStringProp)(spec.props.properties.text)) {
|
31
|
+
t.log(spec.props.properties.text);
|
32
|
+
t.fail(`text prop should be a string`);
|
33
|
+
return;
|
34
|
+
}
|
35
|
+
if (!(0, types_1.isOptionsProp)(spec.props.properties.size)) {
|
36
|
+
t.log(spec.props.properties.size);
|
37
|
+
t.fail(`size prop should be an options prop`);
|
38
|
+
return;
|
39
|
+
}
|
40
|
+
t.deepEqual(spec.props.properties.size.enum, ['small', 'medium', 'large']);
|
41
|
+
t.is(spec.slots.children.title, 'children', `Should detect "children" slot`);
|
42
|
+
});
|
43
|
+
//# sourceMappingURL=pkg-diff-types.test.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"pkg-diff-types.test.js","sourceRoot":"","sources":["../../src/analyze/pkg-diff-types.test.ts"],"names":[],"mappings":";;;;;AAAA,8CAAuB;AACvB,+BAA4B;AAC5B,2CAA8D;AAC9D,oCAAwC;AAExC,IAAA,aAAI,EAAC,6DAA6D,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE;IAC9E,MAAM,IAAI,GAAG,MAAM,IAAA,oBAAY,EAAC;QAC9B,GAAG,EAAE,IAAA,WAAI,EAAC,SAAS,EAAE,oCAAoC,CAAC;QAC1D,UAAU,EAAE,QAAQ;QACpB,cAAc,EAAE,SAAS;KAC1B,CAAC,CAAC;IACH,IAAI,IAAI,KAAK,KAAK,EAAE,CAAC;QACnB,CAAC,CAAC,IAAI,CAAC,4BAA4B,CAAC,CAAC;QACrC,OAAO;IACT,CAAC;IACD,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACf,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;QAChB,CAAC,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAC;QACjC,OAAO;IACT,CAAC;IACD,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;QAChB,CAAC,CAAC,IAAI,CAAC,wBAAwB,CAAC,CAAC;QACjC,OAAO;IACT,CAAC;IACD,CAAC,CAAC,SAAS,CACT,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,IAAI,EAAE,EACzC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,IAAI,EAAE,CACxB,CAAC;IACF,IAAI,CAAC,IAAA,oBAAY,EAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;QAC9C,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;QAClC,CAAC,CAAC,IAAI,CAAC,8BAA8B,CAAC,CAAC;QACvC,OAAO;IACT,CAAC;IACD,IAAI,CAAC,IAAA,qBAAa,EAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;QAC/C,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;QAClC,CAAC,CAAC,IAAI,CAAC,qCAAqC,CAAC,CAAC;QAC9C,OAAO;IACT,CAAC;IACD,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,OAAO,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC;IAC3E,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,EAAE,UAAU,EAAE,+BAA+B,CAAC,CAAC;AAC/E,CAAC,CAAC,CAAC"}
|
package/dist/client/init.d.mts
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
export {};
|
2
|
+
//# sourceMappingURL=init.d.mts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"init.d.mts","sourceRoot":"","sources":["../../src/client/init.mts"],"names":[],"mappings":""}
|
package/dist/client/init.mjs
CHANGED
@@ -1,5 +1,41 @@
|
|
1
|
-
|
1
|
+
/// <reference lib="dom" />
|
2
|
+
import ReactDOM from 'react-dom/client';
|
3
|
+
import { getKsRendererClientUtils } from '@knapsack/renderer-webpack-base/client';
|
4
|
+
import { ReactRendererClientApp } from '@knapsack/renderer-react-components/react-renderer-client-app';
|
5
|
+
import { rendererMetaScriptTagId, } from '../types.js';
|
6
|
+
async function init() {
|
7
|
+
try {
|
8
|
+
const { getNeededImports, getExtraImports, rendererMeta: { disableReactStrictMode, demoWrapperProps }, rendererMethods: { getDemoApp }, } = getKsRendererClientUtils({
|
9
|
+
rendererMetaScriptTagId,
|
10
|
+
});
|
11
|
+
const [neededImports, { DemoWrapper }] = await Promise.all([
|
12
|
+
getNeededImports(),
|
13
|
+
getExtraImports(),
|
14
|
+
]);
|
15
|
+
const root = document.getElementById('render-root');
|
16
|
+
if (!root) {
|
17
|
+
throw new Error('No root element found');
|
18
|
+
}
|
19
|
+
const demoComponents = neededImports;
|
20
|
+
const DemoApp = getDemoApp(demoComponents);
|
21
|
+
const app = ReactRendererClientApp({
|
22
|
+
DemoWrapper,
|
23
|
+
DemoApp,
|
24
|
+
disableReactStrictMode,
|
25
|
+
demoWrapperProps,
|
26
|
+
});
|
27
|
+
ReactDOM.createRoot(root).render(app);
|
28
|
+
}
|
29
|
+
catch (e) {
|
30
|
+
console.error(e);
|
31
|
+
// create html element with error message
|
32
|
+
const errorElement = document.createElement('div');
|
33
|
+
errorElement.innerHTML = `
|
2
34
|
<h1>Error</h1>
|
3
|
-
<p>${
|
4
|
-
|
35
|
+
<p>${e.message}</p>
|
36
|
+
`;
|
37
|
+
document.body.appendChild(errorElement);
|
38
|
+
}
|
39
|
+
}
|
40
|
+
init();
|
5
41
|
//# sourceMappingURL=init.mjs.map
|
package/dist/client/init.mjs.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"file":"init.mjs","sourceRoot":"","sources":["../../src/client/init.mts"],"names":[],"mappings":"AAAA,2BAA2B;AAC3B,OAAO,QAAQ,MAAM,kBAAkB,CAAC;AACxC,OAAO,EAAE,wBAAwB,EAAE,MAAM,wCAAwC,CAAC;AAClF,OAAO,EAAE,sBAAsB,EAAE,MAAM,+DAA+D,CAAC;AACvG,OAAO,EACL,uBAAuB,GAKxB,MAAM,aAAa,CAAC;AAErB,KAAK,UAAU,IAAI;IACjB,IAAI,CAAC;QACH,MAAM,EACJ,gBAAgB,EAChB,eAAe,EACf,YAAY,EAAE,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,EAC1D,eAAe,EAAE,EAAE,UAAU,EAAE,GAChC,GAAG,wBAAwB,CAK1B;YACA,uBAAuB;SACxB,CAAC,CAAC;QACH,MAAM,CAAC,aAAa,EAAE,EAAE,WAAW,EAAE,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;YACzD,gBAAgB,EAAE;YAClB,eAAe,EAAE;SAClB,CAAC,CAAC;QACH,MAAM,IAAI,GAAG,QAAQ,CAAC,cAAc,CAAC,aAAa,CAAC,CAAC;QACpD,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC;QAC3C,CAAC;QACD,MAAM,cAAc,GAAG,aAAa,CAAC;QACrC,MAAM,OAAO,GAAG,UAAU,CAAC,cAAc,CAAC,CAAC;QAC3C,MAAM,GAAG,GAAG,sBAAsB,CAAC;YACjC,WAAW;YACX,OAAO;YACP,sBAAsB;YACtB,gBAAgB;SACjB,CAAC,CAAC;QAEH,QAAQ,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IACxC,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QACjB,yCAAyC;QACzC,MAAM,YAAY,GAAG,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;QACnD,YAAY,CAAC,SAAS,GAAG;;SAEpB,CAAC,CAAC,OAAO;GACf,CAAC;QACA,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC;IAC1C,CAAC;AACH,CAAC;AAED,IAAI,EAAE,CAAC"}
|
package/dist/index.d.ts
CHANGED
@@ -1,45 +1,3 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
export { D as DemoWrapperProps } from './types-CivTHEEo.js';
|
5
|
-
|
6
|
-
declare class KnapsackReactRenderer extends RendererWebpackBase implements Renderable {
|
7
|
-
#private;
|
8
|
-
/**
|
9
|
-
* `react.js` & `react-dom.js` root relative paths
|
10
|
-
*/
|
11
|
-
assets: string[];
|
12
|
-
babelConfig: Record<string, unknown>;
|
13
|
-
constructor({ webpackConfig, demoWrapperPath, id, disableReactStrictMode, }?: {
|
14
|
-
webpackConfig?: ConstructorParameters<typeof RendererWebpackBase>[0]['webpackConfig'];
|
15
|
-
demoWrapperPath?: string;
|
16
|
-
/** When using React v18+, this option allows a workspace to _disable_ React's Strict Mode from running in Knapsack's React Renderer (StrictMode is enabled by default).
|
17
|
-
*
|
18
|
-
* See https://reactjs.org/docs/strict-mode.html for more info
|
19
|
-
* */
|
20
|
-
disableReactStrictMode?: boolean;
|
21
|
-
/** Don't set if calling from `knapsack.config.js`, only use if creating a new Renderer based on the React Renderer */
|
22
|
-
id?: RendererId;
|
23
|
-
});
|
24
|
-
setConfig: Renderer['setConfig'];
|
25
|
-
init: Renderer['init'];
|
26
|
-
hydrate: Renderer['hydrate'];
|
27
|
-
getMeta: Renderer['getMeta'];
|
28
|
-
changeCase: Renderer['changeCase'];
|
29
|
-
createWebpackConfig: RendererWebpackBase['createWebpackConfig'];
|
30
|
-
prepClientRenderResults({ usage, demoApp, importMap, renderOptions: { demo, state, patternId, templateId }, }: {
|
31
|
-
usage: string;
|
32
|
-
demoApp: string;
|
33
|
-
importMap: KsJsImportMap;
|
34
|
-
renderOptions: Parameters<Renderer['render']>[0];
|
35
|
-
}): ReturnType<Renderer['render']>;
|
36
|
-
render: Renderer['render'];
|
37
|
-
getUsageAndImports: RendererWebpackBase['getUsageAndImports'];
|
38
|
-
inferSpec: Renderer['inferSpec'];
|
39
|
-
watch: Renderer['watch'];
|
40
|
-
getTemplateMeta: Renderer['getTemplateMeta'];
|
41
|
-
alterTemplateMetaFiles: Renderer['alterTemplateMetaFiles'];
|
42
|
-
getTemplateSuggestions: Renderer['getTemplateSuggestions'];
|
43
|
-
}
|
44
|
-
|
45
|
-
export { KnapsackReactRenderer };
|
1
|
+
export * from './renderer-react';
|
2
|
+
export type { DemoWrapperProps, } from '@knapsack/renderer-react-components/demo-wrapper';
|
3
|
+
//# sourceMappingURL=index.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,YAAY,EACV,gBAAgB,GAEjB,MAAM,kDAAkD,CAAC"}
|
package/dist/index.js
CHANGED
@@ -1,33 +1,18 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
`}c(se,"renderUsageTemplate");var M="DemoApp";function ae({imports:a="",children:t}){return `${a}
|
8
|
-
|
9
|
-
function ${M}() {
|
10
|
-
return (
|
11
|
-
${t}
|
12
|
-
)
|
13
|
-
}
|
14
|
-
`}c(ae,"renderDemoAppTemplate");async function O(a){let t=Object.keys(a.props||{}).map(s=>{let n=a.props[s];return {key:s,value:n}}),{templateName:e,children:r,extraProps:o=[]}=a;if(!e)throw new Error('Cannot getUsage of a React Component when no "templateName" is provided.');let i=t.map(({key:s,value:n})=>{switch(typeof n){case"string":return n.startsWith("(")&&n.includes("=>")?`${s}={${n}}`:`${s}="${n}"`;case"boolean":return n?`${s}`:`${s}={${n}}`;default:return `${s}={${JSON.stringify(n)}}`}}),p=[],d={};o.forEach(({key:s,value:n})=>{d[s]=d[s]??[],d[s].push(n);}),Object.entries(d).forEach(([s,n])=>{let f=n.length===1?n[0]:`<>${n.join(`
|
15
|
-
`)}</>`;p.push(`${s}={${f}}`);});let u=se({templateName:e,attributes:[...i,...p].join(" "),children:r});return a.format?fileUtils.formatCode({contents:u,path:"x.tsx"}).then(s=>s.trim()).catch(()=>u.trim()):u.trim()}c(O,"getUsage");async function I({children:a,imports:t,format:e}){let r=ae({children:a,imports:t});return e?fileUtils.formatCode({contents:r,path:"x.tsx"}):r}c(I,"getDemoAppUsage");async function V({src:a}){let t=await fileUtils.findUp("tsconfig.json",{cwd:y__default.default.dirname(a)}),e=await import('react-docgen-typescript'),r={shouldExtractLiteralValuesFromEnum:!0,savePropValueAsString:!0,skipChildrenPropWithoutDoc:!1,customComponentTypes:["VoidFunctionComponent","VFC"]};return {info:(t?e.withCustomConfig(t,r).parse:e.withDefaultConfig(r).parse)(a)}}c(V,"getTypeScriptInfoFromFile");function ne({info:a,exportName:t}){try{if(!a)return !1;let e={props:{$schema:"http://json-schema.org/draft-07/schema",type:"object",required:[],properties:{}},slots:{}},o=!t||t==="default"?a.pop():a.find(p=>p.displayName===t);if(!o)return !1;return Object.entries(o?.props||{}).forEach(([p,d])=>{let{name:u,description:s,defaultValue:n,required:f,type:l,parent:h}=d;switch(l?.name?.replace("| undefined","").replace(/<.*/g,"").trim()){case"string":e.props.properties[p]={type:"string"};break;case"number":e.props.properties[p]={type:"number"};break;case"boolean":case"bool":n&&"value"in n&&(n.value=n.value==="true"),e.props.properties[p]={type:"boolean"};break;case"enum":e.props.properties[p]={type:"string",enum:[...new Set(l.value.flatMap(({value:b})=>{if(!b)return [];let g=utils.removeWrappingDoubleQuotes(b.trim());return g==="undefined"?[]:[g]}))]};break;case"ReactNode":case"React.ReactNode":case"React.ReactElement":case"ReactElement":e.slots[p]={title:p},s&&(e.slots[p]={...e.slots[p],description:s});break;case"VFC":case"FC":e.slots[p]={title:p,description:s||"A reference to a component",isTemplateReference:!0,allowOnlyOne:!0,disallowText:!0};break;default:if(l?.name?.startsWith("("))e.props.properties[p]={typeof:"function",tsType:d?.type?.name};else if(l?.name?.includes("|")){let b=l.name.split("|").flatMap(g=>{if(!g)return [];let T=utils.removeWrappingDoubleQuotes(g.trim());return T==="undefined"?[]:[T]});b?.length&&(e.props.properties[p]={type:"string",enum:[...new Set(b)]});}else e.props.properties[p]={tsType:d?.type?.name};}e.props.properties[p]&&(f&&e.props.required.push(p),s&&!e.props.properties[p].description&&(e.props.properties[p].description=s),n&&"value"in n&&(types.isNumberProp(e.props.properties[p])?e.props.properties[p].default=parseFloat(n.value):e.props.properties[p].default=utils.removeWrappingDoubleQuotes(n.value)));}),e}catch(e){return app.log.verbose("Could not infer spec from React TypeScript file",{exportName:t,error:e},"react renderer"),!1}}c(ne,"extractSpecFromTypeScriptInfo");async function oe({src:a}){let t=await import('react-docgen'),{builtinResolvers:e}=t,r=await fileUtils.readFile(a),{FindExportedDefinitionsResolver:o}=e;return {info:t.parse(r,{resolver:new o,handlers:null,filename:a})}}c(oe,"getPropTypesInfoFromFile");function ie({info:a,exportName:t}){try{let r=!t||t==="default"?a.pop():a.find(i=>i.displayName===t),o={isInferred:!0,props:{$schema:"http://json-schema.org/draft-07/schema",type:"object",required:[],properties:{}},slots:{}};return Object.entries(r?.props||{}).forEach(([i,p])=>{let{required:d,description:u,defaultValue:s}=p;switch(p?.type?.name){case"string":o.props.properties[i]={type:"string"};break;case"func":o.props.properties[i]={type:"string"};break;case"bool":o.props.properties[i]={type:"boolean"};break;case"node":o.slots[i]={title:i,description:u};}o.props.properties[i]&&(d&&o.props.required.push(i),u&&!o.props.properties[i].description&&(o.props.properties[i].description=u),s&&"value"in s&&(o.props.properties[i].default=typeof s.value=="string"?utils.removeWrappingDoubleQuotes(s.value):s.value));}),o}catch(e){return app.log.verbose("Could not infer spec from React PropTypes",{exportName:t,error:e},"react renderer"),!1}}c(ie,"extractSpecFromPropTypesInfo");function pe({spec:a}){return a===!1||Object.entries(a?.props?.properties||{}).forEach(([t,e])=>{types.isOptionsProp(e)&&(e.enum.includes(e.default)||(e.default=void 0));}),a}c(pe,"cleanUpSpec");async function ce({src:a,resolveFromDir:t}){let e=await fileUtils.resolvePath({path:a,resolveFromDir:t,resolveType:"types"});if(e.exists){let i=await V({src:e.absolutePath});if(i)return {type:"typescript",info:i.info}}let r=await fileUtils.resolvePath({path:a,resolveFromDir:t});if(!r.exists)return {type:"unknown"};let{ext:o}=y__default.default.parse(r.absolutePath);switch(o){case".jsx":return {type:"propTypes",info:(await oe({src:r.absolutePath})).info};case".ts":case".tsx":return {type:"typescript",info:(await V({src:r.absolutePath})).info};default:return {type:"unknown"}}}c(ce,"getReactModuleInfoUncached");var $=new Map,N=c(()=>{app.log.info("Clearing React TypeScript inferSpec cache..."),$.clear();},"clearInferSpecCache");async function le(a){let t=JSON.stringify(a);return $.has(t)||$.set(t,ce(a)),$.get(t)}c(le,"getReactModuleInfo");async function de({src:a,exportName:t,resolveFromDir:e}){let r=await le({src:a,resolveFromDir:e});switch(r.type){case"typescript":return ne({info:r.info,exportName:t});case"propTypes":return ie({info:r.info,exportName:t});case"unknown":default:return !1}}c(de,"getReactSpec");async function _(a){return pe({spec:await de(a)})}c(_,"getReactDocs");async function L(a,t){try{let{version:e}=fileUtils.getModulePkgJson("react"),{version:r}=fileUtils.getModulePkgJson("react-dom"),o=y__default.default.dirname(E.resolve("react",{paths:[process.cwd()]})),i=y__default.default.dirname(E.resolve("react-dom",{paths:[process.cwd()]}));await Promise.all([fileUtils.copy(y__default.default.join(o,"umd/react.development.js"),y__default.default.join(a,`react.development.${e}.js`)),fileUtils.copy(y__default.default.join(o,"umd/react.production.min.js"),y__default.default.join(a,`react.production.min.${e}.js`)),fileUtils.copy(y__default.default.join(i,"umd/react-dom.production.min.js"),y__default.default.join(a,`react-dom.production.min.${r}.js`)),fileUtils.copy(y__default.default.join(i,"umd/react-dom.development.js"),y__default.default.join(a,`react-dom.development.${r}.js`))]);let p=process.env.NODE_ENV==="production"?"production.min":"development";return [y__default.default.join(t,`react.${p}.${e}.js`),y__default.default.join(t,`react-dom.${p}.${r}.js`)]}catch(e){app.log.warn('Error trying to copy "react" and "react-dom" JS files, are they installed? We want to use your exact versions.',e,"templateRenderer:react"),process.exit(1);}}c(L,"copyReactAssets");function Re(a){return a.toUpperCase()===a}c(Re,"isCapitalLetter");function be(a){return Re(a[0])}c(be,"startsWithCapitalLetter");function Te({importName:a,id:t,title:e=a,pkgPath:r,initialDemoId:o}){return {id:t,title:e,description:"",statuses:{main:"ready"},templates:[{id:"react",title:"react",path:r,alias:a,templateLanguageId:"react",spec:{isInferred:!0},demoIds:[o],blockIds:[]}],tabs:[{type:"template",id:"react"}],subPages:[]}}c(Te,"createPatternData");var G=creatorUtils.createCreator({id:"react-patterns",title:"React Ks Patterns",description:"Adds React templates as Knapsack Patterns",getQuestions:c(async()=>({pkgPath:{type:"text",title:"Package path"},importPrefix:{type:"text",title:"Import Prefix to Remove"}}),"getQuestions"),getTasks:c(async({answers:{pkgPath:a,importPrefix:t=""},config:e})=>{let r=e.dest,i=(await ksFileUtils.readKsPatternConfigs({dataDir:r})).reduce((d,u)=>{let s=u.templates?.filter(n=>n.templateLanguageId==="react")??[];return d.push(...s.map(n=>n.alias)),d},[]),{exports:p}=await fileUtils.getJsExportNames({path:a});return [{title:"Pick Imports to add",task:c((d,u)=>creatorUtils.tasks.runSubCreator({task:u,config:e,creator:creatorUtils.createCreator({id:"react-pattern-import-names",getQuestions:c(async()=>({importNames:{type:"choices",choices:p.filter(s=>be(s)&&!i.includes(s)).map(s=>({value:s}))}}),"getQuestions"),getTasks:c(async({answers:s})=>{let{importNames:n}=s,f=n.map(l=>({importName:l,patternId:l.startsWith(t)?l.slice(t.length).toLowerCase():l.toLowerCase()}));return [...f.map(({importName:l,patternId:h})=>({title:`Add ${l} React Template`,task:c(async(w,b)=>{let g={type:"data",id:utils.makeShortId(),title:"Main",patternId:h,templateId:"react",data:{props:{},slots:{}}},T=Te({id:h,importName:l,pkgPath:a,initialDemoId:g.id});await Promise.all([ksFileUtils.writeDemo({dataDir:r,demo:g}),ksFileUtils.writeKsPatternConfig({dataDir:r,patternId:h,data:T})]);},"task")})),{title:"Updating Nav",task:c(async(l,h)=>{let{byId:w}=await ksFileUtils.readKsNavConfig({dataDir:r}),b=Object.values(w).find(({path:g,name:T,id:P})=>g?!1:T.toLowerCase()==="patterns"||T.toLowerCase()==="components");await ksFileUtils.addKsNavItems({dataDir:r,navItems:f.map(({patternId:g})=>({navId:g,navPath:`/pattern/${g}`,navParent:b?.id||"root"}))});},"task")}]},"getTasks")})}),"task")}]},"getTasks")});var H="ks-react-meta";var{pkg:j}=fileUtils.findUpPkgJson(__dirname);app.log.setupUpdateNotifier({...j,name:j.name,version:j.version});var K=y.join(__dirname,"./error-catcher.mjs");if(!fileUtils.exists(K))throw new Error(`Could not find error catcher at: ${K}`);var Q=class a extends rendererWebpackBase.RendererWebpackBase{static{c(this,"KnapsackReactRenderer");}assets;babelConfig;#e;#t;constructor({webpackConfig:t,demoWrapperPath:e=y.join(__dirname,"./demo-wrapper.mjs"),id:r=types.rendererIds.react,disableReactStrictMode:o}={}){super({id:r,language:"jsx",webpackConfig:t,extraScripts:["@knapsack/renderer-react/client"]}),this.language="jsx",this.assets=[],this.#e=e,this.#t=o,this.creators=[G];}setConfig=c(t=>{super.setConfig(t);let{absolutePath:e,exists:r,type:o}=this.resolvePathSync({path:this.#e,resolveFromDir:this.userConfigDir});if(!r)throw new Error(`Could not find demo wrapper at: "${this.#e}"
|
16
|
-
Please adjust setting in "knapsack.config.js" or pass a different path when creating the React Renderer.`);this.registerExtraJsImports({DemoWrapper:{exportName:"DemoWrapper",isDefaultExport:!0,path:o==="package"?this.#e:e},ErrorCatcher:{exportName:"ErrorCatcher",isDefaultExport:!0,path:K}});},"setConfig");init=c(async()=>{this.assets=await L(this.outputDir,this.publicPath);},"init");hydrate=c(async t=>{await super.hydrate(t),await this.init({missingFileVerbosity:"silent"});},"hydrate");getMeta=c(()=>({id:this.id,title:"React",aliasUse:"optional",aliasTitle:"Named Export",aliasIsJsNamedExport:!0,aliasDescription:"If `export X` was used instead of `export default`, then provide X.",enableDataDemos:!0,enableTemplateDemos:!0,hasSlotsSupport:!0,hasSlotOptionsSupport:!0,version:j.version,hasInferSpecSupport:!0,syntaxHighlightingLanguage:"jsx",hasTemplateSuggestionsSupport:!0,prototypingTemplate:{path:"@knapsack/renderer-react/prototype-template",spec:{isInferred:!1,props:{type:"object",properties:{}},slots:{children:{title:"Children"}}}}}),"getMeta");changeCase=c(t=>utils.pascalCase(t),"changeCase");createWebpackConfig=c(()=>{let t=super.createWebpackConfig();return t.externals={react:"React","react-dom":"ReactDOM"},t},"createWebpackConfig");async prepClientRenderResults({usage:t,demoApp:e,importMap:r,renderOptions:{demo:o,state:i,patternId:p,templateId:d}}){let u={demo:o,disableReactStrictMode:this.#t,neededImportsByCodeSrcId:rendererWebpackBase.convertImportMapToNeededImportsByCodeSrcId(r),demoWrapperProps:{patternId:p,templateId:d,demo:o}},s=`
|
17
|
-
window.knapsack = window.knapsack || {};
|
18
|
-
window.knapsack.getDemoApp = ({ ${[...r.keys()].join(", ")} }) => {
|
19
|
-
${e}
|
20
|
-
return ${M}
|
1
|
+
"use strict";
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
+
if (k2 === undefined) k2 = k;
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
21
7
|
}
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
`),encoding:"utf8",path:y.join(e,"react.d.ts")}]},"alterTemplateMetaFiles");getTemplateSuggestions=c(async({newPath:t,state:e})=>{let r=Array.from(new Map(Object.values(e.patterns).reduce((s,{templateDemos:n,templates:f})=>(f.forEach(({path:l,alias:h,templateLanguageId:w})=>{w===this.id&&s.push([JSON.stringify({path:l,alias:h}),{path:l,alias:h}]);}),n.forEach(({templateInfo:{path:l,alias:h},templateLanguageId:w})=>{w===this.id&&s.push([JSON.stringify({path:l,alias:h}),{path:l,alias:h}]);}),s),[])).values()),o=new Set(this.getCodeSrcs().map(({path:s})=>s)),i=[...new Set([t,...Object.keys(this.pkgPathAliases||{}),...o])],d=(await Promise.all(i.map(async s=>{if(!s)return [];try{let{exports:n,errorMsg:f}=await fileUtils.getJsExportNames({path:s,resolveFromDir:this.dataDir,pkgPathAliases:this.pkgPathAliases});if(f)throw new Error(f);return n.filter(l=>l==="default"||utils.isFirstLetterCapital(l)).map(l=>({alias:l,path:s}))}catch(n){return app.log.verbose(`Error getting import names for ${s}: ${n.message}`,null,this.logPrefix),[]}})).then(s=>s.flat())).filter(s=>!r.find(n=>n.alias===s.alias&&n.path===s.path)),u=r.map(s=>({...s,connected:!0}));return {suggestions:[...d,...u]}},"getTemplateSuggestions")};exports.KnapsackReactRenderer=Q;//# sourceMappingURL=index.js.map
|
8
|
+
Object.defineProperty(o, k2, desc);
|
9
|
+
}) : (function(o, m, k, k2) {
|
10
|
+
if (k2 === undefined) k2 = k;
|
11
|
+
o[k2] = m[k];
|
12
|
+
}));
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
15
|
+
};
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
17
|
+
__exportStar(require("./renderer-react"), exports);
|
33
18
|
//# sourceMappingURL=index.js.map
|