@knapsack/renderer-react 4.71.16--canary.5224.facfa79.0 → 4.71.16--canary.5239.d839174.0
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +29 -0
- package/ava.config.cjs +1 -7
- package/dist/client/init.d.mts +2 -2
- package/dist/client/init.d.ts +2 -0
- package/dist/client/init.js +5 -0
- package/dist/client/init.js.map +1 -0
- package/dist/client/init.mjs +3 -39
- package/dist/client/init.mjs.map +1 -1
- package/dist/demo-wrapper.d.mts +7 -0
- package/dist/demo-wrapper.d.ts +7 -0
- package/dist/demo-wrapper.js +2 -0
- package/dist/demo-wrapper.js.map +1 -0
- package/dist/demo-wrapper.mjs +2 -0
- package/dist/demo-wrapper.mjs.map +1 -0
- package/dist/error-catcher.d.mts +20 -0
- package/dist/error-catcher.d.ts +20 -0
- package/dist/error-catcher.js +2 -0
- package/dist/error-catcher.js.map +1 -0
- package/dist/error-catcher.mjs +2 -0
- package/dist/error-catcher.mjs.map +1 -0
- package/dist/{renderer-react.d.ts → index.d.mts} +5 -2
- package/dist/index.d.ts +45 -3
- package/dist/index.js +31 -16
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +33 -0
- package/dist/index.mjs.map +1 -0
- package/dist/prototype-template.d.mts +7 -0
- package/dist/prototype-template.d.ts +7 -0
- package/dist/prototype-template.js +2 -0
- package/dist/prototype-template.js.map +1 -0
- package/dist/prototype-template.mjs +2 -0
- package/dist/prototype-template.mjs.map +1 -0
- package/dist/types-CivTHEEo.d.mts +10 -0
- package/dist/types-CivTHEEo.d.ts +10 -0
- package/package.json +27 -23
- package/tsconfig.json +2 -2
- package/tsup.config.cjs +5 -0
- package/dist/analyze/infer-spec.test.d.ts +0 -2
- package/dist/analyze/infer-spec.test.d.ts.map +0 -1
- package/dist/analyze/infer-spec.test.js +0 -112
- package/dist/analyze/infer-spec.test.js.map +0 -1
- package/dist/analyze/mui.test.d.ts +0 -2
- package/dist/analyze/mui.test.d.ts.map +0 -1
- package/dist/analyze/mui.test.js +0 -60
- package/dist/analyze/mui.test.js.map +0 -1
- package/dist/analyze/pkg-basic.test.d.ts +0 -2
- package/dist/analyze/pkg-basic.test.d.ts.map +0 -1
- package/dist/analyze/pkg-basic.test.js +0 -33
- package/dist/analyze/pkg-basic.test.js.map +0 -1
- package/dist/analyze/pkg-diff-types.test.d.ts +0 -2
- package/dist/analyze/pkg-diff-types.test.d.ts.map +0 -1
- package/dist/analyze/pkg-diff-types.test.js +0 -43
- package/dist/analyze/pkg-diff-types.test.js.map +0 -1
- package/dist/client/init.d.mts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/react-creators.d.ts +0 -20
- package/dist/react-creators.d.ts.map +0 -1
- package/dist/react-creators.js +0 -170
- package/dist/react-creators.js.map +0 -1
- package/dist/renderer-react.d.ts.map +0 -1
- package/dist/renderer-react.js +0 -569
- package/dist/renderer-react.js.map +0 -1
- package/dist/types.d.ts +0 -19
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -5
- package/dist/types.js.map +0 -1
- package/dist/utils.d.ts +0 -28
- package/dist/utils.d.ts.map +0 -1
- package/dist/utils.js +0 -500
- package/dist/utils.js.map +0 -1
- package/dist/utils.test.d.ts +0 -2
- package/dist/utils.test.d.ts.map +0 -1
- package/dist/utils.test.js +0 -59
- package/dist/utils.test.js.map +0 -1
- package/prototype-template.d.mts +0 -3
- package/prototype-template.mjs +0 -3
- package/test-fixtures/pkg-diff-types/button.js +0 -10
- package/test-fixtures/pkg-diff-types/package.json +0 -4
- package/test-fixtures/pkg-diff-types/readme.md +0 -1
- package/test-fixtures/pkg-diff-types/types/button.d.ts +0 -5
package/CHANGELOG.md
CHANGED
@@ -1,3 +1,32 @@
|
|
1
|
+
# v4.71.13 (Wed Dec 04 2024)
|
2
|
+
|
3
|
+
#### 🐛 Bug Fix
|
4
|
+
|
5
|
+
- Merge branch 'feature/ksp-5777-gsk-sso-issues' into feature/sso-config-via-db ([@EvanLovely](https://github.com/EvanLovely))
|
6
|
+
- Merge branch 'latest' into feature/ksp-5777-gsk-sso-issues ([@illepic](https://github.com/illepic))
|
7
|
+
- Bump version to: v4.71.12 \[skip ci\] ([@KnapsackBot](https://github.com/KnapsackBot))
|
8
|
+
- Update CHANGELOG.md \[skip ci\] ([@KnapsackBot](https://github.com/KnapsackBot))
|
9
|
+
- Bump version to: v4.71.11 \[skip ci\] ([@KnapsackBot](https://github.com/KnapsackBot))
|
10
|
+
|
11
|
+
#### 🏠 Internal
|
12
|
+
|
13
|
+
- refactor Cypress user login [#5225](https://github.com/knapsack-labs/app-monorepo/pull/5225) ([@EvanLovely](https://github.com/EvanLovely))
|
14
|
+
- Update Node.js to v20.18.1 [#5197](https://github.com/knapsack-labs/app-monorepo/pull/5197) ([@renovate[bot]](https://github.com/renovate[bot]))
|
15
|
+
- adds evt handlers for design src logs [#5194](https://github.com/knapsack-labs/app-monorepo/pull/5194) ([@mabry1985](https://github.com/mabry1985))
|
16
|
+
- setup login w popup [#5209](https://github.com/knapsack-labs/app-monorepo/pull/5209) ([@GormanDesign](https://github.com/GormanDesign) [@mabry1985](https://github.com/mabry1985) [@EvanLovely](https://github.com/EvanLovely) [@KnapsackBot](https://github.com/KnapsackBot) [@illepic](https://github.com/illepic))
|
17
|
+
- migrate to new Figma oAuth endpoints and configuration [#5206](https://github.com/knapsack-labs/app-monorepo/pull/5206) ([@mabry1985](https://github.com/mabry1985))
|
18
|
+
|
19
|
+
#### Authors: 6
|
20
|
+
|
21
|
+
- [@renovate[bot]](https://github.com/renovate[bot])
|
22
|
+
- Christopher Bloom ([@illepic](https://github.com/illepic))
|
23
|
+
- Evan Lovely ([@EvanLovely](https://github.com/EvanLovely))
|
24
|
+
- Josh Mabry ([@mabry1985](https://github.com/mabry1985))
|
25
|
+
- KnapsackBot ([@KnapsackBot](https://github.com/KnapsackBot))
|
26
|
+
- Matt Gorman ([@GormanDesign](https://github.com/GormanDesign))
|
27
|
+
|
28
|
+
---
|
29
|
+
|
1
30
|
# v4.71.12 (Thu Nov 21 2024)
|
2
31
|
|
3
32
|
#### 🐛 Bug Fix
|
package/ava.config.cjs
CHANGED
package/dist/client/init.d.mts
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
|
2
|
+
export { }
|
@@ -0,0 +1,5 @@
|
|
1
|
+
'use strict';var E=require('react'),g=require('react-dom/client'),client=require('@knapsack/renderer-webpack-base/client'),jsxRuntime=require('react/jsx-runtime');function _interopDefault(e){return e&&e.__esModule?e:{default:e}}var E__default=/*#__PURE__*/_interopDefault(E);var g__default=/*#__PURE__*/_interopDefault(g);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=`
|
2
|
+
<h1>Error</h1>
|
3
|
+
<p>${r.message}</p>
|
4
|
+
`,document.body.appendChild(e);}}n(x,"init");x();});var init = I();module.exports=init;//# sourceMappingURL=init.js.map
|
5
|
+
//# sourceMappingURL=init.js.map
|
@@ -0,0 +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","getKsRend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AAAA,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,cAACJ,CAAAA,CAAAA,CAAA,CACC,QAAA,CAAAI,cAACL,CAAAA,CAAAA,CAAA,CAAa,GAAGJ,EACf,QAAAS,CAAAA,cAAAA,CAACF,CAAA,CAAA,EAAQ,CACX,CAAA,CAAA,CACF,CAGFG,CAAAA,kBAAAA,CAAS,WAAWJ,CAAI,CAAA,CAAE,MACxBP,CAAAA,CAAAA,CAAyBS,CAAMC,CAAAA,cAAAA,CAACE,kBAAM,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.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/client/init.mjs
CHANGED
@@ -1,41 +1,5 @@
|
|
1
|
-
|
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 = `
|
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=`
|
34
2
|
<h1>Error</h1>
|
35
|
-
<p>${
|
36
|
-
|
37
|
-
document.body.appendChild(errorElement);
|
38
|
-
}
|
39
|
-
}
|
40
|
-
init();
|
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
|
41
5
|
//# sourceMappingURL=init.mjs.map
|
package/dist/client/init.mjs.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
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,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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"]}
|
@@ -0,0 +1,7 @@
|
|
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 };
|
@@ -0,0 +1,7 @@
|
|
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 };
|
@@ -0,0 +1,2 @@
|
|
1
|
+
'use strict';var jsxRuntime=require('react/jsx-runtime');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;module.exports=d;//# sourceMappingURL=demo-wrapper.js.map
|
2
|
+
//# sourceMappingURL=demo-wrapper.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../src/demo-wrapper.tsx"],"names":["DemoWrapper","__name","children","jsx","demo_wrapper_default"],"mappings":"yDAGE,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"]}
|
@@ -0,0 +1,2 @@
|
|
1
|
+
import {jsx}from'react/jsx-runtime';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;export{d as default};//# sourceMappingURL=demo-wrapper.mjs.map
|
2
|
+
//# sourceMappingURL=demo-wrapper.mjs.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../src/demo-wrapper.tsx"],"names":["DemoWrapper","__name","children","jsx","demo_wrapper_default"],"mappings":"oCAGE,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"]}
|
@@ -0,0 +1,20 @@
|
|
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 };
|
@@ -0,0 +1,20 @@
|
|
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 };
|
@@ -0,0 +1,2 @@
|
|
1
|
+
'use strict';var n=require('react'),jsxRuntime=require('react/jsx-runtime');function _interopNamespace(e){if(e&&e.__esModule)return e;var n=Object.create(null);if(e){Object.keys(e).forEach(function(k){if(k!=='default'){var d=Object.getOwnPropertyDescriptor(e,k);Object.defineProperty(n,k,d.get?d:{enumerable:true,get:function(){return e[k]}});}})}n.default=e;return Object.freeze(n)}var n__namespace=/*#__PURE__*/_interopNamespace(n);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}};module.exports=o;//# sourceMappingURL=error-catcher.js.map
|
2
|
+
//# sourceMappingURL=error-catcher.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../src/error-catcher.tsx"],"names":["ErrorCatcher","n","__name","props","error","errorInfo","componentStack","jsxs","jsx","Fragment"],"mappings":"kbAAA,IAAA,CAAA,CAAA,MAAA,CAAA,cAAA,CAAA,IAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,GAAA,CAAA,CAAA,CAAA,CAAA,MAAA,CAAA,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AAA,CAAgB,EACpBA,cAAC,CAAA,KAAA,CAAA,CACC,QAAAA,CAAAA,cAAAA,CAAC,QAAM,QAAK,CAAA,IAAA,CAAA,KAAA,CAAM,cAAe,CAAA,CAAA,CACnC,EACAA,cAAC,CAAA,IAAA,CAAA,EAAG,CACN,CAAA,CAAA,CAAA,CAED,KAAK,KAAM,CAAA,KAAA,EAAO,OACjBD,eAAAE,CAAAA,mBAAAA,CAAA,CACE,QAAAD,CAAAA,CAAAA,cAAAA,CAAC,IAAG,CAAA,CAAA,QAAA,CAAA,cAAA,CAAY,EAChBA,cAAC,CAAA,KAAA,CAAA,CACC,QAAAA,CAAAA,cAAAA,CAAC,QAAM,QAAK,CAAA,IAAA,CAAA,KAAA,CAAM,KAAO,EAAA,KAAA,CAAM,EACjC,CACF,CAAA,CAAA,CAAA,CAAA,CAEJ,EAIG,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"]}
|
@@ -0,0 +1,2 @@
|
|
1
|
+
import*as n from'react';import {jsxs,jsx,Fragment}from'react/jsx-runtime';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}};export{o as default};//# sourceMappingURL=error-catcher.mjs.map
|
2
|
+
//# sourceMappingURL=error-catcher.mjs.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../src/error-catcher.tsx"],"names":["ErrorCatcher","__name","props","error","errorInfo","componentStack","jsxs","jsx","Fragment"],"mappings":"0EAAA,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,C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ACnC,EACAA,GAAC,CAAA,IAAA,CAAA,EAAG,CACN,CAAA,CAAA,CAAA,CAED,KAAK,KAAM,CAAA,KAAA,EAAO,OACjBD,IAAAE,CAAAA,QAAAA,CAAA,CACE,QAAAD,CAAAA,CAAAA,GAAAA,CAAC,IAAG,CAAA,CAAA,QAAA,CAAA,cAAA,CAAY,EAChBA,GAAC,CAAA,KAAA,CAAA,CACC,QAAAA,CAAAA,GAAAA,CAAC,QAAM,QAAK,CAAA,IAAA,CAAA,KAAA,CAAM,KAAO,EAAA,KAAA,CAAM,EACjC,CACF,CAAA,CAAA,CAAA,CAAA,CAEJ,EAIG,IAAK,CAAA,KAAA,CAAM,QACpB,CACF","file":"error-catcher.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"]}
|
@@ -1,7 +1,9 @@
|
|
1
1
|
import { RendererWebpackBase, Renderer, KsJsImportMap } from '@knapsack/renderer-webpack-base';
|
2
2
|
import { Renderable } from '@knapsack/app/renderers';
|
3
3
|
import { RendererId } from '@knapsack/types';
|
4
|
-
export
|
4
|
+
export { D as DemoWrapperProps } from './types-CivTHEEo.mjs';
|
5
|
+
|
6
|
+
declare class KnapsackReactRenderer extends RendererWebpackBase implements Renderable {
|
5
7
|
#private;
|
6
8
|
/**
|
7
9
|
* `react.js` & `react-dom.js` root relative paths
|
@@ -39,4 +41,5 @@ export declare class KnapsackReactRenderer extends RendererWebpackBase implement
|
|
39
41
|
alterTemplateMetaFiles: Renderer['alterTemplateMetaFiles'];
|
40
42
|
getTemplateSuggestions: Renderer['getTemplateSuggestions'];
|
41
43
|
}
|
42
|
-
|
44
|
+
|
45
|
+
export { KnapsackReactRenderer };
|
package/dist/index.d.ts
CHANGED
@@ -1,3 +1,45 @@
|
|
1
|
-
|
2
|
-
|
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 };
|
package/dist/index.js
CHANGED
@@ -1,18 +1,33 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
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}
|
7
21
|
}
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
})
|
13
|
-
|
14
|
-
|
15
|
-
}
|
16
|
-
Object.
|
17
|
-
|
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
|
18
33
|
//# sourceMappingURL=index.js.map
|