@knapsack/renderer-react 4.71.17--canary.5251.cc77be8.0 → 4.71.17--canary.5261.959b319.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. package/CHANGELOG.md +60 -0
  2. package/ava.config.cjs +7 -1
  3. package/dist/analyze/infer-spec.test.d.ts +2 -0
  4. package/dist/analyze/infer-spec.test.d.ts.map +1 -0
  5. package/dist/analyze/infer-spec.test.js +112 -0
  6. package/dist/analyze/infer-spec.test.js.map +1 -0
  7. package/dist/analyze/mui.test.d.ts +2 -0
  8. package/dist/analyze/mui.test.d.ts.map +1 -0
  9. package/dist/analyze/mui.test.js +60 -0
  10. package/dist/analyze/mui.test.js.map +1 -0
  11. package/dist/analyze/pkg-basic.test.d.ts +2 -0
  12. package/dist/analyze/pkg-basic.test.d.ts.map +1 -0
  13. package/dist/analyze/pkg-basic.test.js +33 -0
  14. package/dist/analyze/pkg-basic.test.js.map +1 -0
  15. package/dist/analyze/pkg-diff-types.test.d.ts +2 -0
  16. package/dist/analyze/pkg-diff-types.test.d.ts.map +1 -0
  17. package/dist/analyze/pkg-diff-types.test.js +43 -0
  18. package/dist/analyze/pkg-diff-types.test.js.map +1 -0
  19. package/dist/client/init.d.mts +2 -2
  20. package/dist/client/init.d.mts.map +1 -0
  21. package/dist/client/init.mjs +39 -3
  22. package/dist/client/init.mjs.map +1 -1
  23. package/dist/index.d.ts +3 -45
  24. package/dist/index.d.ts.map +1 -0
  25. package/dist/index.js +16 -31
  26. package/dist/index.js.map +1 -1
  27. package/dist/react-creators.d.ts +20 -0
  28. package/dist/react-creators.d.ts.map +1 -0
  29. package/dist/react-creators.js +170 -0
  30. package/dist/react-creators.js.map +1 -0
  31. package/dist/{index.d.mts → renderer-react.d.ts} +2 -5
  32. package/dist/renderer-react.d.ts.map +1 -0
  33. package/dist/renderer-react.js +569 -0
  34. package/dist/renderer-react.js.map +1 -0
  35. package/dist/types.d.ts +19 -0
  36. package/dist/types.d.ts.map +1 -0
  37. package/dist/types.js +5 -0
  38. package/dist/types.js.map +1 -0
  39. package/dist/utils.d.ts +28 -0
  40. package/dist/utils.d.ts.map +1 -0
  41. package/dist/utils.js +500 -0
  42. package/dist/utils.js.map +1 -0
  43. package/dist/utils.test.d.ts +2 -0
  44. package/dist/utils.test.d.ts.map +1 -0
  45. package/dist/utils.test.js +59 -0
  46. package/dist/utils.test.js.map +1 -0
  47. package/package.json +23 -27
  48. package/prototype-template.d.mts +3 -0
  49. package/prototype-template.mjs +3 -0
  50. package/test-fixtures/pkg-diff-types/button.js +10 -0
  51. package/test-fixtures/pkg-diff-types/package.json +4 -0
  52. package/test-fixtures/pkg-diff-types/readme.md +1 -0
  53. package/test-fixtures/pkg-diff-types/types/button.d.ts +5 -0
  54. package/tsconfig.json +2 -2
  55. package/dist/client/init.d.ts +0 -2
  56. package/dist/client/init.js +0 -5
  57. package/dist/client/init.js.map +0 -1
  58. package/dist/demo-wrapper.d.mts +0 -7
  59. package/dist/demo-wrapper.d.ts +0 -7
  60. package/dist/demo-wrapper.js +0 -2
  61. package/dist/demo-wrapper.js.map +0 -1
  62. package/dist/demo-wrapper.mjs +0 -2
  63. package/dist/demo-wrapper.mjs.map +0 -1
  64. package/dist/error-catcher.d.mts +0 -20
  65. package/dist/error-catcher.d.ts +0 -20
  66. package/dist/error-catcher.js +0 -2
  67. package/dist/error-catcher.js.map +0 -1
  68. package/dist/error-catcher.mjs +0 -2
  69. package/dist/error-catcher.mjs.map +0 -1
  70. package/dist/index.mjs +0 -33
  71. package/dist/index.mjs.map +0 -1
  72. package/dist/prototype-template.d.mts +0 -7
  73. package/dist/prototype-template.d.ts +0 -7
  74. package/dist/prototype-template.js +0 -2
  75. package/dist/prototype-template.js.map +0 -1
  76. package/dist/prototype-template.mjs +0 -2
  77. package/dist/prototype-template.mjs.map +0 -1
  78. package/dist/types-CivTHEEo.d.mts +0 -10
  79. package/dist/types-CivTHEEo.d.ts +0 -10
  80. package/tsup.config.cjs +0 -5
package/CHANGELOG.md CHANGED
@@ -1,3 +1,63 @@
1
+ # v4.71.16 (Thu Dec 05 2024)
2
+
3
+ #### 🐛 Bug Fix
4
+
5
+ - refactor React Renderer to use `tsc` for build [#5224](https://github.com/knapsack-labs/app-monorepo/pull/5224) ([@EvanLovely](https://github.com/EvanLovely) [@mabry1985](https://github.com/mabry1985))
6
+ - cleanup ([@EvanLovely](https://github.com/EvanLovely))
7
+ - remove concurrency in CI change ([@EvanLovely](https://github.com/EvanLovely))
8
+ - remove memory bump ([@EvanLovely](https://github.com/EvanLovely))
9
+ - set MUI Button test to failing ([@EvanLovely](https://github.com/EvanLovely))
10
+ - do not mutate arrays ([@EvanLovely](https://github.com/EvanLovely))
11
+ - Remove use of __dirname ([@EvanLovely](https://github.com/EvanLovely))
12
+ - bump memory for CI test run ([@EvanLovely](https://github.com/EvanLovely))
13
+ - restore use of tsconfig ([@EvanLovely](https://github.com/EvanLovely))
14
+ - serial test run ([@EvanLovely](https://github.com/EvanLovely))
15
+ - temp disabling possibility of using custom config to help troubleshoot CI issue ([@EvanLovely](https://github.com/EvanLovely))
16
+ - skip cache during ava tests ([@EvanLovely](https://github.com/EvanLovely))
17
+ - pass MUI pkg name directly in ([@EvanLovely](https://github.com/EvanLovely))
18
+ - re-enable MUI test ([@EvanLovely](https://github.com/EvanLovely))
19
+ - Merge branch 'latest' into feature/react-renderer-build ([@EvanLovely](https://github.com/EvanLovely))
20
+ - Merge branch 'latest' into feature/react-renderer-build ([@mabry1985](https://github.com/mabry1985))
21
+ - undo skipping of utils test ([@mabry1985](https://github.com/mabry1985))
22
+ - skip both mui tests ([@mabry1985](https://github.com/mabry1985))
23
+ - skip mui test ([@mabry1985](https://github.com/mabry1985))
24
+ - revert to run all suites ([@mabry1985](https://github.com/mabry1985))
25
+ - remove utils test for debugging ([@mabry1985](https://github.com/mabry1985))
26
+ - revert to run tests individually ([@mabry1985](https://github.com/mabry1985))
27
+ - remove skip ([@mabry1985](https://github.com/mabry1985))
28
+ - check prop types test for bug ([@mabry1985](https://github.com/mabry1985))
29
+ - revert to failing ([@mabry1985](https://github.com/mabry1985))
30
+ - revert to run all tests ([@mabry1985](https://github.com/mabry1985))
31
+ - skip test using jsx-runtime ([@mabry1985](https://github.com/mabry1985))
32
+ - add getReactDocs import to testing ([@mabry1985](https://github.com/mabry1985))
33
+ - add minimal testing file ([@mabry1985](https://github.com/mabry1985))
34
+ - revert debugging ([@mabry1985](https://github.com/mabry1985))
35
+ - skip all suites for testing ([@mabry1985](https://github.com/mabry1985))
36
+ - remove garbage cleanup step ([@mabry1985](https://github.com/mabry1985))
37
+ - update to use config ([@mabry1985](https://github.com/mabry1985))
38
+ - update to use serial ([@mabry1985](https://github.com/mabry1985))
39
+ - add cleanup steps ([@mabry1985](https://github.com/mabry1985))
40
+ - add concurrency limit to ava test ([@mabry1985](https://github.com/mabry1985))
41
+ - re-order scripts ([@mabry1985](https://github.com/mabry1985))
42
+ - revert to individual tests ([@mabry1985](https://github.com/mabry1985))
43
+ - try garbage cleanup ([@mabry1985](https://github.com/mabry1985))
44
+ - update to run in serial ([@mabry1985](https://github.com/mabry1985))
45
+ - revert test script ([@mabry1985](https://github.com/mabry1985))
46
+ - fix default demo wrapper path resolution ([@EvanLovely](https://github.com/EvanLovely))
47
+ - break tests up to debug CI ([@EvanLovely](https://github.com/EvanLovely))
48
+ - set unit tests to run serially to prevent segmentation fault in CI ([@EvanLovely](https://github.com/EvanLovely))
49
+ - add sideEffects ([@EvanLovely](https://github.com/EvanLovely))
50
+ - cleanup file ([@EvanLovely](https://github.com/EvanLovely))
51
+ - adjust line command ([@EvanLovely](https://github.com/EvanLovely))
52
+ - refactor React Renderer to use `tsc` for build ([@EvanLovely](https://github.com/EvanLovely))
53
+
54
+ #### Authors: 2
55
+
56
+ - Evan Lovely ([@EvanLovely](https://github.com/EvanLovely))
57
+ - Josh Mabry ([@mabry1985](https://github.com/mabry1985))
58
+
59
+ ---
60
+
1
61
  # v4.71.13 (Wed Dec 04 2024)
2
62
 
3
63
  #### 🐛 Bug Fix
package/ava.config.cjs CHANGED
@@ -1,3 +1,9 @@
1
- const config = require('@knapsack/test-ava');
1
+ const config = require('@knapsack/test-ava/esm');
2
+
3
+ const isCi = !!process.env.CI;
4
+
5
+ if (isCi) {
6
+ // config.concurrency = 1;
7
+ }
2
8
 
3
9
  module.exports = config;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=infer-spec.test.d.ts.map
@@ -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":"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"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=mui.test.d.ts.map
@@ -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":"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"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=pkg-basic.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pkg-basic.test.d.ts","sourceRoot":"","sources":["../../src/analyze/pkg-basic.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,33 @@
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,oBAAY,EAAC;QAC9B,GAAG,EAAE,mDAAmD;QACxD,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,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"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=pkg-diff-types.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"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"}
@@ -1,2 +1,2 @@
1
-
2
- export { }
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":""}
@@ -1,5 +1,41 @@
1
- import E from'react';import g from'react-dom/client';import {getKsRendererClientUtils}from'@knapsack/renderer-webpack-base/client';import {jsx}from'react/jsx-runtime';var l=Object.defineProperty;var n=(r,e)=>l(r,"name",{value:e,configurable:!0});var h=(r,e)=>()=>(r&&(e=r(r=0)),e);var C=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports);var a,m=h(()=>{a="ks-react-meta";});var I=C(()=>{m();async function x(){try{let{getNeededImports:r,getExtraImports:e,rendererMeta:{disableReactStrictMode:d,demoWrapperProps:s},rendererMethods:{getDemoApp:c}}=getKsRendererClientUtils({rendererMetaScriptTagId:a}),[i,{DemoWrapper:R,ErrorCatcher:y}]=await Promise.all([r(),e()]),o=document.getElementById("render-root");if(!o)throw new Error("No root element found");let M=c(i),p=jsx(y,{children:jsx(R,{...s,children:jsx(M,{})})});g.createRoot(o).render(d?p:jsx(E.StrictMode,{children:p}));}catch(r){console.error(r);let e=document.createElement("div");e.innerHTML=`
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>${r.message}</p>
4
- `,document.body.appendChild(e);}}n(x,"init");x();});var init = I();export{init as default};//# sourceMappingURL=init.mjs.map
35
+ <p>${e.message}</p>
36
+ `;
37
+ document.body.appendChild(errorElement);
38
+ }
39
+ }
40
+ init();
5
41
  //# sourceMappingURL=init.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/types.ts","../../src/client/init.tsx"],"names":["rendererMetaScriptTagId","init_types","__esmMin","require_init","__commonJSMin","init","getNeededImports","getExtraImports","disableReactStrictMode","demoWrapperProps","getDemoApp","getKsRendererClientUtils","neededImports","DemoWrapper","ErrorCatcher","root","DemoApp","app","jsx","ReactDOM","React","e","errorElement","__name"],"mappings":"uKAAA,IAAA,CAAA,CAAA,MAAA,CAAA,cAAA,CAAA,IAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,GAAA,CAAA,CAAA,CAAA,CAAA,MAAA,CAAA,CAAA,KAAA,CAAA,CAAA,CAAA,YAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,IAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,GAAA,KAAA,CAAA,GAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,IAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,GAAA,KAAA,CAAA,EAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,OAAA,CAAA,EAAA,CAAA,EAAA,OAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,OAAA,CAAA,CAAA,IAuBaA,CAvBbC,CAAAA,CAAAA,CAAAC,CAAA,CAAA,IAAA,CAuBaF,CAA0B,CAAA,gBAAA,CAAA,CAAA,CCvBvC,IAAAG,CAAAA,CAAAC,EAAA,IAIAH,CAAAA,CAAAA,EAAAA,CAQA,eAAeI,CAAAA,EAAO,CACpB,GAAI,CACF,GAAM,CACJ,gBAAAC,CAAAA,CAAAA,CACA,eAAAC,CAAAA,CAAAA,CACA,YAAc,CAAA,CAAE,sBAAAC,CAAAA,CAAAA,CAAwB,gBAAAC,CAAAA,CAAiB,CACzD,CAAA,eAAA,CAAiB,CAAE,UAAA,CAAAC,CAAW,CAChC,EAAIC,wBAKF,CAAA,CACA,uBAAAX,CAAAA,CACF,CAAC,CAAA,CACK,CAACY,CAAAA,CAAe,CAAE,WAAAC,CAAAA,CAAAA,CAAa,YAAAC,CAAAA,CAAa,CAAC,CAAA,CAAI,MAAM,OAAA,CAAQ,IAAI,CACvER,CAAAA,EACAC,CAAAA,CAAAA,EACF,CAAC,CACKQ,CAAAA,CAAAA,CAAO,QAAS,CAAA,cAAA,CAAe,aAAa,CAAA,CAClD,GAAI,CAACA,CACH,CAAA,MAAM,IAAI,KAAM,CAAA,uBAAuB,CAGzC,CAAA,IAAMC,CAAUN,CAAAA,CAAAA,CADOE,CACkB,CAAA,CACnCK,EACJC,GAACJ,CAAAA,CAAAA,CAAA,CACC,QAAA,CAAAI,GAACL,CAAAA,CAAAA,CAAA,CAAa,GAAGJ,EACf,QAAAS,CAAAA,GAAAA,CAACF,CAAA,CAAA,EAAQ,CACX,CAAA,CAAA,CACF,CAGFG,CAAAA,CAAAA,CAAS,WAAWJ,CAAI,CAAA,CAAE,MACxBP,CAAAA,CAAAA,CAAyBS,CAAMC,CAAAA,GAAAA,CAACE,CAAM,CAAA,UAAA,CAAN,CAAkB,QAAAH,CAAAA,CAAAA,CAAI,CACxD,EACF,CAASI,MAAAA,CAAAA,CAAG,CACV,OAAA,CAAQ,MAAMA,CAAC,CAAA,CAEf,IAAMC,CAAAA,CAAe,QAAS,CAAA,aAAA,CAAc,KAAK,CAAA,CACjDA,EAAa,SAAY,CAAA;AAAA;AAAA,OAAA,EAEpBD,EAAE,OAAO,CAAA;AAAA,EAEd,CAAA,CAAA,QAAA,CAAS,IAAK,CAAA,WAAA,CAAYC,CAAY,EACxC,CACF,CA9CeC,CAAAA,CAAAlB,CAAA,CAAA,MAAA,CAAA,CAgDfA,CAAK,GAAA,CAAA,CAAA,CAAA,WAAA,CAAA,EAAA","file":"init.mjs","sourcesContent":["import type { Demo, Except } from '@knapsack/types';\nimport type { ComponentType } from 'react';\nimport type { RendererMetaBase } from '@knapsack/renderer-webpack-base/client';\n\nexport type Component = ComponentType<Record<string, unknown>>;\n\nexport type DemoWrapperProps = {\n children: React.ReactNode;\n demo: Demo;\n patternId: string;\n templateId: string;\n};\n\nexport type ExtraJsImportNames = 'DemoWrapper' | 'ErrorCatcher';\n/**\n * Found as JSON in HTML `#ks-react-meta`\n */\nexport type KsReactMeta = {\n disableReactStrictMode: boolean;\n demo: Demo;\n demoWrapperProps: Except<DemoWrapperProps, 'children'>;\n} & RendererMetaBase;\n\nexport const rendererMetaScriptTagId = 'ks-react-meta';\n\nexport type RendererMethods = {\n getDemoApp: (components: Record<string, Component>) => Component;\n};\n","/// <reference lib=\"dom\" />\nimport React from 'react';\nimport ReactDOM from 'react-dom/client';\nimport { getKsRendererClientUtils } from '@knapsack/renderer-webpack-base/client';\nimport {\n rendererMetaScriptTagId,\n type KsReactMeta,\n type Component,\n type RendererMethods,\n ExtraJsImportNames,\n} from '../types';\n\nasync function init() {\n try {\n const {\n getNeededImports,\n getExtraImports,\n rendererMeta: { disableReactStrictMode, demoWrapperProps },\n rendererMethods: { getDemoApp },\n } = getKsRendererClientUtils<\n Component,\n KsReactMeta,\n RendererMethods,\n ExtraJsImportNames\n >({\n rendererMetaScriptTagId,\n });\n const [neededImports, { DemoWrapper, ErrorCatcher }] = await Promise.all([\n getNeededImports(),\n getExtraImports(),\n ]);\n const root = document.getElementById('render-root');\n if (!root) {\n throw new Error('No root element found');\n }\n const demoComponents = neededImports;\n const DemoApp = getDemoApp(demoComponents);\n const app = (\n <ErrorCatcher>\n <DemoWrapper {...demoWrapperProps}>\n <DemoApp />\n </DemoWrapper>\n </ErrorCatcher>\n );\n\n ReactDOM.createRoot(root).render(\n disableReactStrictMode ? app : <React.StrictMode>{app}</React.StrictMode>,\n );\n } catch (e) {\n console.error(e);\n // create html element with error message\n const errorElement = document.createElement('div');\n errorElement.innerHTML = `\n <h1>Error</h1>\n <p>${e.message}</p>\n `;\n document.body.appendChild(errorElement);\n }\n}\n\ninit();\n"]}
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
- import { RendererWebpackBase, Renderer, KsJsImportMap } from '@knapsack/renderer-webpack-base';
2
- import { Renderable } from '@knapsack/app/renderers';
3
- import { RendererId } from '@knapsack/types';
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
- 'use strict';var ke=require('sleep-promise'),rendererWebpackBase=require('@knapsack/renderer-webpack-base'),utils=require('@knapsack/utils'),app=require('@knapsack/app'),renderers=require('@knapsack/app/renderers'),types=require('@knapsack/types'),fileUtils=require('@knapsack/file-utils'),y=require('path'),creatorUtils=require('@knapsack/creator-utils'),ksFileUtils=require('@knapsack/ks-file-utils');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var ke__default=/*#__PURE__*/_interopDefault(ke);var y__default=/*#__PURE__*/_interopDefault(y);var Y=Object.defineProperty;var c=(a,t)=>Y(a,"name",{value:t,configurable:!0}),E=(a=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(a,{get:(t,e)=>(typeof require<"u"?require:t)[e]}):a)(function(a){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+a+'" is not supported')});function se({templateName:a,attributes:t,children:e}){return `
2
- <${a}
3
- ${t}
4
- ${e?`>
5
- ${e}
6
- </${a}>`:"/>"}
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
- `,n="";try{s=await renderers.babelCodeForBrowser({code:s});}catch(l){console.log(s),console.log("---original code before babel error ^---"),console.trace(l.message),s=`console.error(${JSON.stringify(l.message)});`,n=`<pre><code>${l.message}</code></pre>`;}let f=`
23
- <script type="application/json" id="${H}">${JSON.stringify(u)}</script>
24
- <script type="application/javascript">${s}</script>
25
- <div id="render-root" class="knapsack-pattern-direct-parent" data-dev-note="Knapsack React Template Wrapper"></div>
26
- ${this.assets.map(l=>`<script src="${l}"></script>`).join(`
27
- `)}
28
- ${rendererWebpackBase.RendererWebpackBase.createHtmlTagsForAssetPaths({assets:this.getWebpackAssetPaths(),scriptTagsAreAsync:!1})}
29
- ${n}
30
- `;return {ok:!n,html:await fileUtils.formatCode({contents:f,path:"x.html"}),usage:t,templateLanguage:this.language}}render=c(async t=>{if(t.demo?.type==="template"){let e=[5,10,20,50,100,1e3,1e3],r,o=0;for(;;)try{let{absolutePath:n,exists:f}=await this.resolvePath(t.demo.templateInfo.path);if(!f)throw new Error(`Template demo file does not exist: ${n}`);r=n;break}catch(n){let f=e[o];if(!f)throw new Error(n);o+=1,await ke__default.default(f);}let[i,{usage:p,importMap:d}]=await Promise.all([fileUtils.readFile(r),this.getUsageAndImports({...t,importMap:new Map})]),u=await I({children:p});return await this.prepClientRenderResults({usage:i,demoApp:u,renderOptions:t,importMap:d})}if(t.demo?.type==="data"){let{usage:e,importMap:r}=await this.getUsageAndImports({...t,importMap:new Map}),o=rendererWebpackBase.RendererWebpackBase.createJsImportCodeBlock({importMap:r}),[i,p]=await Promise.all([I({children:e,imports:o,format:!0}),I({children:e})]);return this.prepClientRenderResults({demoApp:p,usage:i,renderOptions:t,importMap:r})}},"render");getUsageAndImports=c(async({patternId:t,templateId:e,demo:r,state:o,importMap:i})=>{if(!r)throw new Error(`No demo provided while rendering ${t} ${e}`);let p=o.patterns[t];if(!p)throw new Error(`Could not find pattern: ${t}`);if(r.type==="data"){let u=p.templates.find(g=>g.id===e);if(!u)throw new Error(`Could not find template: ${e}`);let{data:{props:s,slots:n,slotsOptionsComputed:f}}=r,{name:l}=await this.addUniqueValueToImportMap({importMap:i,path:u.path,alias:u.alias||"default"}),h=[],w=[];if(n){let g=Object.keys(n);(await Promise.all(g.map(async P=>{let k=n[P],D=await Promise.all(k.filter(m=>!(!m||m.type!=="text"&&(!m.patternId||!m.templateId||m.type==="template-demo"&&!m.demoId))).map(async m=>{if(m.type==="text")return k.length===1&&P!=="children"?`\`${m.text}\``:m.text;if(m.type==="template-reference"){let R=o.patterns[m.patternId]?.templates.find(z=>z.id===m.templateId);if(!R)throw new Error(`Could not find slotted template: ${m.patternId} ${m.templateId}`);return (await this.addUniqueValueToImportMap({importMap:i,path:R.path,alias:R.alias||"default"})).name}if(m.type==="template-demo"){let R=m.demo;if(!R)throw new Error(`Could not find slotted template demo ${JSON.stringify(m)}`);let{usage:U}=await this.getUsageAndImports({patternId:R.patternId,templateId:R.templateId,demo:R,state:o,importMap:i});return U}throw new Error(`Unknown slot item: ${JSON.stringify(m)}`)}));return {slotName:P,slotItemsUsages:D}}))).forEach(({slotName:P,slotItemsUsages:k})=>{let D=f?.[P],{openTag:m,closeTag:C}=renderers.createSlotOptionsHtmlTags({slotOptionsComputed:D,classAttributeName:"className",stylesValueType:"object"});m&&(P==="children"?h.push(m):w.push({key:P,value:m})),k.forEach(R=>{P==="children"?h.push(R):w.push({key:P,value:R});}),C&&(P==="children"?h.push(C):w.push({key:P,value:C}));});}return {usage:await O({templateName:l,props:s,children:h.join(`
31
- `),extraProps:w}),importMap:i}}if(r.type==="template"){let{templateInfo:u}=r,{name:s}=await this.addUniqueValueToImportMap({importMap:i,path:u.path,alias:u.alias||"default"});return {usage:await O({templateName:s}),importMap:i}}throw new Error(`Unhandled demo type for ${t}-${e}: ${JSON.stringify(r)}`)},"getUsageAndImports");inferSpec=c(async({template:t,templatePath:e})=>{let r=await _({src:t.path,exportName:t.alias||"default",resolveFromDir:this.config.data});if(r!==!1){let o=Object.keys(r?.props?.properties||{}).length,i=Object.keys(r?.slots||{}).length;if(o===0&&i===0)return !1}return r},"inferSpec");watch=c(async()=>{super.watch(),app.knapsackEvents.onPatternTemplateChanged(()=>{N();});},"watch");getTemplateMeta=c(async({pattern:t,template:e})=>{let r=[];if(e?.spec?.props){let o=JSON.parse(JSON.stringify(e.spec.props));e?.spec?.slots&&Object.entries(e.spec.slots).forEach(([p,d])=>{o.properties[p]={typeof:"function",tsType:"React.ReactNode",description:d.allowedPatternIds?`${d.description}. Only use: ${d.allowedPatternIds.join(", ")}`:d.description},o.required=o.required??[],d.isRequired&&o.required.push(p);});let i=await a.convertSchemaToTypeScriptDefs({schema:o,title:`${this.changeCase(t.id)}Props`,description:`[Knapsack Docs](http://localhost:3999/pattern/${t.id}/${e.id})`,patternId:t.id,templateId:e.id,postBanner:"import * as React from 'react';"});r.push({contents:i,encoding:"utf8",path:`${t.id}.${e.id}.spec.d.ts`}),r.push({contents:JSON.stringify(o,null," "),encoding:"utf8",path:`${t.id}.${e.id}.spec.json`});}return r},"getTemplateMeta");alterTemplateMetaFiles=c(async({files:t,metaDir:e})=>{let r=[],o=".spec.d.ts";return t.forEach(i=>{if(i.path.endsWith(o)){let{base:p}=y.parse(i.path),[d,u]=p.split("."),s=u===this.id,n=this.changeCase(`${d}Props`),f=this.changeCase(`${d}-${u}Props`);r.push(`export { ${s?n:`${n} as ${f}`} } from './${y.relative(e,i.path).replace(".d.ts","")}';`);}}),r.push(""),[...t,{contents:r.join(`
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