@knapsack/renderer-react 4.72.0--canary.4920.be98a9b.0 → 4.72.0--canary.5313.51b7b5f.0
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +217 -0
- 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 +38 -10
- 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 -52
- 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 +27 -31
- 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 +3 -2
- package/dist/client/init.d.ts +0 -2
- package/dist/client/init.js +0 -20
- 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 -9
- package/dist/demo-wrapper.js.map +0 -1
- package/dist/demo-wrapper.mjs +0 -7
- 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 -30
- package/dist/error-catcher.js.map +0 -1
- package/dist/error-catcher.mjs +0 -8
- package/dist/error-catcher.mjs.map +0 -1
- package/dist/index.mjs +0 -47
- 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 -7
- package/dist/prototype-template.js.map +0 -1
- package/dist/prototype-template.mjs +0 -5
- 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/package.json
CHANGED
@@ -1,10 +1,8 @@
|
|
1
1
|
{
|
2
2
|
"name": "@knapsack/renderer-react",
|
3
3
|
"description": "Render React",
|
4
|
-
"version": "4.72.0--canary.
|
4
|
+
"version": "4.72.0--canary.5313.51b7b5f.0",
|
5
5
|
"type": "commonjs",
|
6
|
-
"main": "dist/index.js",
|
7
|
-
"types": "dist/index.d.ts",
|
8
6
|
"exports": {
|
9
7
|
".": {
|
10
8
|
"types": "./dist/index.d.ts",
|
@@ -17,31 +15,30 @@
|
|
17
15
|
"./package": "./package.json",
|
18
16
|
"./package.json": "./package.json",
|
19
17
|
"./prototype-template": {
|
20
|
-
"types": "./
|
21
|
-
"
|
22
|
-
"import": "./dist/prototype-template.mjs",
|
23
|
-
"default": "./dist/prototype-template.mjs"
|
18
|
+
"types": "./prototype-template.d.mts",
|
19
|
+
"default": "./prototype-template.mjs"
|
24
20
|
}
|
25
21
|
},
|
26
|
-
"sideEffects":
|
22
|
+
"sideEffects": [
|
23
|
+
"./dist/client/init.mjs"
|
24
|
+
],
|
27
25
|
"scripts": {
|
28
|
-
"build": "
|
26
|
+
"build": "tsc",
|
29
27
|
"clean": "rm -rf dist",
|
30
|
-
"lint": "eslint ./src
|
31
|
-
"test": "
|
32
|
-
"test:types": "tsc",
|
33
|
-
"test:unit": "ava"
|
28
|
+
"lint": "eslint ./src --quiet",
|
29
|
+
"test": "ava"
|
34
30
|
},
|
35
31
|
"author": "Knapsack",
|
36
32
|
"dependencies": {
|
37
|
-
"@babel/preset-react": "^7.25.
|
38
|
-
"@knapsack/app": "4.72.0--canary.
|
39
|
-
"@knapsack/creator-utils": "4.72.0--canary.
|
40
|
-
"@knapsack/file-utils": "4.72.0--canary.
|
41
|
-
"@knapsack/ks-file-utils": "4.72.0--canary.
|
42
|
-
"@knapsack/renderer-
|
43
|
-
"@knapsack/
|
44
|
-
"@knapsack/
|
33
|
+
"@babel/preset-react": "^7.25.9",
|
34
|
+
"@knapsack/app": "4.72.0--canary.5313.51b7b5f.0",
|
35
|
+
"@knapsack/creator-utils": "4.72.0--canary.5313.51b7b5f.0",
|
36
|
+
"@knapsack/file-utils": "4.72.0--canary.5313.51b7b5f.0",
|
37
|
+
"@knapsack/ks-file-utils": "4.72.0--canary.5313.51b7b5f.0",
|
38
|
+
"@knapsack/renderer-react-components": "4.72.0--canary.5313.51b7b5f.0",
|
39
|
+
"@knapsack/renderer-webpack-base": "4.72.0--canary.5313.51b7b5f.0",
|
40
|
+
"@knapsack/types": "4.72.0--canary.5313.51b7b5f.0",
|
41
|
+
"@knapsack/utils": "4.72.0--canary.5313.51b7b5f.0",
|
45
42
|
"react": "^18.3.1",
|
46
43
|
"react-docgen": "^6.0.4",
|
47
44
|
"react-docgen-typescript": "^2.2.2",
|
@@ -50,19 +47,18 @@
|
|
50
47
|
"typescript": "^5.6.3"
|
51
48
|
},
|
52
49
|
"devDependencies": {
|
53
|
-
"@knapsack/eslint-config-starter": "4.72.0--canary.
|
54
|
-
"@knapsack/sandbox-components": "4.72.0--canary.
|
55
|
-
"@knapsack/test-ava": "4.72.0--canary.
|
56
|
-
"@knapsack/typescript-config-starter": "4.72.0--canary.
|
50
|
+
"@knapsack/eslint-config-starter": "4.72.0--canary.5313.51b7b5f.0",
|
51
|
+
"@knapsack/sandbox-components": "4.72.0--canary.5313.51b7b5f.0",
|
52
|
+
"@knapsack/test-ava": "4.72.0--canary.5313.51b7b5f.0",
|
53
|
+
"@knapsack/typescript-config-starter": "4.72.0--canary.5313.51b7b5f.0",
|
57
54
|
"@mui/material": "^5.16.7",
|
58
55
|
"@mui/x-data-grid": "^6.20.4",
|
59
|
-
"@types/node": "^20.17.
|
60
|
-
"@types/react": "^18.3.
|
61
|
-
"@types/react-dom": "^18.3.
|
56
|
+
"@types/node": "^20.17.8",
|
57
|
+
"@types/react": "^18.3.12",
|
58
|
+
"@types/react-dom": "^18.3.1",
|
62
59
|
"ava": "^6.2.0",
|
63
60
|
"eslint": "^8.57.0",
|
64
|
-
"prop-types": "^15.8.1"
|
65
|
-
"tsup": "^8.3.0"
|
61
|
+
"prop-types": "^15.8.1"
|
66
62
|
},
|
67
63
|
"publishConfig": {
|
68
64
|
"access": "public"
|
@@ -72,5 +68,5 @@
|
|
72
68
|
"directory": "apps/client/renderers/renderer-react",
|
73
69
|
"type": "git"
|
74
70
|
},
|
75
|
-
"gitHead": "
|
71
|
+
"gitHead": "51b7b5f2b8e4a42f078030647178769053559d32"
|
76
72
|
}
|
@@ -0,0 +1 @@
|
|
1
|
+
note that the dist does not have `x.js` & `x.d.ts` - instead the `types` key in `package.json` points to a different location - this is because of the `declarationDir` config in `tsconfig.json`
|
package/tsconfig.json
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
{
|
2
|
-
"extends": "@knapsack/typescript-config-starter/tsconfig.
|
3
|
-
"include": ["src/**/*"
|
2
|
+
"extends": "@knapsack/typescript-config-starter/tsconfig.build.json",
|
3
|
+
"include": ["src/**/*"],
|
4
4
|
"exclude": ["**/dist"],
|
5
5
|
"compilerOptions": {
|
6
|
+
"strictNullChecks": false,
|
6
7
|
"noImplicitAny": false,
|
7
8
|
"outDir": "./dist"
|
8
9
|
}
|
package/dist/client/init.d.ts
DELETED
package/dist/client/init.js
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
'use strict';
|
2
|
-
|
3
|
-
var E = require('react');
|
4
|
-
var g = require('react-dom/client');
|
5
|
-
var client = require('@knapsack/renderer-webpack-base/client');
|
6
|
-
var jsxRuntime = require('react/jsx-runtime');
|
7
|
-
|
8
|
-
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
9
|
-
|
10
|
-
var E__default = /*#__PURE__*/_interopDefault(E);
|
11
|
-
var g__default = /*#__PURE__*/_interopDefault(g);
|
12
|
-
|
13
|
-
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}}=client.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=jsxRuntime.jsx(y,{children:jsxRuntime.jsx(R,{...s,children:jsxRuntime.jsx(M,{})})});g__default.default.createRoot(o).render(d?p:jsxRuntime.jsx(E__default.default.StrictMode,{children:p}));}catch(r){console.error(r);let e=document.createElement("div");e.innerHTML=`
|
14
|
-
<h1>Error</h1>
|
15
|
-
<p>${r.message}</p>
|
16
|
-
`,document.body.appendChild(e);}}n(x,"init");x();});var init = I();
|
17
|
-
|
18
|
-
module.exports = init;
|
19
|
-
//# sourceMappingURL=init.js.map
|
20
|
-
//# sourceMappingURL=init.js.map
|
package/dist/client/init.js.map
DELETED
@@ -1 +0,0 @@
|
|
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":";;;;;;;;;;;;AAAA,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,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AAA,aAAA,CAAc,KAAK,CAAA,CACjDA,EAAa,SAAY,CAAA,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.js","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"]}
|
package/dist/demo-wrapper.d.mts
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
import * as react_jsx_runtime from 'react/jsx-runtime';
|
2
|
-
import { D as DemoWrapperProps } from './types-CivTHEEo.mjs';
|
3
|
-
import '@knapsack/types';
|
4
|
-
|
5
|
-
declare const DemoWrapper: ({ children }: DemoWrapperProps) => react_jsx_runtime.JSX.Element;
|
6
|
-
|
7
|
-
export { DemoWrapper as default };
|
package/dist/demo-wrapper.d.ts
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
import * as react_jsx_runtime from 'react/jsx-runtime';
|
2
|
-
import { D as DemoWrapperProps } from './types-CivTHEEo.js';
|
3
|
-
import '@knapsack/types';
|
4
|
-
|
5
|
-
declare const DemoWrapper: ({ children }: DemoWrapperProps) => react_jsx_runtime.JSX.Element;
|
6
|
-
|
7
|
-
export { DemoWrapper as default };
|
package/dist/demo-wrapper.js
DELETED
@@ -1,9 +0,0 @@
|
|
1
|
-
'use strict';
|
2
|
-
|
3
|
-
var jsxRuntime = require('react/jsx-runtime');
|
4
|
-
|
5
|
-
var o=Object.defineProperty;var e=(p,r)=>o(p,"name",{value:r,configurable:!0});var a=e(({children:p})=>jsxRuntime.jsx("div",{className:"demo-wrapper",children:p}),"DemoWrapper"),d=a;
|
6
|
-
|
7
|
-
module.exports = d;
|
8
|
-
//# sourceMappingURL=demo-wrapper.js.map
|
9
|
-
//# sourceMappingURL=demo-wrapper.js.map
|
package/dist/demo-wrapper.js.map
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"sources":["../src/demo-wrapper.tsx"],"names":["DemoWrapper","__name","children","jsx","demo_wrapper_default"],"mappings":";;;;AAGE,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,CADF,IAAMA,EAAcC,CAAA,CAAA,CAAC,CAAE,QAAAC,CAAAA,CAAS,CAC9BC,GAAAA,cAAAA,CAAC,OAAI,SAAU,CAAA,cAAA,CAAgB,SAAAD,CAAS,CAAA,CAAA,CADtB,eAIbE,CAAQJ,CAAAA","file":"demo-wrapper.js","sourcesContent":["import type { DemoWrapperProps } from './types';\n\nconst DemoWrapper = ({ children }: DemoWrapperProps) => (\n <div className=\"demo-wrapper\">{children}</div>\n);\n\nexport default DemoWrapper;\n"]}
|
package/dist/demo-wrapper.mjs
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
import { jsx } from 'react/jsx-runtime';
|
2
|
-
|
3
|
-
var o=Object.defineProperty;var e=(p,r)=>o(p,"name",{value:r,configurable:!0});var a=e(({children:p})=>jsx("div",{className:"demo-wrapper",children:p}),"DemoWrapper"),d=a;
|
4
|
-
|
5
|
-
export { d as default };
|
6
|
-
//# sourceMappingURL=demo-wrapper.mjs.map
|
7
|
-
//# sourceMappingURL=demo-wrapper.mjs.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"sources":["../src/demo-wrapper.tsx"],"names":["DemoWrapper","__name","children","jsx","demo_wrapper_default"],"mappings":";;AAGE,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,CADF,IAAMA,EAAcC,CAAA,CAAA,CAAC,CAAE,QAAAC,CAAAA,CAAS,CAC9BC,GAAAA,GAAAA,CAAC,OAAI,SAAU,CAAA,cAAA,CAAgB,SAAAD,CAAS,CAAA,CAAA,CADtB,eAIbE,CAAQJ,CAAAA","file":"demo-wrapper.mjs","sourcesContent":["import type { DemoWrapperProps } from './types';\n\nconst DemoWrapper = ({ children }: DemoWrapperProps) => (\n <div className=\"demo-wrapper\">{children}</div>\n);\n\nexport default DemoWrapper;\n"]}
|
package/dist/error-catcher.d.mts
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
import * as react_jsx_runtime from 'react/jsx-runtime';
|
2
|
-
import * as React from 'react';
|
3
|
-
|
4
|
-
type State = {
|
5
|
-
hasError: boolean;
|
6
|
-
componentStack?: string;
|
7
|
-
error?: Error;
|
8
|
-
};
|
9
|
-
declare class ErrorCatcher extends React.Component<{
|
10
|
-
children: React.ReactNode;
|
11
|
-
}, State> {
|
12
|
-
constructor(props: any);
|
13
|
-
static getDerivedStateFromError(error: Error): {
|
14
|
-
hasError: boolean;
|
15
|
-
};
|
16
|
-
componentDidCatch(error: Error, errorInfo: React.ErrorInfo): void;
|
17
|
-
render(): string | number | boolean | Iterable<React.ReactNode> | react_jsx_runtime.JSX.Element;
|
18
|
-
}
|
19
|
-
|
20
|
-
export { ErrorCatcher as default };
|
package/dist/error-catcher.d.ts
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
import * as react_jsx_runtime from 'react/jsx-runtime';
|
2
|
-
import * as React from 'react';
|
3
|
-
|
4
|
-
type State = {
|
5
|
-
hasError: boolean;
|
6
|
-
componentStack?: string;
|
7
|
-
error?: Error;
|
8
|
-
};
|
9
|
-
declare class ErrorCatcher extends React.Component<{
|
10
|
-
children: React.ReactNode;
|
11
|
-
}, State> {
|
12
|
-
constructor(props: any);
|
13
|
-
static getDerivedStateFromError(error: Error): {
|
14
|
-
hasError: boolean;
|
15
|
-
};
|
16
|
-
componentDidCatch(error: Error, errorInfo: React.ErrorInfo): void;
|
17
|
-
render(): string | number | boolean | Iterable<React.ReactNode> | react_jsx_runtime.JSX.Element;
|
18
|
-
}
|
19
|
-
|
20
|
-
export { ErrorCatcher as default };
|
package/dist/error-catcher.js
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
'use strict';
|
2
|
-
|
3
|
-
var n = require('react');
|
4
|
-
var jsxRuntime = require('react/jsx-runtime');
|
5
|
-
|
6
|
-
function _interopNamespace(e) {
|
7
|
-
if (e && e.__esModule) return e;
|
8
|
-
var n = Object.create(null);
|
9
|
-
if (e) {
|
10
|
-
Object.keys(e).forEach(function (k) {
|
11
|
-
if (k !== 'default') {
|
12
|
-
var d = Object.getOwnPropertyDescriptor(e, k);
|
13
|
-
Object.defineProperty(n, k, d.get ? d : {
|
14
|
-
enumerable: true,
|
15
|
-
get: function () { return e[k]; }
|
16
|
-
});
|
17
|
-
}
|
18
|
-
});
|
19
|
-
}
|
20
|
-
n.default = e;
|
21
|
-
return Object.freeze(n);
|
22
|
-
}
|
23
|
-
|
24
|
-
var n__namespace = /*#__PURE__*/_interopNamespace(n);
|
25
|
-
|
26
|
-
var d=Object.defineProperty;var a=(s,t)=>d(s,"name",{value:t,configurable:!0});var o=class extends n__namespace.Component{static{a(this,"ErrorCatcher");}constructor(t){super(t),this.state={hasError:!1,componentStack:"",error:null};}static getDerivedStateFromError(t){return {hasError:!0}}componentDidCatch(t,h){let{componentStack:i}=h;this.setState({error:t,componentStack:i});}render(){return this.state.hasError?jsxRuntime.jsxs("div",{style:{padding:"5px"},children:[jsxRuntime.jsx("h5",{children:"Error caught in React Components"}),this.state.error?.name&&jsxRuntime.jsxs("h5",{children:["Error Name: ",jsxRuntime.jsx("code",{children:this.state.error?.name})]}),this.state.error?.message&&jsxRuntime.jsxs("h5",{children:["Message:",this.state.error?.message]}),this.state.componentStack&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("h6",{children:"Component Stack:"}),jsxRuntime.jsx("pre",{children:jsxRuntime.jsx("code",{children:this.state.componentStack})}),jsxRuntime.jsx("br",{})]}),this.state.error?.stack&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("h6",{children:"Error Stack:"}),jsxRuntime.jsx("pre",{children:jsxRuntime.jsx("code",{children:this.state.error?.stack})})]})]}):this.props.children}};
|
27
|
-
|
28
|
-
module.exports = o;
|
29
|
-
//# sourceMappingURL=error-catcher.js.map
|
30
|
-
//# sourceMappingURL=error-catcher.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"sources":["../src/error-catcher.tsx"],"names":["ErrorCatcher","n","__name","props","error","errorInfo","componentStack","jsxs","jsx","Fragment"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,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,KAQqBA,CAArB,CAAA,cAAgDC,sBAG9C,CAXF,OAWEC,CAAA,CAAA,IAAA,CAAA,cAAA,EAAA,CACA,WAAYC,CAAAA,CAAAA,CAAO,CACjB,KAAMA,CAAAA,CAAK,CACX,CAAA,IAAA,CAAK,MAAQ,CACX,QAAA,CAAU,CACV,CAAA,CAAA,cAAA,CAAgB,GAChB,KAAO,CAAA,IACT,EACF,CAEA,OAAO,yBAAyBC,CAAc,CAAA,CAE5C,OAAO,CACL,SAAU,CACZ,CAAA,CACF,CAES,iBAAA,CAAkBA,EAAcC,CAAkC,CAAA,CACzE,GAAM,CAAE,eAAAC,CAAe,CAAA,CAAID,EAC3B,IAAK,CAAA,QAAA,CAAS,CACZ,KAAAD,CAAAA,CA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G,IAAK,CAAA,KAAA,CAAM,QACpB,CACF","file":"error-catcher.js","sourcesContent":["import * as React from 'react';\n\ntype State = {\n hasError: boolean;\n componentStack?: string;\n error?: Error;\n};\n\nexport default class ErrorCatcher extends React.Component<\n { children: React.ReactNode },\n State\n> {\n constructor(props) {\n super(props);\n this.state = {\n hasError: false,\n componentStack: '',\n error: null,\n };\n }\n\n static getDerivedStateFromError(error: Error) {\n // Update state so the next render will show the fallback UI.\n return {\n hasError: true,\n };\n }\n\n override componentDidCatch(error: Error, errorInfo: React.ErrorInfo): void {\n const { componentStack } = errorInfo;\n this.setState({\n error,\n componentStack,\n });\n }\n\n override render() {\n if (this.state.hasError) {\n return (\n <div\n style={{\n padding: '5px',\n }}\n >\n <h5>Error caught in React Components</h5>\n {this.state.error?.name && (\n <h5>\n Error Name: <code>{this.state.error?.name}</code>\n </h5>\n )}\n {this.state.error?.message && (\n <h5>\n Message:\n {this.state.error?.message}\n </h5>\n )}\n {this.state.componentStack && (\n <>\n <h6>Component Stack:</h6>\n <pre>\n <code>{this.state.componentStack}</code>\n </pre>\n <br />\n </>\n )}\n {this.state.error?.stack && (\n <>\n <h6>Error Stack:</h6>\n <pre>\n <code>{this.state.error?.stack}</code>\n </pre>\n </>\n )}\n </div>\n );\n }\n\n return this.props.children;\n }\n}\n"]}
|
package/dist/error-catcher.mjs
DELETED
@@ -1,8 +0,0 @@
|
|
1
|
-
import * as n from 'react';
|
2
|
-
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
3
|
-
|
4
|
-
var d=Object.defineProperty;var a=(s,t)=>d(s,"name",{value:t,configurable:!0});var o=class extends n.Component{static{a(this,"ErrorCatcher");}constructor(t){super(t),this.state={hasError:!1,componentStack:"",error:null};}static getDerivedStateFromError(t){return {hasError:!0}}componentDidCatch(t,h){let{componentStack:i}=h;this.setState({error:t,componentStack:i});}render(){return this.state.hasError?jsxs("div",{style:{padding:"5px"},children:[jsx("h5",{children:"Error caught in React Components"}),this.state.error?.name&&jsxs("h5",{children:["Error Name: ",jsx("code",{children:this.state.error?.name})]}),this.state.error?.message&&jsxs("h5",{children:["Message:",this.state.error?.message]}),this.state.componentStack&&jsxs(Fragment,{children:[jsx("h6",{children:"Component Stack:"}),jsx("pre",{children:jsx("code",{children:this.state.componentStack})}),jsx("br",{})]}),this.state.error?.stack&&jsxs(Fragment,{children:[jsx("h6",{children:"Error Stack:"}),jsx("pre",{children:jsx("code",{children:this.state.error?.stack})})]})]}):this.props.children}};
|
5
|
-
|
6
|
-
export { o as default };
|
7
|
-
//# sourceMappingURL=error-catcher.mjs.map
|
8
|
-
//# sourceMappingURL=error-catcher.mjs.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"sources":["../src/error-catcher.tsx"],"names":["ErrorCatcher","__name","props","error","errorInfo","componentStack","jsxs","jsx","Fragment"],"mappings":";;;AAAA,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,KAQqBA,CAArB,CAAA,cAAgD,WAG9C,CAXF,OAWEC,CAAA,CAAA,IAAA,CAAA,cAAA,EAAA,CACA,WAAYC,CAAAA,CAAAA,CAAO,CACjB,KAAMA,CAAAA,CAAK,CACX,CAAA,IAAA,CAAK,MAAQ,CACX,QAAA,CAAU,CACV,CAAA,CAAA,cAAA,CAAgB,GAChB,KAAO,CAAA,IACT,EACF,CAEA,OAAO,yBAAyBC,CAAc,CAAA,CAE5C,OAAO,CACL,SAAU,CACZ,CAAA,CACF,CAES,iBAAA,CAAkBA,EAAcC,CAAkC,CAAA,CACzE,GAAM,CAAE,eAAAC,CAAe,CAAA,CAAID,EAC3B,IAAK,CAAA,QAAA,CAAS,CACZ,KAAAD,CAAAA,CAAAA,CACA,cAAAE,CAAAA,CACF,CAAC,EACH,CAES,M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mjs","sourcesContent":["import * as React from 'react';\n\ntype State = {\n hasError: boolean;\n componentStack?: string;\n error?: Error;\n};\n\nexport default class ErrorCatcher extends React.Component<\n { children: React.ReactNode },\n State\n> {\n constructor(props) {\n super(props);\n this.state = {\n hasError: false,\n componentStack: '',\n error: null,\n };\n }\n\n static getDerivedStateFromError(error: Error) {\n // Update state so the next render will show the fallback UI.\n return {\n hasError: true,\n };\n }\n\n override componentDidCatch(error: Error, errorInfo: React.ErrorInfo): void {\n const { componentStack } = errorInfo;\n this.setState({\n error,\n componentStack,\n });\n }\n\n override render() {\n if (this.state.hasError) {\n return (\n <div\n style={{\n padding: '5px',\n }}\n >\n <h5>Error caught in React Components</h5>\n {this.state.error?.name && (\n <h5>\n Error Name: <code>{this.state.error?.name}</code>\n </h5>\n )}\n {this.state.error?.message && (\n <h5>\n Message:\n {this.state.error?.message}\n </h5>\n )}\n {this.state.componentStack && (\n <>\n <h6>Component Stack:</h6>\n <pre>\n <code>{this.state.componentStack}</code>\n </pre>\n <br />\n </>\n )}\n {this.state.error?.stack && (\n <>\n <h6>Error Stack:</h6>\n <pre>\n <code>{this.state.error?.stack}</code>\n </pre>\n </>\n )}\n </div>\n );\n }\n\n return this.props.children;\n }\n}\n"]}
|
package/dist/index.mjs
DELETED
@@ -1,47 +0,0 @@
|
|
1
|
-
import ke from 'sleep-promise';
|
2
|
-
import { RendererWebpackBase, convertImportMapToNeededImportsByCodeSrcId } from '@knapsack/renderer-webpack-base';
|
3
|
-
import { makeShortId, pascalCase, isFirstLetterCapital, removeWrappingDoubleQuotes } from '@knapsack/utils';
|
4
|
-
import { log, knapsackEvents } from '@knapsack/app';
|
5
|
-
import { babelCodeForBrowser, createSlotOptionsHtmlTags } from '@knapsack/app/renderers';
|
6
|
-
import { rendererIds, isNumberProp, isOptionsProp } from '@knapsack/types';
|
7
|
-
import { findUpPkgJson, exists, formatCode, getJsExportNames, readFile, findUp, resolvePath, getModulePkgJson, copy } from '@knapsack/file-utils';
|
8
|
-
import g, { join, parse, relative } from 'path';
|
9
|
-
import { createCreator, tasks } from '@knapsack/creator-utils';
|
10
|
-
import { readKsPatternConfigs, writeDemo, writeKsPatternConfig, readKsNavConfig, addKsNavItems } from '@knapsack/ks-file-utils';
|
11
|
-
|
12
|
-
var Y=Object.defineProperty;var l=(s,t)=>Y(s,"name",{value:t,configurable:!0}),D=(s=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(s,{get:(t,e)=>(typeof require<"u"?require:t)[e]}):s)(function(s){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+s+'" is not supported')});function se({templateName:s,attributes:t,children:e}){return `
|
13
|
-
<${s}
|
14
|
-
${t}
|
15
|
-
${e?`>
|
16
|
-
${e}
|
17
|
-
</${s}>`:"/>"}
|
18
|
-
`}l(se,"renderUsageTemplate");var E="DemoApp";function ae({imports:s="",children:t}){return `${s}
|
19
|
-
|
20
|
-
function ${E}() {
|
21
|
-
return (
|
22
|
-
${t}
|
23
|
-
)
|
24
|
-
}
|
25
|
-
`}l(ae,"renderDemoAppTemplate");async function O(s){let t=Object.keys(s.props||{}).map(a=>{let o=s.props[a];return {key:a,value:o}}),{templateName:e,children:r,extraProps:n=[]}=s;if(!e)throw new Error('Cannot getUsage of a React Component when no "templateName" is provided.');let i=t.map(({key:a,value:o})=>{switch(typeof o){case"string":return o.startsWith("(")&&o.includes("=>")?`${a}={${o}}`:`${a}="${o}"`;case"boolean":return o?`${a}`:`${a}={${o}}`;default:return `${a}={${JSON.stringify(o)}}`}}),p=[],u={};n.forEach(({key:a,value:o})=>{u[a]=u[a]??[],u[a].push(o);}),Object.entries(u).forEach(([a,o])=>{let d=o.length===1?o[0]:`<>${o.join(`
|
26
|
-
`)}</>`;p.push(`${a}={${d}}`);});let c=se({templateName:e,attributes:[...i,...p].join(" "),children:r});return s.format?formatCode({contents:c,path:"x.tsx"}).then(a=>a.trim()).catch(()=>c.trim()):c.trim()}l(O,"getUsage");async function v({children:s,imports:t,format:e}){let r=ae({children:s,imports:t});return e?formatCode({contents:r,path:"x.tsx"}):r}l(v,"getDemoAppUsage");async function J({src:s}){let t=await findUp("tsconfig.json",{cwd:g.dirname(s)}),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)(s)}}l(J,"getTypeScriptInfoFromFile");function ne({info:s,exportName:t}){try{if(!s)return !1;let e={props:{$schema:"http://json-schema.org/draft-07/schema",type:"object",required:[],properties:{}},slots:{}},n=!t||t==="default"?s.pop():s.find(p=>p.displayName===t);if(!n)return !1;return Object.entries(n?.props||{}).forEach(([p,u])=>{let{name:c,description:a,defaultValue:o,required:d,type:f,parent:y}=u;switch(f?.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":o&&"value"in o&&(o.value=o.value==="true"),e.props.properties[p]={type:"boolean"};break;case"enum":e.props.properties[p]={type:"string",enum:[...new Set(f.value.map(({value:h})=>removeWrappingDoubleQuotes(h?.trim())).filter(Boolean))]};break;case"ReactNode":case"React.ReactNode":case"React.ReactElement":case"ReactElement":e.slots[p]={title:p},a&&(e.slots[p]={...e.slots[p],description:a});break;case"VFC":case"FC":e.slots[p]={title:p,description:a||"A reference to a component",isTemplateReference:!0,allowOnlyOne:!0,disallowText:!0};break;default:if(f?.name?.startsWith("("))e.props.properties[p]={typeof:"function",tsType:u?.type?.name};else if(f?.name?.includes("|")){let h=f.name.split("|").map(R=>removeWrappingDoubleQuotes(R.trim())).filter(Boolean);h?.length&&(e.props.properties[p]={type:"string",enum:[...new Set(h)]});}else e.props.properties[p]={tsType:u?.type?.name};}e.props.properties[p]&&(d&&e.props.required.push(p),a&&!e.props.properties[p].description&&(e.props.properties[p].description=a),o&&"value"in o&&(isNumberProp(e.props.properties[p])?e.props.properties[p].default=parseFloat(o.value):e.props.properties[p].default=removeWrappingDoubleQuotes(o.value)));}),e}catch(e){return log.verbose("Could not infer spec from React TypeScript file",{exportName:t,error:e},"react renderer"),!1}}l(ne,"extractSpecFromTypeScriptInfo");async function oe({src:s}){let t=await import('react-docgen'),{builtinResolvers:e}=t,r=await readFile(s),{FindExportedDefinitionsResolver:n}=e;return {info:t.parse(r,{resolver:new n,handlers:null,filename:s})}}l(oe,"getPropTypesInfoFromFile");function ie({info:s,exportName:t}){try{let r=!t||t==="default"?s.pop():s.find(i=>i.displayName===t),n={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:u,description:c,defaultValue:a}=p;switch(p?.type?.name){case"string":n.props.properties[i]={type:"string"};break;case"func":n.props.properties[i]={type:"string"};break;case"bool":n.props.properties[i]={type:"boolean"};break;case"node":n.slots[i]={title:i,description:c};}n.props.properties[i]&&(u&&n.props.required.push(i),c&&!n.props.properties[i].description&&(n.props.properties[i].description=c),a&&"value"in a&&(n.props.properties[i].default=typeof a.value=="string"?removeWrappingDoubleQuotes(a.value):a.value));}),n}catch(e){return log.verbose("Could not infer spec from React PropTypes",{exportName:t,error:e},"react renderer"),!1}}l(ie,"extractSpecFromPropTypesInfo");function pe({spec:s}){return s===!1||Object.entries(s?.props?.properties||{}).forEach(([t,e])=>{isOptionsProp(e)&&(e.enum.includes(e.default)||(e.default=void 0));}),s}l(pe,"cleanUpSpec");async function ce({src:s,resolveFromDir:t}){let e=await resolvePath({path:s,resolveFromDir:t,resolveType:"types"});if(e.exists){let i=await J({src:e.absolutePath});if(i)return {type:"typescript",info:i.info}}let r=await resolvePath({path:s,resolveFromDir:t});if(!r.exists)return {type:"unknown"};let{ext:n}=g.parse(r.absolutePath);switch(n){case".jsx":return {type:"propTypes",info:(await oe({src:r.absolutePath})).info};case".ts":case".tsx":return {type:"typescript",info:(await J({src:r.absolutePath})).info};default:return {type:"unknown"}}}l(ce,"getReactModuleInfoUncached");var S=new Map,q=l(()=>{log.info("Clearing React TypeScript inferSpec cache..."),S.clear();},"clearInferSpecCache");async function le(s){let t=JSON.stringify(s);return S.has(t)||S.set(t,ce(s)),S.get(t)}l(le,"getReactModuleInfo");async function de({src:s,exportName:t,resolveFromDir:e}){let r=await le({src:s,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}}l(de,"getReactSpec");async function B(s){return pe({spec:await de(s)})}l(B,"getReactDocs");async function _(s,t){try{let{version:e}=getModulePkgJson("react"),{version:r}=getModulePkgJson("react-dom"),n=g.dirname(D.resolve("react",{paths:[process.cwd()]})),i=g.dirname(D.resolve("react-dom",{paths:[process.cwd()]}));await Promise.all([copy(g.join(n,"umd/react.development.js"),g.join(s,`react.development.${e}.js`)),copy(g.join(n,"umd/react.production.min.js"),g.join(s,`react.production.min.${e}.js`)),copy(g.join(i,"umd/react-dom.production.min.js"),g.join(s,`react-dom.production.min.${r}.js`)),copy(g.join(i,"umd/react-dom.development.js"),g.join(s,`react-dom.development.${r}.js`))]);let p=process.env.NODE_ENV==="production"?"production.min":"development";return [g.join(t,`react.${p}.${e}.js`),g.join(t,`react-dom.${p}.${r}.js`)]}catch(e){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);}}l(_,"copyReactAssets");function Re(s){return s.toUpperCase()===s}l(Re,"isCapitalLetter");function be(s){return Re(s[0])}l(be,"startsWithCapitalLetter");function Te({importName:s,id:t,title:e=s,pkgPath:r,initialDemoId:n}){return {id:t,title:e,description:"",statuses:{main:"ready"},templates:[{id:"react",title:"react",path:r,alias:s,templateLanguageId:"react",spec:{isInferred:!0},demoIds:[n],blockIds:[]}],tabs:[{type:"template",id:"react"}],subPages:[]}}l(Te,"createPatternData");var N=createCreator({id:"react-patterns",title:"React Ks Patterns",description:"Adds React templates as Knapsack Patterns",getQuestions:l(async()=>({pkgPath:{type:"text",title:"Package path"},importPrefix:{type:"text",title:"Import Prefix to Remove"}}),"getQuestions"),getTasks:l(async({answers:{pkgPath:s,importPrefix:t=""},config:e})=>{let r=e.dest,i=(await readKsPatternConfigs({dataDir:r})).reduce((u,c)=>{let a=c.templates?.filter(o=>o.templateLanguageId==="react")??[];return u.push(...a.map(o=>o.alias)),u},[]),{exports:p}=await getJsExportNames({path:s});return [{title:"Pick Imports to add",task:l((u,c)=>tasks.runSubCreator({task:c,config:e,creator:createCreator({id:"react-pattern-import-names",getQuestions:l(async()=>({importNames:{type:"choices",choices:p.filter(a=>be(a)&&!i.includes(a)).map(a=>({value:a}))}}),"getQuestions"),getTasks:l(async({answers:{importNames:a}})=>{let o=a.map(d=>({importName:d,patternId:d.startsWith(t)?d.slice(t.length).toLowerCase():d.toLowerCase()}));return [...o.map(({importName:d,patternId:f})=>({title:`Add ${d} React Template`,task:l(async(y,b)=>{let h={type:"data",id:makeShortId(),title:"Main",patternId:f,templateId:"react",data:{props:{},slots:{}}},R=Te({id:f,importName:d,pkgPath:s,initialDemoId:h.id});await Promise.all([writeDemo({dataDir:r,demo:h}),writeKsPatternConfig({dataDir:r,patternId:f,data:R})]);},"task")})),{title:"Updating Nav",task:l(async(d,f)=>{let{byId:y}=await readKsNavConfig({dataDir:r}),b=Object.values(y).find(({path:h,name:R,id:X})=>h?!1:R.toLowerCase()==="patterns"||R.toLowerCase()==="components");await addKsNavItems({dataDir:r,navItems:o.map(({patternId:h})=>({navId:h,navPath:`/pattern/${h}`,navParent:b?.id||"root"}))});},"task")}]},"getTasks")})}),"task")}]},"getTasks")});var G="ks-react-meta";var{pkg:I}=findUpPkgJson(__dirname);log.setupUpdateNotifier({...I,name:I.name,version:I.version});var A=join(__dirname,"./error-catcher.mjs");if(!exists(A))throw new Error(`Could not find error catcher at: ${A}`);var H=class s extends RendererWebpackBase{static{l(this,"KnapsackReactRenderer");}assets;babelConfig;#e;#t;constructor({webpackConfig:t,demoWrapperPath:e=join(__dirname,"./demo-wrapper.mjs"),id:r=rendererIds.react,disableReactStrictMode:n}={}){super({id:r,language:"jsx",webpackConfig:t,extraScripts:["@knapsack/renderer-react/client"]}),this.language="jsx",this.assets=[],this.#e=e,this.#t=n,this.creators=[N];}setConfig=l(t=>{super.setConfig(t);let{absolutePath:e,exists:r,type:n}=this.resolvePathSync({path:this.#e,resolveFromDir:this.userConfigDir});if(!r)throw new Error(`Could not find demo wrapper at: "${this.#e}"
|
27
|
-
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:n==="package"?this.#e:e},ErrorCatcher:{exportName:"ErrorCatcher",isDefaultExport:!0,path:A}});},"setConfig");init=l(async()=>{this.assets=await _(this.outputDir,this.publicPath);},"init");hydrate=l(async t=>{await super.hydrate(t),await this.init({missingFileVerbosity:"silent"});},"hydrate");getMeta=l(()=>({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:I.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=l(t=>pascalCase(t),"changeCase");createWebpackConfig=l(()=>{let t=super.createWebpackConfig();return t.externals={react:"React","react-dom":"ReactDOM"},t},"createWebpackConfig");async prepClientRenderResults({usage:t,demoApp:e,importMap:r,renderOptions:{demo:n,state:i,patternId:p,templateId:u}}){let c={demo:n,disableReactStrictMode:this.#t,neededImportsByCodeSrcId:convertImportMapToNeededImportsByCodeSrcId(r),demoWrapperProps:{patternId:p,templateId:u,demo:n}},a=`
|
28
|
-
window.knapsack = window.knapsack || {};
|
29
|
-
window.knapsack.getDemoApp = ({ ${[...r.keys()].join(", ")} }) => {
|
30
|
-
${e}
|
31
|
-
return ${E}
|
32
|
-
}
|
33
|
-
`,o="";try{a=await babelCodeForBrowser({code:a});}catch(f){console.log(a),console.log("---original code before babel error ^---"),console.trace(f.message),a=`console.error(${JSON.stringify(f.message)});`,o=`<pre><code>${f.message}</code></pre>`;}let d=`
|
34
|
-
<script type="application/json" id="${G}">${JSON.stringify(c)}</script>
|
35
|
-
<script type="application/javascript">${a}</script>
|
36
|
-
<div id="render-root" class="knapsack-pattern-direct-parent" data-dev-note="Knapsack React Template Wrapper"></div>
|
37
|
-
${this.assets.map(f=>`<script src="${f}"></script>`).join(`
|
38
|
-
`)}
|
39
|
-
${RendererWebpackBase.createHtmlTagsForAssetPaths({assets:this.getWebpackAssetPaths(),scriptTagsAreAsync:!1})}
|
40
|
-
${o}
|
41
|
-
`;return {ok:!o,html:await formatCode({contents:d,path:"x.html"}),usage:t,templateLanguage:this.language}}render=l(async t=>{if(t.demo?.type==="template"){let e=[5,10,20,50,100,1e3,1e3],r,n=0;for(;;)try{let{absolutePath:o,exists:d}=await this.resolvePath(t.demo.templateInfo.path);if(!d)throw new Error(`Template demo file does not exist: ${o}`);r=o;break}catch(o){let d=e[n];if(!d)throw new Error(o);n+=1,await ke(d);}let[i,{usage:p,importMap:u}]=await Promise.all([readFile(r),this.getUsageAndImports({...t,importMap:new Map})]),c=await v({children:p});return await this.prepClientRenderResults({usage:i,demoApp:c,renderOptions:t,importMap:u})}if(t.demo?.type==="data"){let{usage:e,importMap:r}=await this.getUsageAndImports({...t,importMap:new Map}),n=RendererWebpackBase.createJsImportCodeBlock({importMap:r}),[i,p]=await Promise.all([v({children:e,imports:n,format:!0}),v({children:e})]);return this.prepClientRenderResults({demoApp:p,usage:i,renderOptions:t,importMap:r})}},"render");getUsageAndImports=l(async({patternId:t,templateId:e,demo:r,state:n,importMap:i})=>{if(!r)throw new Error(`No demo provided while rendering ${t} ${e}`);let p=n.patterns[t];if(!p)throw new Error(`Could not find pattern: ${t}`);if(r.type==="data"){let c=p.templates.find(R=>R.id===e);if(!c)throw new Error(`Could not find template: ${e}`);let{data:{props:a,slots:o,slotsOptionsComputed:d}}=r,{name:f}=await this.addUniqueValueToImportMap({importMap:i,path:c.path,alias:c.alias||"default"}),y=[],b=[];if(o){let R=Object.keys(o);(await Promise.all(R.map(async w=>{let T=o[w],j=await Promise.all(T.filter(m=>!(!m||m.type!=="text"&&(!m.patternId||!m.templateId||m.type==="template-demo"&&!m.demoId))).map(async m=>{if(m.type==="text")return T.length===1&&w!=="children"?`\`${m.text}\``:m.text;if(m.type==="template-reference"){let P=n.patterns[m.patternId]?.templates.find(z=>z.id===m.templateId);if(!P)throw new Error(`Could not find slotted template: ${m.patternId} ${m.templateId}`);return (await this.addUniqueValueToImportMap({importMap:i,path:P.path,alias:P.alias||"default"})).name}if(m.type==="template-demo"){let P=m.demo;if(!P)throw new Error(`Could not find slotted template demo ${JSON.stringify(m)}`);let{usage:K}=await this.getUsageAndImports({patternId:P.patternId,templateId:P.templateId,demo:P,state:n,importMap:i});return K}throw new Error(`Unknown slot item: ${JSON.stringify(m)}`)}));return {slotName:w,slotItemsUsages:j}}))).forEach(({slotName:w,slotItemsUsages:T})=>{let j=d?.[w],{openTag:m,closeTag:k}=createSlotOptionsHtmlTags({slotOptionsComputed:j,classAttributeName:"className",stylesValueType:"object"});m&&(w==="children"?y.push(m):b.push({key:w,value:m})),T.forEach(P=>{w==="children"?y.push(P):b.push({key:w,value:P});}),k&&(w==="children"?y.push(k):b.push({key:w,value:k}));});}return {usage:await O({templateName:f,props:a,children:y.join(`
|
42
|
-
`),extraProps:b}),importMap:i}}if(r.type==="template"){let{templateInfo:c}=r,{name:a}=await this.addUniqueValueToImportMap({importMap:i,path:c.path,alias:c.alias||"default"});return {usage:await O({templateName:a}),importMap:i}}throw new Error(`Unhandled demo type for ${t}-${e}: ${JSON.stringify(r)}`)},"getUsageAndImports");inferSpec=l(async({template:t,templatePath:e})=>{let r=await B({src:t.path,exportName:t.alias||"default",resolveFromDir:this.config.data});if(r!==!1){let n=Object.keys(r?.props?.properties||{}).length,i=Object.keys(r?.slots||{}).length;if(n===0&&i===0)return !1}return r},"inferSpec");watch=l(async()=>{super.watch(),knapsackEvents.onPatternTemplateChanged(()=>{q();});},"watch");getTemplateMeta=l(async({pattern:t,template:e})=>{let r=[];if(e?.spec?.props){let n=JSON.parse(JSON.stringify(e.spec.props));e?.spec?.slots&&Object.entries(e.spec.slots).forEach(([p,u])=>{n.properties[p]={typeof:"function",tsType:"React.ReactNode",description:u.allowedPatternIds?`${u.description}. Only use: ${u.allowedPatternIds.join(", ")}`:u.description},n.required=n.required??[],u.isRequired&&n.required.push(p);});let i=await s.convertSchemaToTypeScriptDefs({schema:n,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(n,null," "),encoding:"utf8",path:`${t.id}.${e.id}.spec.json`});}return r},"getTemplateMeta");alterTemplateMetaFiles=l(async({files:t,metaDir:e})=>{let r=[],n=".spec.d.ts";return t.forEach(i=>{if(i.path.endsWith(n)){let{base:p}=parse(i.path),[u,c]=p.split("."),a=c===this.id,o=this.changeCase(`${u}Props`),d=this.changeCase(`${u}-${c}Props`);r.push(`export { ${a?o:`${o} as ${d}`} } from './${relative(e,i.path).replace(".d.ts","")}';`);}}),r.push(""),[...t,{contents:r.join(`
|
43
|
-
`),encoding:"utf8",path:join(e,"react.d.ts")}]},"alterTemplateMetaFiles");getTemplateSuggestions=l(async({newPath:t,state:e})=>{let r=Object.values(e.patterns).reduce((c,{templateDemos:a,templates:o})=>(o.forEach(({path:d,alias:f,templateLanguageId:y})=>{y===this.id&&c.push({path:d,alias:f});}),a.forEach(({templateInfo:{path:d,alias:f},templateLanguageId:y})=>{y===this.id&&c.push({path:d,alias:f});}),c),[]),n=new Set(this.getCodeSrcs().map(({path:c})=>c)),i=[...new Set([t,...Object.keys(this.pkgPathAliases||{}),...n])];return {suggestions:(await Promise.all(i.map(async c=>{if(!c)return [];try{let{exports:a,errorMsg:o}=await getJsExportNames({path:c,resolveFromDir:this.dataDir,pkgPathAliases:this.pkgPathAliases});if(o)throw new Error(o);return a.filter(d=>d==="default"||isFirstLetterCapital(d)).map(d=>({alias:d,path:c}))}catch(a){return log.verbose(`Error getting import names for ${c}: ${a.message}`,null,this.logPrefix),[]}})).then(c=>c.flat())).filter(c=>!r.find(a=>a.alias===c.alias&&a.path===c.path))}},"getTemplateSuggestions")};
|
44
|
-
|
45
|
-
export { H as KnapsackReactRenderer };
|
46
|
-
//# sourceMappingURL=index.mjs.map
|
47
|
-
//# sourceMappingURL=index.mjs.map
|