@makeswift/runtime 0.28.10-canary.5 → 0.28.10-canary.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/api/graphql-api-client.js +1 -1
- package/dist/cjs/api/rest-api-client.js +1 -1
- package/dist/cjs/api-handler/handlers/manifest.js +1 -1
- package/dist/cjs/next/components/tests/controls/page-control-prop-rendering.js +3 -18
- package/dist/cjs/next/components/tests/controls/page-control-prop-rendering.js.map +1 -1
- package/dist/cjs/runtimes/react/react-runtime-core.js +14 -3
- package/dist/cjs/runtimes/react/react-runtime-core.js.map +1 -1
- package/dist/cjs/runtimes/react/server/components/element-data.js +6 -2
- package/dist/cjs/runtimes/react/server/components/element-data.js.map +1 -1
- package/dist/cjs/runtimes/react/server/components/element.js +20 -2
- package/dist/cjs/runtimes/react/server/components/element.js.map +1 -1
- package/dist/cjs/runtimes/react/server/injectable-props.js +17 -0
- package/dist/cjs/runtimes/react/server/injectable-props.js.map +1 -0
- package/dist/cjs/runtimes/react/testing/react-runtime.js +3 -4
- package/dist/cjs/runtimes/react/testing/react-runtime.js.map +1 -1
- package/dist/cjs/runtimes/react/testing/render-to-string.js +44 -0
- package/dist/cjs/runtimes/react/testing/render-to-string.js.map +1 -0
- package/dist/cjs/state/modules/components-meta.js.map +1 -1
- package/dist/esm/api/graphql-api-client.js +1 -1
- package/dist/esm/api/rest-api-client.js +1 -1
- package/dist/esm/api-handler/handlers/manifest.js +1 -1
- package/dist/esm/next/components/tests/controls/page-control-prop-rendering.js +1 -16
- package/dist/esm/next/components/tests/controls/page-control-prop-rendering.js.map +1 -1
- package/dist/esm/runtimes/react/react-runtime-core.js +14 -3
- package/dist/esm/runtimes/react/react-runtime-core.js.map +1 -1
- package/dist/esm/runtimes/react/server/components/element-data.js +6 -2
- package/dist/esm/runtimes/react/server/components/element-data.js.map +1 -1
- package/dist/esm/runtimes/react/server/components/element.js +20 -2
- package/dist/esm/runtimes/react/server/components/element.js.map +1 -1
- package/dist/esm/runtimes/react/server/injectable-props.js +1 -0
- package/dist/esm/runtimes/react/server/injectable-props.js.map +1 -0
- package/dist/esm/runtimes/react/testing/react-runtime.js +3 -4
- package/dist/esm/runtimes/react/testing/react-runtime.js.map +1 -1
- package/dist/esm/runtimes/react/testing/render-to-string.js +20 -0
- package/dist/esm/runtimes/react/testing/render-to-string.js.map +1 -0
- package/dist/esm/state/modules/components-meta.js.map +1 -1
- package/dist/types/next/components/tests/controls/page-control-prop-rendering.d.ts.map +1 -1
- package/dist/types/runtimes/react/react-runtime-core.d.ts +18 -5
- package/dist/types/runtimes/react/react-runtime-core.d.ts.map +1 -1
- package/dist/types/runtimes/react/server/components/__tests__/element.test.d.ts +2 -0
- package/dist/types/runtimes/react/server/components/__tests__/element.test.d.ts.map +1 -0
- package/dist/types/runtimes/react/server/components/element-data.d.ts +2 -1
- package/dist/types/runtimes/react/server/components/element-data.d.ts.map +1 -1
- package/dist/types/runtimes/react/server/components/element.d.ts.map +1 -1
- package/dist/types/runtimes/react/server/injectable-props.d.ts +5 -0
- package/dist/types/runtimes/react/server/injectable-props.d.ts.map +1 -0
- package/dist/types/runtimes/react/testing/react-runtime.d.ts +5 -4
- package/dist/types/runtimes/react/testing/react-runtime.d.ts.map +1 -1
- package/dist/types/runtimes/react/testing/render-to-string.d.ts +3 -0
- package/dist/types/runtimes/react/testing/render-to-string.d.ts.map +1 -0
- package/dist/types/state/modules/components-meta.d.ts +2 -0
- package/dist/types/state/modules/components-meta.d.ts.map +1 -1
- package/package.json +2 -2
|
@@ -27,7 +27,7 @@ class MakeswiftGraphQLApiClient {
|
|
|
27
27
|
graphqlClient;
|
|
28
28
|
constructor({ endpoint }) {
|
|
29
29
|
this.graphqlClient = new import_client.GraphQLClient(endpoint, {
|
|
30
|
-
"makeswift-runtime-version": "0.28.10-canary.
|
|
30
|
+
"makeswift-runtime-version": "0.28.10-canary.6"
|
|
31
31
|
});
|
|
32
32
|
}
|
|
33
33
|
async getUnversionedResources({
|
|
@@ -185,7 +185,7 @@ class MakeswiftRestAPIClient {
|
|
|
185
185
|
const requestHeaders = new Headers({
|
|
186
186
|
"x-api-key": this.apiKey,
|
|
187
187
|
"makeswift-site-api-key": this.apiKey,
|
|
188
|
-
"makeswift-runtime-version": "0.28.10-canary.
|
|
188
|
+
"makeswift-runtime-version": "0.28.10-canary.6"
|
|
189
189
|
});
|
|
190
190
|
if (siteVersion?.token) {
|
|
191
191
|
requestUrl.searchParams.set("version", siteVersion.version);
|
|
@@ -28,7 +28,7 @@ async function manifestHandler(req, { apiKey, manifest }) {
|
|
|
28
28
|
return import_request_response.ApiResponse.json({ message: "Unauthorized" }, { status: 401 });
|
|
29
29
|
}
|
|
30
30
|
return import_request_response.ApiResponse.json({
|
|
31
|
-
version: "0.28.10-canary.
|
|
31
|
+
version: "0.28.10-canary.6",
|
|
32
32
|
interactionMode: true,
|
|
33
33
|
clientSideNavigation: false,
|
|
34
34
|
elementFromPoint: false,
|
|
@@ -33,7 +33,6 @@ __export(page_control_prop_rendering_exports, {
|
|
|
33
33
|
module.exports = __toCommonJS(page_control_prop_rendering_exports);
|
|
34
34
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
35
35
|
var import_react = require("react");
|
|
36
|
-
var import_server = require("react-dom/server");
|
|
37
36
|
var import_jsdom = require("jsdom");
|
|
38
37
|
var import_react2 = require("@testing-library/react");
|
|
39
38
|
var import_jest_dom = require("@testing-library/jest-dom");
|
|
@@ -42,33 +41,19 @@ var import_read_only_actions = require("../../../../state/actions/internal/read-
|
|
|
42
41
|
var import_MakeswiftComponent = require("../../../../runtimes/react/components/MakeswiftComponent");
|
|
43
42
|
var import_page = require("../../page");
|
|
44
43
|
var import_is_server = require("../../../../utils/is-server");
|
|
44
|
+
var import_render_to_string = require("../../../../runtimes/react/testing/render-to-string");
|
|
45
45
|
var Testing = __toESM(require("../../../testing"));
|
|
46
46
|
const ROOT_ID = "00000000-0000-0000-0000-000000000000";
|
|
47
47
|
const ELEMENT_ID = "11111111-1111-1111-1111-111111111111";
|
|
48
48
|
const renderProp = (prop) => prop === void 0 ? "undefined" : (0, import_react.isValidElement)(prop) ? prop : JSON.stringify(prop);
|
|
49
49
|
const propSnapshot = (prop) => prop?.childElementCount ? prop.childNodes : parseStringifiedProp(prop?.textContent ?? "");
|
|
50
50
|
const parseStringifiedProp = (prop) => prop === "undefined" ? void 0 : JSON.parse(prop);
|
|
51
|
-
async function streamToString(stream) {
|
|
52
|
-
const reader = stream.getReader();
|
|
53
|
-
const decoder = new TextDecoder();
|
|
54
|
-
let result = "";
|
|
55
|
-
while (true) {
|
|
56
|
-
const { done, value } = await reader.read();
|
|
57
|
-
if (done)
|
|
58
|
-
break;
|
|
59
|
-
result += decoder.decode(value, { stream: true });
|
|
60
|
-
}
|
|
61
|
-
return result;
|
|
62
|
-
}
|
|
63
|
-
async function renderToString(element) {
|
|
64
|
-
return await streamToString(await (0, import_server.renderToReadableStream)(element));
|
|
65
|
-
}
|
|
66
51
|
async function serverSideRender(children) {
|
|
67
52
|
const serverInsertedCallbacks = [];
|
|
68
53
|
const elementTree = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_navigation.ServerInsertedHTMLContext.Provider, { value: (handler) => serverInsertedCallbacks.push(handler), children });
|
|
69
|
-
const elementsHTML = await renderToString(elementTree);
|
|
54
|
+
const elementsHTML = await (0, import_render_to_string.renderToString)(elementTree);
|
|
70
55
|
const serverInsertedNodes = serverInsertedCallbacks.map((callback, index) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.Fragment, { children: callback() }, "__next_server_inserted__" + index));
|
|
71
|
-
const headHTML = await renderToString(serverInsertedNodes);
|
|
56
|
+
const headHTML = await (0, import_render_to_string.renderToString)(serverInsertedNodes);
|
|
72
57
|
const dom = new import_jsdom.JSDOM(
|
|
73
58
|
`<!DOCTYPE html><head>${headHTML}</head><body><div id="root">${elementsHTML}</div></body></div>`,
|
|
74
59
|
{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../src/next/components/tests/controls/page-control-prop-rendering.tsx"],"sourcesContent":["import { type ReactNode, Fragment, forwardRef, useRef, isValidElement, act } from 'react'\nimport { renderToReadableStream } from 'react-dom/server'\nimport { JSDOM } from 'jsdom'\nimport { render, screen } from '@testing-library/react'\nimport '@testing-library/jest-dom'\nimport { ServerInsertedHTMLContext } from 'next/navigation'\n\nimport { type Data, type ValueType, type DataType, ControlDefinition } from '@makeswift/controls'\n\nimport { type CacheData } from '../../../../api/api-resources-client'\nimport { ElementData } from '../../../../state/read-only-state'\nimport { setIsInBuilder } from '../../../../state/actions/internal/read-only-actions'\nimport { ReactRuntime } from '../../../../runtimes/react/react-runtime'\nimport { MakeswiftComponent } from '../../../../runtimes/react/components/MakeswiftComponent'\nimport { Page } from '../../page'\nimport { isServer } from '../../../../utils/is-server'\nimport * as Testing from '../../../testing'\n\nconst ROOT_ID = '00000000-0000-0000-0000-000000000000'\nconst ELEMENT_ID = '11111111-1111-1111-1111-111111111111'\n\nconst renderProp = (prop: any) =>\n prop === undefined ? 'undefined' : isValidElement(prop) ? prop : JSON.stringify(prop)\n\nconst propSnapshot = (prop: HTMLElement | null) =>\n prop?.childElementCount ? prop.childNodes : parseStringifiedProp(prop?.textContent ?? '')\n\nconst parseStringifiedProp = (prop: string) => (prop === 'undefined' ? undefined : JSON.parse(prop))\n\nasync function streamToString(stream: ReadableStream) {\n const reader = stream.getReader()\n const decoder = new TextDecoder()\n\n let result = ''\n\n while (true) {\n const { done, value } = await reader.read()\n if (done) break\n result += decoder.decode(value, { stream: true })\n }\n\n return result\n}\n\nasync function renderToString(element: ReactNode) {\n return await streamToString(await renderToReadableStream(element))\n}\n\nasync function serverSideRender(children: ReactNode) {\n // wrap the children in a context provider to capture server-inserted HTML, see\n // https://github.com/vercel/next.js/blob/canary/packages/next/src/server/app-render/server-inserted-html.tsx\n const serverInsertedCallbacks: (() => React.ReactNode)[] = []\n\n const elementTree = (\n <ServerInsertedHTMLContext.Provider value={handler => serverInsertedCallbacks.push(handler)}>\n {children}\n </ServerInsertedHTMLContext.Provider>\n )\n\n const elementsHTML = await renderToString(elementTree)\n\n const serverInsertedNodes = serverInsertedCallbacks.map((callback, index) => (\n <Fragment key={'__next_server_inserted__' + index}>{callback()}</Fragment>\n ))\n\n const headHTML = await renderToString(serverInsertedNodes)\n\n const dom = new JSDOM(\n `<!DOCTYPE html><head>${headHTML}</head><body><div id=\"root\">${elementsHTML}</div></body></div>`,\n {\n runScripts: 'dangerously',\n },\n )\n\n return dom.window.document\n}\n\n/**\n * In read-write mode, the runtime opens a `MessageChannel` to the builder\n * parent frame; jsdom doesn't implement `MessageChannel`, so stub them to keep\n * the read-write setup from throwing.\n */\nfunction stubBuilderMessageChannel(): () => void {\n const postMessageSpy = jest.spyOn(window, 'postMessage').mockImplementation(() => {})\n\n const originalMessageChannel = window.MessageChannel\n const stubPort = () => ({ onmessage: null, postMessage: () => {}, close: () => {} })\n window.MessageChannel = class {\n port1 = stubPort()\n port2 = stubPort()\n } as unknown as typeof MessageChannel\n\n return () => {\n postMessageSpy.mockRestore()\n window.MessageChannel = originalMessageChannel\n }\n}\n\nexport async function testPageControlPropRendering<D extends ControlDefinition>(\n controlDefinition: D,\n {\n toData,\n value,\n locale,\n cacheData,\n expectedRenders,\n registerComponents,\n action,\n rootElements = [],\n isInBuilder = false,\n isReadOnly = true,\n }: {\n toData?: (value: ValueType<D>) => DataType<D>\n value: ValueType<D> | undefined\n locale?: string | null\n cacheData?: Partial<CacheData>\n expectedRenders?: number\n registerComponents?: (runtime: ReactRuntime) => void\n action?: (element: HTMLElement) => Promise<void>\n rootElements?: ElementData[]\n isInBuilder?: boolean\n isReadOnly?: boolean\n },\n) {\n // Arrange\n const controlData: DataType<D> | Data =\n value !== undefined ? (toData ? toData(value) : controlDefinition.toData(value)) : undefined\n\n const testComponentMeta = {\n type: 'TestComponent',\n label: 'Test Component',\n }\n\n const testId = 'test-id'\n const renderCountTestId = 'render-count-test-id'\n const elementData: ElementData = {\n key: ELEMENT_ID,\n type: testComponentMeta.type,\n props: {\n propKey: controlData,\n },\n }\n\n const runtime = Testing.createReactRuntime()\n runtime.protoStore.dispatch(setIsInBuilder(isInBuilder))\n registerComponents?.(runtime)\n\n // Act\n runtime.registerComponent(\n forwardRef<HTMLDivElement, { propKey?: any }>(({ propKey }, ref) => {\n const renderCount = useRef(0)\n ++renderCount.current\n\n return (\n <div ref={ref}>\n <div data-testid={renderCountTestId}>{renderCount.current}</div>\n <div data-testid={testId}>{renderProp(propKey)}</div>\n </div>\n )\n }),\n {\n ...testComponentMeta,\n props: {\n propKey: controlDefinition as any,\n },\n },\n )\n\n const testElementTree = (component: ReactNode) => {\n // The runtime enters the read-write state when a non-null site version is\n // passed\n const siteVersion = isReadOnly ? null : { token: 'test-token', version: 'draft' }\n return (\n <Testing.ReactProvider runtime={runtime} siteVersion={siteVersion}>\n {component}\n </Testing.ReactProvider>\n )\n }\n\n if (!isServer()) {\n const restoreMessageChannel = isReadOnly ? null : stubBuilderMessageChannel()\n\n const rootElementData: ElementData = Testing.createRootComponent(\n [elementData, ...rootElements],\n ROOT_ID,\n )\n\n const snapshot = Testing.createMakeswiftPageSnapshot(rootElementData, { locale, cacheData })\n\n // Assert\n await act(async () => render(testElementTree(<Page snapshot={snapshot} />)))\n\n if (action) {\n await act(async () => {\n await action(screen.getByTestId(testId))\n })\n }\n\n expect(snapshot).toMatchSnapshot('snapshot')\n expect(propSnapshot(screen.getByTestId(testId))).toMatchSnapshot('resolvedValue')\n\n if (expectedRenders != null) {\n expect(Number(screen.getByTestId(renderCountTestId).textContent)).toBe(expectedRenders)\n }\n\n restoreMessageChannel?.()\n } else {\n // test server-side rendering using a component snapshot\n console.assert(action == null)\n console.assert(rootElements.length === 0)\n\n const snapshot = Testing.createMakeswiftComponentSnapshot(elementData, { locale, cacheData })\n const elementTree = testElementTree(\n <MakeswiftComponent snapshot={snapshot} {...testComponentMeta} />,\n )\n\n const document = await serverSideRender(elementTree)\n const getByTestId = (id: string): HTMLElement | null =>\n document.querySelector(`[data-testid=\"${id}\"]`)\n\n expect(propSnapshot(getByTestId(testId))).toMatchSnapshot('resolvedValue')\n expect([...document.querySelectorAll('style')].map(n => n.textContent)).toMatchSnapshot(\n 'component styles',\n )\n expect(Number(getByTestId(renderCountTestId)?.textContent)).toBe(1)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAsDI;AAtDJ,mBAAkF;AAClF,oBAAuC;AACvC,mBAAsB;AACtB,IAAAA,gBAA+B;AAC/B,sBAAO;AACP,wBAA0C;AAM1C,+BAA+B;AAE/B,gCAAmC;AACnC,kBAAqB;AACrB,uBAAyB;AACzB,cAAyB;AAEzB,MAAM,UAAU;AAChB,MAAM,aAAa;AAEnB,MAAM,aAAa,CAAC,SAClB,SAAS,SAAY,kBAAc,6BAAe,IAAI,IAAI,OAAO,KAAK,UAAU,IAAI;AAEtF,MAAM,eAAe,CAAC,SACpB,MAAM,oBAAoB,KAAK,aAAa,qBAAqB,MAAM,eAAe,EAAE;AAE1F,MAAM,uBAAuB,CAAC,SAAkB,SAAS,cAAc,SAAY,KAAK,MAAM,IAAI;AAElG,eAAe,eAAe,QAAwB;AACpD,QAAM,SAAS,OAAO,UAAU;AAChC,QAAM,UAAU,IAAI,YAAY;AAEhC,MAAI,SAAS;AAEb,SAAO,MAAM;AACX,UAAM,EAAE,MAAM,MAAM,IAAI,MAAM,OAAO,KAAK;AAC1C,QAAI;AAAM;AACV,cAAU,QAAQ,OAAO,OAAO,EAAE,QAAQ,KAAK,CAAC;AAAA,EAClD;AAEA,SAAO;AACT;AAEA,eAAe,eAAe,SAAoB;AAChD,SAAO,MAAM,eAAe,UAAM,sCAAuB,OAAO,CAAC;AACnE;AAEA,eAAe,iBAAiB,UAAqB;AAGnD,QAAM,0BAAqD,CAAC;AAE5D,QAAM,cACJ,4CAAC,4CAA0B,UAA1B,EAAmC,OAAO,aAAW,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AO,qBAAO,YAAY,iBAAiB,EAAE,WAAW,CAAC,EAAE,KAAK,eAAe;AAAA,IACxF;AAEA,4BAAwB;AAAA,EAC1B,OAAO;AAEL,YAAQ,OAAO,UAAU,IAAI;AAC7B,YAAQ,OAAO,aAAa,WAAW,CAAC;AAExC,UAAM,WAAW,QAAQ,iCAAiC,aAAa,EAAE,QAAQ,UAAU,CAAC;AAC5F,UAAM,cAAc;AAAA,MAClB,4CAAC,gDAAmB,UAAqB,GAAG,mBAAmB;AAAA,IACjE;AAEA,UAAM,WAAW,MAAM,iBAAiB,WAAW;AACnD,UAAM,cAAc,CAAC,OACnB,SAAS,cAAc,iBAAiB,EAAE,IAAI;AAEhD,WAAO,aAAa,YAAY,MAAM,CAAC,CAAC,EAAE,gBAAgB,eAAe;AACzE,WAAO,CAAC,GAAG,SAAS,iBAAiB,OAAO,CAAC,EAAE,IAAI,OAAK,EAAE,WAAW,CAAC,EAAE;AAAA,MACtE;AAAA,IACF;AACA,WAAO,OAAO,YAAY,iBAAiB,GAAG,WAAW,CAAC,EAAE,KAAK,CAAC;AAAA,EACpE;AACF;","names":["import_react"]}
|
|
1
|
+
{"version":3,"sources":["../../../../../../src/next/components/tests/controls/page-control-prop-rendering.tsx"],"sourcesContent":["import { type ReactNode, Fragment, forwardRef, useRef, isValidElement, act } from 'react'\nimport { JSDOM } from 'jsdom'\nimport { render, screen } from '@testing-library/react'\nimport '@testing-library/jest-dom'\nimport { ServerInsertedHTMLContext } from 'next/navigation'\n\nimport { type Data, type ValueType, type DataType, ControlDefinition } from '@makeswift/controls'\n\nimport { type CacheData } from '../../../../api/api-resources-client'\nimport { ElementData } from '../../../../state/read-only-state'\nimport { setIsInBuilder } from '../../../../state/actions/internal/read-only-actions'\nimport { ReactRuntime } from '../../../../runtimes/react/react-runtime'\nimport { MakeswiftComponent } from '../../../../runtimes/react/components/MakeswiftComponent'\nimport { Page } from '../../page'\nimport { isServer } from '../../../../utils/is-server'\n\nimport { renderToString } from '../../../../runtimes/react/testing/render-to-string'\nimport * as Testing from '../../../testing'\n\nconst ROOT_ID = '00000000-0000-0000-0000-000000000000'\nconst ELEMENT_ID = '11111111-1111-1111-1111-111111111111'\n\nconst renderProp = (prop: any) =>\n prop === undefined ? 'undefined' : isValidElement(prop) ? prop : JSON.stringify(prop)\n\nconst propSnapshot = (prop: HTMLElement | null) =>\n prop?.childElementCount ? prop.childNodes : parseStringifiedProp(prop?.textContent ?? '')\n\nconst parseStringifiedProp = (prop: string) => (prop === 'undefined' ? undefined : JSON.parse(prop))\n\nasync function serverSideRender(children: ReactNode) {\n // wrap the children in a context provider to capture server-inserted HTML, see\n // https://github.com/vercel/next.js/blob/canary/packages/next/src/server/app-render/server-inserted-html.tsx\n const serverInsertedCallbacks: (() => React.ReactNode)[] = []\n\n const elementTree = (\n <ServerInsertedHTMLContext.Provider value={handler => serverInsertedCallbacks.push(handler)}>\n {children}\n </ServerInsertedHTMLContext.Provider>\n )\n\n const elementsHTML = await renderToString(elementTree)\n\n const serverInsertedNodes = serverInsertedCallbacks.map((callback, index) => (\n <Fragment key={'__next_server_inserted__' + index}>{callback()}</Fragment>\n ))\n\n const headHTML = await renderToString(serverInsertedNodes)\n\n const dom = new JSDOM(\n `<!DOCTYPE html><head>${headHTML}</head><body><div id=\"root\">${elementsHTML}</div></body></div>`,\n {\n runScripts: 'dangerously',\n },\n )\n\n return dom.window.document\n}\n\n/**\n * In read-write mode, the runtime opens a `MessageChannel` to the builder\n * parent frame; jsdom doesn't implement `MessageChannel`, so stub them to keep\n * the read-write setup from throwing.\n */\nfunction stubBuilderMessageChannel(): () => void {\n const postMessageSpy = jest.spyOn(window, 'postMessage').mockImplementation(() => {})\n\n const originalMessageChannel = window.MessageChannel\n const stubPort = () => ({ onmessage: null, postMessage: () => {}, close: () => {} })\n window.MessageChannel = class {\n port1 = stubPort()\n port2 = stubPort()\n } as unknown as typeof MessageChannel\n\n return () => {\n postMessageSpy.mockRestore()\n window.MessageChannel = originalMessageChannel\n }\n}\n\nexport async function testPageControlPropRendering<D extends ControlDefinition>(\n controlDefinition: D,\n {\n toData,\n value,\n locale,\n cacheData,\n expectedRenders,\n registerComponents,\n action,\n rootElements = [],\n isInBuilder = false,\n isReadOnly = true,\n }: {\n toData?: (value: ValueType<D>) => DataType<D>\n value: ValueType<D> | undefined\n locale?: string | null\n cacheData?: Partial<CacheData>\n expectedRenders?: number\n registerComponents?: (runtime: ReactRuntime) => void\n action?: (element: HTMLElement) => Promise<void>\n rootElements?: ElementData[]\n isInBuilder?: boolean\n isReadOnly?: boolean\n },\n) {\n // Arrange\n const controlData: DataType<D> | Data =\n value !== undefined ? (toData ? toData(value) : controlDefinition.toData(value)) : undefined\n\n const testComponentMeta = {\n type: 'TestComponent',\n label: 'Test Component',\n }\n\n const testId = 'test-id'\n const renderCountTestId = 'render-count-test-id'\n const elementData: ElementData = {\n key: ELEMENT_ID,\n type: testComponentMeta.type,\n props: {\n propKey: controlData,\n },\n }\n\n const runtime = Testing.createReactRuntime()\n runtime.protoStore.dispatch(setIsInBuilder(isInBuilder))\n registerComponents?.(runtime)\n\n // Act\n runtime.registerComponent(\n forwardRef<HTMLDivElement, { propKey?: any }>(({ propKey }, ref) => {\n const renderCount = useRef(0)\n ++renderCount.current\n\n return (\n <div ref={ref}>\n <div data-testid={renderCountTestId}>{renderCount.current}</div>\n <div data-testid={testId}>{renderProp(propKey)}</div>\n </div>\n )\n }),\n {\n ...testComponentMeta,\n props: {\n propKey: controlDefinition as any,\n },\n },\n )\n\n const testElementTree = (component: ReactNode) => {\n // The runtime enters the read-write state when a non-null site version is\n // passed\n const siteVersion = isReadOnly ? null : { token: 'test-token', version: 'draft' }\n return (\n <Testing.ReactProvider runtime={runtime} siteVersion={siteVersion}>\n {component}\n </Testing.ReactProvider>\n )\n }\n\n if (!isServer()) {\n const restoreMessageChannel = isReadOnly ? null : stubBuilderMessageChannel()\n\n const rootElementData: ElementData = Testing.createRootComponent(\n [elementData, ...rootElements],\n ROOT_ID,\n )\n\n const snapshot = Testing.createMakeswiftPageSnapshot(rootElementData, { locale, cacheData })\n\n // Assert\n await act(async () => render(testElementTree(<Page snapshot={snapshot} />)))\n\n if (action) {\n await act(async () => {\n await action(screen.getByTestId(testId))\n })\n }\n\n expect(snapshot).toMatchSnapshot('snapshot')\n expect(propSnapshot(screen.getByTestId(testId))).toMatchSnapshot('resolvedValue')\n\n if (expectedRenders != null) {\n expect(Number(screen.getByTestId(renderCountTestId).textContent)).toBe(expectedRenders)\n }\n\n restoreMessageChannel?.()\n } else {\n // test server-side rendering using a component snapshot\n console.assert(action == null)\n console.assert(rootElements.length === 0)\n\n const snapshot = Testing.createMakeswiftComponentSnapshot(elementData, { locale, cacheData })\n const elementTree = testElementTree(\n <MakeswiftComponent snapshot={snapshot} {...testComponentMeta} />,\n )\n\n const document = await serverSideRender(elementTree)\n const getByTestId = (id: string): HTMLElement | null =>\n document.querySelector(`[data-testid=\"${id}\"]`)\n\n expect(propSnapshot(getByTestId(testId))).toMatchSnapshot('resolvedValue')\n expect([...document.querySelectorAll('style')].map(n => n.textContent)).toMatchSnapshot(\n 'component styles',\n )\n expect(Number(getByTestId(renderCountTestId)?.textContent)).toBe(1)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAoCI;AApCJ,mBAAkF;AAClF,mBAAsB;AACtB,IAAAA,gBAA+B;AAC/B,sBAAO;AACP,wBAA0C;AAM1C,+BAA+B;AAE/B,gCAAmC;AACnC,kBAAqB;AACrB,uBAAyB;AAEzB,8BAA+B;AAC/B,cAAyB;AAEzB,MAAM,UAAU;AAChB,MAAM,aAAa;AAEnB,MAAM,aAAa,CAAC,SAClB,SAAS,SAAY,kBAAc,6BAAe,IAAI,IAAI,OAAO,KAAK,UAAU,IAAI;AAEtF,MAAM,eAAe,CAAC,SACpB,MAAM,oBAAoB,KAAK,aAAa,qBAAqB,MAAM,eAAe,EAAE;AAE1F,MAAM,uBAAuB,CAAC,S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A,IACH;AAEA,WAAO,QAAQ,EAAE,gBAAgB,UAAU;AAC3C,WAAO,aAAa,qBAAO,YAAY,MAAM,CAAC,CAAC,EAAE,gBAAgB,eAAe;AAEhF,QAAI,mBAAmB,MAAM;AAC3B,aAAO,OAAO,qBAAO,YAAY,iBAAiB,EAAE,WAAW,CAAC,EAAE,KAAK,eAAe;AAAA,IACxF;AAEA,4BAAwB;AAAA,EAC1B,OAAO;AAEL,YAAQ,OAAO,UAAU,IAAI;AAC7B,YAAQ,OAAO,aAAa,WAAW,CAAC;AAExC,UAAM,WAAW,QAAQ,iCAAiC,aAAa,EAAE,QAAQ,UAAU,CAAC;AAC5F,UAAM,cAAc;AAAA,MAClB,4CAAC,gDAAmB,UAAqB,GAAG,mBAAmB;AAAA,IACjE;AAEA,UAAM,WAAW,MAAM,iBAAiB,WAAW;AACnD,UAAM,cAAc,CAAC,OACnB,SAAS,cAAc,iBAAiB,EAAE,IAAI;AAEhD,WAAO,aAAa,YAAY,MAAM,CAAC,CAAC,EAAE,gBAAgB,eAAe;AACzE,WAAO,CAAC,GAAG,SAAS,iBAAiB,OAAO,CAAC,EAAE,IAAI,OAAK,EAAE,WAAW,CAAC,EAAE;AAAA,MACtE;AAAA,IACF;AACA,WAAO,OAAO,YAAY,iBAAiB,GAAG,WAAW,CAAC,EAAE,KAAK,CAAC;AAAA,EACpE;AACF;","names":["import_react"]}
|
|
@@ -47,10 +47,12 @@ class ReactRuntimeCore extends import_runtime_core.RuntimeCore {
|
|
|
47
47
|
server = false,
|
|
48
48
|
props
|
|
49
49
|
}) {
|
|
50
|
+
const isServerComponent = server !== false;
|
|
51
|
+
const injectedProps = typeof server === "object" ? server.unstable_injectedProps : {};
|
|
50
52
|
validateComponentType(
|
|
51
53
|
// make sure we don't access `component?.name` and trigger loading of the server
|
|
52
54
|
// component unless we're running in the RSC environment
|
|
53
|
-
|
|
55
|
+
isServerComponent && !this.isRSCEnv() ? { type, componentName: label || "Unknown server component" } : {
|
|
54
56
|
type,
|
|
55
57
|
componentName: component?.name || label || "Unknown component"
|
|
56
58
|
}
|
|
@@ -58,7 +60,16 @@ class ReactRuntimeCore extends import_runtime_core.RuntimeCore {
|
|
|
58
60
|
const unregisterComponent = this.protoStore.dispatch(
|
|
59
61
|
(0, import_read_only_actions.registerComponentEffect)(
|
|
60
62
|
type,
|
|
61
|
-
{
|
|
63
|
+
{
|
|
64
|
+
label,
|
|
65
|
+
icon,
|
|
66
|
+
hidden,
|
|
67
|
+
description,
|
|
68
|
+
builtinSuspense,
|
|
69
|
+
unstable_migration,
|
|
70
|
+
server: isServerComponent,
|
|
71
|
+
injectedProps
|
|
72
|
+
},
|
|
62
73
|
props ?? {}
|
|
63
74
|
)
|
|
64
75
|
);
|
|
@@ -67,7 +78,7 @@ class ReactRuntimeCore extends import_runtime_core.RuntimeCore {
|
|
|
67
78
|
"builtinSuspense is ignored in React >= 19.2; components are always wrapped in <Activity>."
|
|
68
79
|
);
|
|
69
80
|
}
|
|
70
|
-
if (
|
|
81
|
+
if (isServerComponent && !this.isRSCEnv()) {
|
|
71
82
|
return () => {
|
|
72
83
|
unregisterComponent();
|
|
73
84
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/runtimes/react/react-runtime-core.ts"],"sourcesContent":["import { ControlDefinition as UnifiedControlDefinition } from '@makeswift/controls'\n\nimport { type LegacyDescriptor, type DescriptorValueType } from '../../prop-controllers/descriptors'\n\nimport { supportsActivity } from './components/activity-with-fallback'\n\nimport {\n registerComponentEffect,\n registerReactComponentEffect,\n} from '../../state/actions/internal/read-only-actions'\n\nimport { ComponentIcon } from '../../state/modules/components-meta'\nimport type { ComponentType } from '../../state/read-only-state'\n\nimport { RuntimeCore } from './runtime-core'\n\nfunction validateComponentType({\n type,\n componentName,\n}: {\n type: string\n componentName: string\n}): void {\n if (typeof type !== 'string' || type === '') {\n throw new Error(\n `${componentName}: A non-empty string \\`type\\` is required for component registration, got ${type}`,\n )\n }\n}\n\nexport class ReactRuntimeCore extends RuntimeCore {\n registerComponent<\n ControlDef extends UnifiedControlDefinition,\n P extends Record<string, LegacyDescriptor | ControlDef>,\n
|
|
1
|
+
{"version":3,"sources":["../../../../src/runtimes/react/react-runtime-core.ts"],"sourcesContent":["import { type Component, type PropsWithoutRef, type ReactNode, type RefAttributes } from 'react'\n\nimport { ControlDefinition as UnifiedControlDefinition } from '@makeswift/controls'\n\nimport { type LegacyDescriptor, type DescriptorValueType } from '../../prop-controllers/descriptors'\n\nimport { supportsActivity } from './components/activity-with-fallback'\n\nimport {\n registerComponentEffect,\n registerReactComponentEffect,\n} from '../../state/actions/internal/read-only-actions'\n\nimport { ComponentIcon } from '../../state/modules/components-meta'\nimport type { ComponentType } from '../../state/read-only-state'\n\nimport { type InjectableProps } from './server/injectable-props'\n\nimport { RuntimeCore } from './runtime-core'\n\nfunction validateComponentType({\n type,\n componentName,\n}: {\n type: string\n componentName: string\n}): void {\n if (typeof type !== 'string' || type === '') {\n throw new Error(\n `${componentName}: A non-empty string \\`type\\` is required for component registration, got ${type}`,\n )\n }\n}\n\ntype InjectedPropsConfig = Record<string, keyof InjectableProps>\n\ntype ServerComponentConfig<I extends InjectedPropsConfig> =\n | boolean\n | {\n unstable_injectedProps: I\n }\n\ntype InjectedProps<I extends InjectedPropsConfig> = {\n [K in keyof I]: InjectableProps[I[K]]\n}\n\ntype ResolvedProps<P extends Record<string, LegacyDescriptor | UnifiedControlDefinition>> = {\n [K in keyof P]: DescriptorValueType<P[K]>\n}\n\ntype RegisteredComponentType<\n P extends Record<string, LegacyDescriptor | UnifiedControlDefinition>,\n I extends InjectedPropsConfig,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n T = any,\n> =\n | {\n new (\n props: PropsWithoutRef<ResolvedProps<P>> & InjectedProps<I> & RefAttributes<T>,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n context?: any,\n ): Component<ResolvedProps<P> & InjectedProps<I>>\n }\n | ((\n props: PropsWithoutRef<ResolvedProps<P>> & InjectedProps<I> & RefAttributes<T>,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n context?: any,\n ) => ReactNode)\n\nexport class ReactRuntimeCore extends RuntimeCore {\n registerComponent<\n ControlDef extends UnifiedControlDefinition,\n P extends Record<string, LegacyDescriptor | ControlDef>,\n // eslint-disable-next-line @typescript-eslint/no-empty-object-type\n const I extends InjectedPropsConfig = {},\n C extends RegisteredComponentType<P, I> = RegisteredComponentType<P, I>,\n >(\n component: C,\n {\n type,\n label,\n icon = ComponentIcon.Cube,\n hidden = false,\n description,\n builtinSuspense,\n unstable_migration,\n server = false,\n props,\n }: {\n type: string\n label: string\n icon?: ComponentIcon\n hidden?: boolean\n description?: string\n /**\n * In React <= 19.1, controls the default `<Suspense>` boundary.\n * Ignored in React >= 19.2; components are always wrapped in `<Activity>`.\n * Defaults to `true`.\n */\n builtinSuspense?: boolean\n /**\n * Marks this registration as superseded by `replacementType`. When\n * `replacementType` differs from `type`, the builder offers a way to\n * update existing instances.\n */\n unstable_migration?: { replacementType: string }\n server?: ServerComponentConfig<I>\n props?: P\n },\n ): () => void {\n const isServerComponent = server !== false\n const injectedProps = typeof server === 'object' ? server.unstable_injectedProps : {}\n\n validateComponentType(\n // make sure we don't access `component?.name` and trigger loading of the server\n // component unless we're running in the RSC environment\n isServerComponent && !this.isRSCEnv()\n ? { type, componentName: label || 'Unknown server component' }\n : {\n type,\n componentName: component?.name || label || 'Unknown component',\n },\n )\n\n const unregisterComponent = this.protoStore.dispatch(\n registerComponentEffect(\n type,\n {\n label,\n icon,\n hidden,\n description,\n builtinSuspense,\n unstable_migration,\n server: isServerComponent,\n injectedProps,\n },\n props ?? {},\n ),\n )\n\n if (supportsActivity() && builtinSuspense !== undefined) {\n console.warn(\n 'builtinSuspense is ignored in React >= 19.2; components are always wrapped in <Activity>.',\n )\n }\n\n if (isServerComponent && !this.isRSCEnv()) {\n // we can't load server components code outside of the RSC environment, but we also\n // don't need to: if everything is set up correctly, React has already rendered and\n // streamed the corresponding React elements to the client for us -- see\n // `ServerElementsCache` and `ElementDataServer`\n return () => {\n unregisterComponent()\n }\n }\n\n const unregisterReactComponent = this.protoStore.dispatch(\n registerReactComponentEffect(type, component as unknown as ComponentType),\n )\n\n return () => {\n unregisterComponent()\n unregisterReactComponent()\n }\n }\n\n protected isRSCEnv() {\n return false\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAMA,oCAAiC;AAEjC,+BAGO;AAEP,6BAA8B;AAK9B,0BAA4B;AAE5B,SAAS,sBAAsB;AAAA,EAC7B;AAAA,EACA;AACF,GAGS;AACP,MAAI,OAAO,SAAS,YAAY,SAAS,IAAI;AAC3C,UAAM,IAAI;AAAA,MACR,GAAG,aAAa,6EAA6E,IAAI;AAAA,IACnG;AAAA,EACF;AACF;AAqCO,MAAM,yBAAyB,gCAAY;AAAA,EAChD,kBAOE,WACA;AAAA,IACE;AAAA,IACA;AAAA,IACA,OAAO,qCAAc;AAAA,IACrB,SAAS;AAAA,IACT;AAAA,IACA;AAAA,IACA;AAAA,IACA,SAAS;AAAA,IACT;AAAA,EACF,GAqBY;AACZ,UAAM,oBAAoB,WAAW;AACrC,UAAM,gBAAgB,OAAO,WAAW,WAAW,OAAO,yBAAyB,CAAC;AAEpF;AAAA;AAAA;AAAA,MAGE,qBAAqB,CAAC,KAAK,SAAS,IAChC,EAAE,MAAM,eAAe,SAAS,2BAA2B,IAC3D;AAAA,QACE;AAAA,QACA,eAAe,WAAW,QAAQ,SAAS;AAAA,MAC7C;AAAA,IACN;AAEA,UAAM,sBAAsB,KAAK,WAAW;AAAA,UAC1C;AAAA,QACE;AAAA,QACA;AAAA,UACE;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA,QAAQ;AAAA,UACR;AAAA,QACF;AAAA,QACA,SAAS,CAAC;AAAA,MACZ;AAAA,IACF;AAEA,YAAI,gDAAiB,KAAK,oBAAoB,QAAW;AACvD,cAAQ;AAAA,QACN;AAAA,MACF;AAAA,IACF;AAEA,QAAI,qBAAqB,CAAC,KAAK,SAAS,GAAG;AAKzC,aAAO,MAAM;AACX,4BAAoB;AAAA,MACtB;AAAA,IACF;AAEA,UAAM,2BAA2B,KAAK,WAAW;AAAA,UAC/C,uDAA6B,MAAM,SAAqC;AAAA,IAC1E;AAEA,WAAO,MAAM;AACX,0BAAoB;AACpB,+BAAyB;AAAA,IAC3B;AAAA,EACF;AAAA,EAEU,WAAW;AACnB,WAAO;AAAA,EACT;AACF;","names":[]}
|
|
@@ -32,7 +32,8 @@ var import_resolve_props = require("../resolve-props");
|
|
|
32
32
|
async function ServerElementData({
|
|
33
33
|
documentKey,
|
|
34
34
|
context,
|
|
35
|
-
elementData
|
|
35
|
+
elementData,
|
|
36
|
+
injectedProps
|
|
36
37
|
}) {
|
|
37
38
|
const state = (0, import_render_context.getStore)(context).getState();
|
|
38
39
|
const Component = (0, import_read_only_state.getReactComponent)(state, elementData.type);
|
|
@@ -59,7 +60,10 @@ async function ServerElementData({
|
|
|
59
60
|
(0, import_read_only_state.getBreakpoints)(state),
|
|
60
61
|
elementData.key
|
|
61
62
|
);
|
|
62
|
-
const props =
|
|
63
|
+
const props = {
|
|
64
|
+
...await (0, import_resolve_props.resolveProps)(context, elementData, documentKey, definitions, stylesheet),
|
|
65
|
+
...injectedProps
|
|
66
|
+
};
|
|
63
67
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
64
68
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, { ...props }, elementData.key),
|
|
65
69
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_server_css.InjectServerCSS, { collector: cssCollector, elementKey: elementData.key })
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../src/runtimes/react/server/components/element-data.tsx"],"sourcesContent":["import { type ReactNode } from 'react'\n\nimport { partitionRecord } from '../../../../utils/partition'\n\nimport {\n type State,\n type ElementData,\n getReactComponent,\n getBreakpoints,\n getComponentPropControllerDescriptors,\n} from '../../../../state/read-only-state'\n\nimport { FallbackComponent } from '../../../../components/shared/FallbackComponent'\nimport { isLegacyDescriptor } from '../../../../prop-controllers/descriptors'\n\nimport {\n ServerCSSCollector,\n createCollectingServerStylesheet,\n InjectServerCSS,\n} from '../css/server-css'\nimport { type ServerRenderContext, getStore } from '../render-context'\nimport { resolveProps } from '../resolve-props'\n\nexport async function ServerElementData({\n documentKey,\n context,\n elementData,\n}: {\n documentKey: string\n context: ServerRenderContext\n elementData: ElementData\n}): Promise<ReactNode> {\n const state = getStore(context).getState()\n\n const Component = getReactComponent(state, elementData.type)\n if (Component == null) {\n return (\n <FallbackComponent\n text=\"Component not found\"\n details={`Unknown component '${elementData.type}'`}\n />\n )\n }\n\n const [legacyDescriptors, definitions] = getControlDefs(state, elementData)\n const legacyKeys = Object.keys(legacyDescriptors)\n if (legacyKeys.length > 0) {\n console.warn(`Unexpected legacy control data in server element '${elementData.key}`, {\n elementData,\n legacyKeys,\n })\n }\n\n const cssCollector = new ServerCSSCollector()\n const stylesheet = createCollectingServerStylesheet(\n cssCollector,\n getBreakpoints(state),\n elementData.key,\n )\n\n const props = await resolveProps(context, elementData, documentKey, definitions, stylesheet)\n\n return (\n <>\n {/* Make the component the first child so that `findDOMNode` resolves to its first\n rendered DOM node (if any) rather than the component's `<style>` element */}\n <Component key={elementData.key} {...props} />\n <InjectServerCSS collector={cssCollector} elementKey={elementData.key} />\n </>\n )\n}\n\nconst getControlDefs = (state: State, elementData: ElementData) => {\n const descriptors = getComponentPropControllerDescriptors(state, elementData.type) ?? {}\n return partitionRecord(descriptors, isLegacyDescriptor)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
1
|
+
{"version":3,"sources":["../../../../../../src/runtimes/react/server/components/element-data.tsx"],"sourcesContent":["import { type ReactNode } from 'react'\n\nimport { partitionRecord } from '../../../../utils/partition'\n\nimport {\n type State,\n type ElementData,\n getReactComponent,\n getBreakpoints,\n getComponentPropControllerDescriptors,\n} from '../../../../state/read-only-state'\n\nimport { FallbackComponent } from '../../../../components/shared/FallbackComponent'\nimport { isLegacyDescriptor } from '../../../../prop-controllers/descriptors'\n\nimport {\n ServerCSSCollector,\n createCollectingServerStylesheet,\n InjectServerCSS,\n} from '../css/server-css'\nimport { type ServerRenderContext, getStore } from '../render-context'\nimport { resolveProps } from '../resolve-props'\n\nexport async function ServerElementData({\n documentKey,\n context,\n elementData,\n injectedProps,\n}: {\n documentKey: string\n context: ServerRenderContext\n elementData: ElementData\n injectedProps: Record<string, unknown>\n}): Promise<ReactNode> {\n const state = getStore(context).getState()\n\n const Component = getReactComponent(state, elementData.type)\n if (Component == null) {\n return (\n <FallbackComponent\n text=\"Component not found\"\n details={`Unknown component '${elementData.type}'`}\n />\n )\n }\n\n const [legacyDescriptors, definitions] = getControlDefs(state, elementData)\n const legacyKeys = Object.keys(legacyDescriptors)\n if (legacyKeys.length > 0) {\n console.warn(`Unexpected legacy control data in server element '${elementData.key}`, {\n elementData,\n legacyKeys,\n })\n }\n\n const cssCollector = new ServerCSSCollector()\n const stylesheet = createCollectingServerStylesheet(\n cssCollector,\n getBreakpoints(state),\n elementData.key,\n )\n\n const props = {\n ...(await resolveProps(context, elementData, documentKey, definitions, stylesheet)),\n ...injectedProps,\n }\n\n return (\n <>\n {/* Make the component the first child so that `findDOMNode` resolves to its first\n rendered DOM node (if any) rather than the component's `<style>` element */}\n <Component key={elementData.key} {...props} />\n <InjectServerCSS collector={cssCollector} elementKey={elementData.key} />\n </>\n )\n}\n\nconst getControlDefs = (state: State, elementData: ElementData) => {\n const descriptors = getComponentPropControllerDescriptors(state, elementData.type) ?? {}\n return partitionRecord(descriptors, isLegacyDescriptor)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAuCM;AArCN,uBAAgC;AAEhC,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jsx_runtime = require("react/jsx-runtime");
|
|
25
|
+
var import_controls = require("@makeswift/controls");
|
|
25
26
|
var import_read_only_state = require("../../../../state/read-only-state");
|
|
26
27
|
var import_FallbackComponent = require("../../../../components/shared/FallbackComponent");
|
|
27
28
|
var import_Element = require("../../components/Element");
|
|
@@ -46,11 +47,28 @@ function ServerElement({
|
|
|
46
47
|
}
|
|
47
48
|
);
|
|
48
49
|
}
|
|
50
|
+
const elementKey = element.key;
|
|
49
51
|
const isRSC = elementMeta.server ?? false;
|
|
50
52
|
if (!isRSC) {
|
|
51
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_Element.Element, { element },
|
|
53
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_Element.Element, { element }, elementKey);
|
|
52
54
|
}
|
|
53
|
-
|
|
55
|
+
const injectableProps = {
|
|
56
|
+
elementKey,
|
|
57
|
+
documentKey
|
|
58
|
+
};
|
|
59
|
+
const injectedProps = (0, import_controls.mapValues)(
|
|
60
|
+
elementMeta.injectedProps ?? {},
|
|
61
|
+
(propName) => injectableProps[propName]
|
|
62
|
+
);
|
|
63
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
64
|
+
import_element_data.ServerElementData,
|
|
65
|
+
{
|
|
66
|
+
documentKey,
|
|
67
|
+
context,
|
|
68
|
+
elementData: element,
|
|
69
|
+
injectedProps
|
|
70
|
+
}
|
|
71
|
+
);
|
|
54
72
|
}
|
|
55
73
|
// Annotate the CommonJS export names for ESM import in node:
|
|
56
74
|
0 && (module.exports = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../src/runtimes/react/server/components/element.tsx"],"sourcesContent":["import { ReactNode } from 'react'\n\nimport {\n isElementReference,\n getComponentsMeta,\n type Element as ElementDataOrRef,\n} from '../../../../state/read-only-state'\n\nimport { FallbackComponent } from '../../../../components/shared/FallbackComponent'\n\nimport { Element as ClientElement } from '../../components/Element'\n\nimport { type ServerRenderContext, getStore } from '../render-context'\n\nimport { ServerElementData } from './element-data'\n\nexport function ServerElement({\n context,\n element,\n documentKey,\n}: {\n context: ServerRenderContext\n element: ElementDataOrRef\n documentKey: string\n}): ReactNode {\n // check for element references first to avoid looking them up as regular components\n if (isElementReference(element)) {\n return <FallbackComponent text=\"Element reference is not supported on server yet\" />\n }\n\n const state = getStore(context).getState()\n const elementMeta = getComponentsMeta(state).get(element.type)\n if (elementMeta == null) {\n return (\n <FallbackComponent\n text=\"Component not found\"\n details={`Missing component metadata for '${element.type}'`}\n />\n )\n }\n\n const isRSC = elementMeta.server ?? false\n if (!isRSC) {\n return <ClientElement key={
|
|
1
|
+
{"version":3,"sources":["../../../../../../src/runtimes/react/server/components/element.tsx"],"sourcesContent":["import { ReactNode } from 'react'\n\nimport { mapValues } from '@makeswift/controls'\n\nimport {\n isElementReference,\n getComponentsMeta,\n type Element as ElementDataOrRef,\n} from '../../../../state/read-only-state'\n\nimport { FallbackComponent } from '../../../../components/shared/FallbackComponent'\n\nimport { Element as ClientElement } from '../../components/Element'\n\nimport { type ServerRenderContext, getStore } from '../render-context'\nimport { type InjectableProps } from '../injectable-props'\n\nimport { ServerElementData } from './element-data'\n\nexport function ServerElement({\n context,\n element,\n documentKey,\n}: {\n context: ServerRenderContext\n element: ElementDataOrRef\n documentKey: string\n}): ReactNode {\n // check for element references first to avoid looking them up as regular components\n if (isElementReference(element)) {\n return <FallbackComponent text=\"Element reference is not supported on server yet\" />\n }\n\n const state = getStore(context).getState()\n const elementMeta = getComponentsMeta(state).get(element.type)\n if (elementMeta == null) {\n return (\n <FallbackComponent\n text=\"Component not found\"\n details={`Missing component metadata for '${element.type}'`}\n />\n )\n }\n\n const elementKey = element.key\n const isRSC = elementMeta.server ?? false\n if (!isRSC) {\n return <ClientElement key={elementKey} element={element} />\n }\n\n const injectableProps: InjectableProps = {\n elementKey,\n documentKey,\n }\n\n const injectedProps = mapValues(\n elementMeta.injectedProps ?? {},\n propName => injectableProps[propName],\n )\n\n return (\n <ServerElementData\n documentKey={documentKey}\n context={context}\n elementData={element}\n injectedProps={injectedProps}\n />\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA8BW;AA5BX,sBAA0B;AAE1B,6BAIO;AAEP,+BAAkC;AAElC,qBAAyC;AAEzC,4BAAmD;AAGnD,0BAAkC;AAE3B,SAAS,cAAc;AAAA,EAC5B;AAAA,EACA;AAAA,EACA;AACF,GAIc;AAEZ,UAAI,2CAAmB,OAAO,GAAG;AAC/B,WAAO,4CAAC,8CAAkB,MAAK,oDAAmD;AAAA,EACpF;AAEA,QAAM,YAAQ,gCAAS,OAAO,EAAE,SAAS;AACzC,QAAM,kBAAc,0CAAkB,KAAK,EAAE,IAAI,QAAQ,IAAI;AAC7D,MAAI,eAAe,MAAM;AACvB,WACE;AAAA,MAAC;AAAA;AAAA,QACC,MAAK;AAAA,QACL,SAAS,mCAAmC,QAAQ,IAAI;AAAA;AAAA,IAC1D;AAAA,EAEJ;AAEA,QAAM,aAAa,QAAQ;AAC3B,QAAM,QAAQ,YAAY,UAAU;AACpC,MAAI,CAAC,OAAO;AACV,WAAO,4CAAC,eAAAA,SAAA,EAA+B,WAAZ,UAA8B;AAAA,EAC3D;AAEA,QAAM,kBAAmC;AAAA,IACvC;AAAA,IACA;AAAA,EACF;AAEA,QAAM,oBAAgB;AAAA,IACpB,YAAY,iBAAiB,CAAC;AAAA,IAC9B,cAAY,gBAAgB,QAAQ;AAAA,EACtC;AAEA,SACE;AAAA,IAAC;AAAA;AAAA,MACC;AAAA,MACA;AAAA,MACA,aAAa;AAAA,MACb;AAAA;AAAA,EACF;AAEJ;","names":["ClientElement"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
var injectable_props_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(injectable_props_exports);
|
|
17
|
+
//# sourceMappingURL=injectable-props.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/runtimes/react/server/injectable-props.ts"],"sourcesContent":["export type InjectableProps = {\n documentKey: string\n elementKey: string\n}\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
|
|
@@ -25,10 +25,7 @@ var import_fixtures = require("../../../testing/fixtures");
|
|
|
25
25
|
var import_react_runtime = require("../react-runtime");
|
|
26
26
|
class TestReactRuntime extends import_react_runtime.ReactRuntime {
|
|
27
27
|
env;
|
|
28
|
-
constructor({
|
|
29
|
-
env,
|
|
30
|
-
...args
|
|
31
|
-
}) {
|
|
28
|
+
constructor({ env, ...args }) {
|
|
32
29
|
super(args);
|
|
33
30
|
this.env = env ?? "client";
|
|
34
31
|
}
|
|
@@ -38,6 +35,7 @@ class TestReactRuntime extends import_react_runtime.ReactRuntime {
|
|
|
38
35
|
}
|
|
39
36
|
function createReactRuntime({
|
|
40
37
|
breakpoints,
|
|
38
|
+
requestKey,
|
|
41
39
|
env
|
|
42
40
|
} = {}) {
|
|
43
41
|
return new TestReactRuntime({
|
|
@@ -45,6 +43,7 @@ function createReactRuntime({
|
|
|
45
43
|
// through the patched version instead of an eagerly captured reference to the original
|
|
46
44
|
fetch: (...args) => globalThis.fetch(...args),
|
|
47
45
|
breakpoints,
|
|
46
|
+
requestKey,
|
|
48
47
|
env,
|
|
49
48
|
...import_fixtures.TestOrigins
|
|
50
49
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/runtimes/react/testing/react-runtime.tsx"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../../../../../src/runtimes/react/testing/react-runtime.tsx"],"sourcesContent":["import { TestOrigins } from '../../../testing/fixtures'\nimport { ReactRuntime } from '../react-runtime'\n\ntype RuntimeEnv = 'client' | 'ssr' | 'rsc'\ntype RuntimeArgs = ConstructorParameters<typeof ReactRuntime>[0]\n\nclass TestReactRuntime extends ReactRuntime {\n readonly env: RuntimeEnv\n\n constructor({ env, ...args }: RuntimeArgs & { env?: RuntimeEnv }) {\n super(args)\n this.env = env ?? 'client'\n }\n\n protected isRSCEnv() {\n return this.env === 'rsc'\n }\n}\n\nexport function createReactRuntime({\n breakpoints,\n requestKey,\n env,\n}: {\n breakpoints?: RuntimeArgs['breakpoints']\n requestKey?: RuntimeArgs['requestKey']\n env?: RuntimeEnv\n} = {}) {\n return new TestReactRuntime({\n // Mock Service Worker patches global `fetch` for interception; make sure our test calls go\n // through the patched version instead of an eagerly captured reference to the original\n fetch: (...args) => globalThis.fetch(...args),\n breakpoints,\n requestKey,\n env,\n ...TestOrigins,\n })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAA4B;AAC5B,2BAA6B;AAK7B,MAAM,yBAAyB,kCAAa;AAAA,EACjC;AAAA,EAET,YAAY,EAAE,KAAK,GAAG,KAAK,GAAuC;AAChE,UAAM,IAAI;AACV,SAAK,MAAM,OAAO;AAAA,EACpB;AAAA,EAEU,WAAW;AACnB,WAAO,KAAK,QAAQ;AAAA,EACtB;AACF;AAEO,SAAS,mBAAmB;AAAA,EACjC;AAAA,EACA;AAAA,EACA;AACF,IAII,CAAC,GAAG;AACN,SAAO,IAAI,iBAAiB;AAAA;AAAA;AAAA,IAG1B,OAAO,IAAI,SAAS,WAAW,MAAM,GAAG,IAAI;AAAA,IAC5C;AAAA,IACA;AAAA,IACA;AAAA,IACA,GAAG;AAAA,EACL,CAAC;AACH;","names":[]}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var render_to_string_exports = {};
|
|
20
|
+
__export(render_to_string_exports, {
|
|
21
|
+
renderToString: () => renderToString
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(render_to_string_exports);
|
|
24
|
+
var import_server = require("react-dom/server");
|
|
25
|
+
async function streamToString(stream) {
|
|
26
|
+
const reader = stream.getReader();
|
|
27
|
+
const decoder = new TextDecoder();
|
|
28
|
+
let result = "";
|
|
29
|
+
while (true) {
|
|
30
|
+
const { done, value } = await reader.read();
|
|
31
|
+
if (done)
|
|
32
|
+
break;
|
|
33
|
+
result += decoder.decode(value, { stream: true });
|
|
34
|
+
}
|
|
35
|
+
return result;
|
|
36
|
+
}
|
|
37
|
+
async function renderToString(element) {
|
|
38
|
+
return await streamToString(await (0, import_server.renderToReadableStream)(element));
|
|
39
|
+
}
|
|
40
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
41
|
+
0 && (module.exports = {
|
|
42
|
+
renderToString
|
|
43
|
+
});
|
|
44
|
+
//# sourceMappingURL=render-to-string.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/runtimes/react/testing/render-to-string.ts"],"sourcesContent":["import { type ReactNode } from 'react'\nimport { renderToReadableStream } from 'react-dom/server'\n\nasync function streamToString(stream: ReadableStream) {\n const reader = stream.getReader()\n const decoder = new TextDecoder()\n\n let result = ''\n\n while (true) {\n const { done, value } = await reader.read()\n if (done) break\n result += decoder.decode(value, { stream: true })\n }\n\n return result\n}\n\nexport async function renderToString(element: ReactNode) {\n return await streamToString(await renderToReadableStream(element))\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,oBAAuC;AAEvC,eAAe,eAAe,QAAwB;AACpD,QAAM,SAAS,OAAO,UAAU;AAChC,QAAM,UAAU,IAAI,YAAY;AAEhC,MAAI,SAAS;AAEb,SAAO,MAAM;AACX,UAAM,EAAE,MAAM,MAAM,IAAI,MAAM,OAAO,KAAK;AAC1C,QAAI;AAAM;AACV,cAAU,QAAQ,OAAO,OAAO,EAAE,QAAQ,KAAK,CAAC;AAAA,EAClD;AAEA,SAAO;AACT;AAEA,eAAsB,eAAe,SAAoB;AACvD,SAAO,MAAM,eAAe,UAAM,sCAAuB,OAAO,CAAC;AACnE;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/state/modules/components-meta.ts"],"sourcesContent":["import { type Action, type UnknownAction, isKnownAction } from '../actions'\nimport { ReadOnlyActionTypes } from '../actions/internal/read-only-action-types'\n\nexport const ComponentIcon = {\n Accordion: 'accordion',\n Audio: 'audio',\n Billing: 'billing',\n Bolt: 'bolt',\n Button: 'button',\n Card: 'card',\n Cards: 'cards',\n Carousel: 'carousel',\n Chats: 'chats',\n Code: 'code',\n Countdown: 'countdown',\n Cube: 'cube',\n Database: 'database',\n Divider: 'divider',\n Form: 'form',\n Gallery: 'gallery',\n Grid: 'grid',\n Help: 'help',\n Image: 'image',\n Layout: 'layout',\n Lock: 'lock',\n Marker: 'marker',\n Navigation: 'navigation',\n Palette: 'palette',\n SocialLinks: 'social-links',\n Star: 'star',\n Table: 'table',\n Tabs: 'tabs',\n Text: 'text',\n Users: 'users',\n Video: 'video',\n} as const\n\nexport type ComponentIcon = (typeof ComponentIcon)[keyof typeof ComponentIcon]\n\nexport type ComponentMeta = {\n label: string\n icon: ComponentIcon\n hidden: boolean\n description?: string\n builtinSuspense?: boolean\n unstable_migration?: {\n replacementType: string\n }\n server?: boolean\n}\n\nexport type State = Map<string, ComponentMeta>\n\nexport function getInitialState({\n componentsMeta = new Map(),\n}: { componentsMeta?: Map<string, ComponentMeta> } = {}): State {\n return componentsMeta\n}\n\nexport function getComponentsMeta(state: State): Map<string, ComponentMeta> {\n return state\n}\n\nexport function getComponentMeta(state: State, type: string): ComponentMeta | null {\n return getComponentsMeta(state).get(type) ?? null\n}\n\nexport function reducer(state: State = getInitialState(), action: Action | UnknownAction): State {\n if (!isKnownAction(action)) return state\n\n switch (action.type) {\n case ReadOnlyActionTypes.REGISTER_COMPONENT:\n return new Map(state).set(action.payload.type, action.payload.meta)\n\n case ReadOnlyActionTypes.UNREGISTER_COMPONENT: {\n const nextState = new Map(state)\n\n const deleted = nextState.delete(action.payload.type)\n\n return deleted ? nextState : state\n }\n\n default:\n return state\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
1
|
+
{"version":3,"sources":["../../../../src/state/modules/components-meta.ts"],"sourcesContent":["import { InjectableProps } from '../../runtimes/react/server/injectable-props'\nimport { type Action, type UnknownAction, isKnownAction } from '../actions'\nimport { ReadOnlyActionTypes } from '../actions/internal/read-only-action-types'\n\nexport const ComponentIcon = {\n Accordion: 'accordion',\n Audio: 'audio',\n Billing: 'billing',\n Bolt: 'bolt',\n Button: 'button',\n Card: 'card',\n Cards: 'cards',\n Carousel: 'carousel',\n Chats: 'chats',\n Code: 'code',\n Countdown: 'countdown',\n Cube: 'cube',\n Database: 'database',\n Divider: 'divider',\n Form: 'form',\n Gallery: 'gallery',\n Grid: 'grid',\n Help: 'help',\n Image: 'image',\n Layout: 'layout',\n Lock: 'lock',\n Marker: 'marker',\n Navigation: 'navigation',\n Palette: 'palette',\n SocialLinks: 'social-links',\n Star: 'star',\n Table: 'table',\n Tabs: 'tabs',\n Text: 'text',\n Users: 'users',\n Video: 'video',\n} as const\n\nexport type ComponentIcon = (typeof ComponentIcon)[keyof typeof ComponentIcon]\n\nexport type ComponentMeta = {\n label: string\n icon: ComponentIcon\n hidden: boolean\n description?: string\n builtinSuspense?: boolean\n unstable_migration?: {\n replacementType: string\n }\n server?: boolean\n injectedProps?: Record<string, keyof InjectableProps>\n}\n\nexport type State = Map<string, ComponentMeta>\n\nexport function getInitialState({\n componentsMeta = new Map(),\n}: { componentsMeta?: Map<string, ComponentMeta> } = {}): State {\n return componentsMeta\n}\n\nexport function getComponentsMeta(state: State): Map<string, ComponentMeta> {\n return state\n}\n\nexport function getComponentMeta(state: State, type: string): ComponentMeta | null {\n return getComponentsMeta(state).get(type) ?? null\n}\n\nexport function reducer(state: State = getInitialState(), action: Action | UnknownAction): State {\n if (!isKnownAction(action)) return state\n\n switch (action.type) {\n case ReadOnlyActionTypes.REGISTER_COMPONENT:\n return new Map(state).set(action.payload.type, action.payload.meta)\n\n case ReadOnlyActionTypes.UNREGISTER_COMPONENT: {\n const nextState = new Map(state)\n\n const deleted = nextState.delete(action.payload.type)\n\n return deleted ? nextState : state\n }\n\n default:\n return state\n }\n}\n"],"mapp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AAO,QAAQ,IAAI;AAEpD,aAAO,UAAU,YAAY;AAAA,IAC/B;AAAA,IAEA;AACE,aAAO;AAAA,EACX;AACF;","names":[]}
|
|
@@ -4,7 +4,7 @@ class MakeswiftGraphQLApiClient {
|
|
|
4
4
|
graphqlClient;
|
|
5
5
|
constructor({ endpoint }) {
|
|
6
6
|
this.graphqlClient = new GraphQLClient(endpoint, {
|
|
7
|
-
"makeswift-runtime-version": "0.28.10-canary.
|
|
7
|
+
"makeswift-runtime-version": "0.28.10-canary.6"
|
|
8
8
|
});
|
|
9
9
|
}
|
|
10
10
|
async getUnversionedResources({
|
|
@@ -150,7 +150,7 @@ class MakeswiftRestAPIClient {
|
|
|
150
150
|
const requestHeaders = new Headers({
|
|
151
151
|
"x-api-key": this.apiKey,
|
|
152
152
|
"makeswift-site-api-key": this.apiKey,
|
|
153
|
-
"makeswift-runtime-version": "0.28.10-canary.
|
|
153
|
+
"makeswift-runtime-version": "0.28.10-canary.6"
|
|
154
154
|
});
|
|
155
155
|
if (siteVersion?.token) {
|
|
156
156
|
requestUrl.searchParams.set("version", siteVersion.version);
|
|
@@ -8,7 +8,7 @@ async function manifestHandler(req, { apiKey, manifest }) {
|
|
|
8
8
|
return ApiResponse.json({ message: "Unauthorized" }, { status: 401 });
|
|
9
9
|
}
|
|
10
10
|
return ApiResponse.json({
|
|
11
|
-
version: "0.28.10-canary.
|
|
11
|
+
version: "0.28.10-canary.6",
|
|
12
12
|
interactionMode: true,
|
|
13
13
|
clientSideNavigation: false,
|
|
14
14
|
elementFromPoint: false,
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { Fragment, forwardRef, useRef, isValidElement, act } from "react";
|
|
3
|
-
import { renderToReadableStream } from "react-dom/server";
|
|
4
3
|
import { JSDOM } from "jsdom";
|
|
5
4
|
import { render, screen } from "@testing-library/react";
|
|
6
5
|
import "@testing-library/jest-dom";
|
|
@@ -9,27 +8,13 @@ import { setIsInBuilder } from "../../../../state/actions/internal/read-only-act
|
|
|
9
8
|
import { MakeswiftComponent } from "../../../../runtimes/react/components/MakeswiftComponent";
|
|
10
9
|
import { Page } from "../../page";
|
|
11
10
|
import { isServer } from "../../../../utils/is-server";
|
|
11
|
+
import { renderToString } from "../../../../runtimes/react/testing/render-to-string";
|
|
12
12
|
import * as Testing from "../../../testing";
|
|
13
13
|
const ROOT_ID = "00000000-0000-0000-0000-000000000000";
|
|
14
14
|
const ELEMENT_ID = "11111111-1111-1111-1111-111111111111";
|
|
15
15
|
const renderProp = (prop) => prop === void 0 ? "undefined" : isValidElement(prop) ? prop : JSON.stringify(prop);
|
|
16
16
|
const propSnapshot = (prop) => prop?.childElementCount ? prop.childNodes : parseStringifiedProp(prop?.textContent ?? "");
|
|
17
17
|
const parseStringifiedProp = (prop) => prop === "undefined" ? void 0 : JSON.parse(prop);
|
|
18
|
-
async function streamToString(stream) {
|
|
19
|
-
const reader = stream.getReader();
|
|
20
|
-
const decoder = new TextDecoder();
|
|
21
|
-
let result = "";
|
|
22
|
-
while (true) {
|
|
23
|
-
const { done, value } = await reader.read();
|
|
24
|
-
if (done)
|
|
25
|
-
break;
|
|
26
|
-
result += decoder.decode(value, { stream: true });
|
|
27
|
-
}
|
|
28
|
-
return result;
|
|
29
|
-
}
|
|
30
|
-
async function renderToString(element) {
|
|
31
|
-
return await streamToString(await renderToReadableStream(element));
|
|
32
|
-
}
|
|
33
18
|
async function serverSideRender(children) {
|
|
34
19
|
const serverInsertedCallbacks = [];
|
|
35
20
|
const elementTree = /* @__PURE__ */ jsx(ServerInsertedHTMLContext.Provider, { value: (handler) => serverInsertedCallbacks.push(handler), children });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../src/next/components/tests/controls/page-control-prop-rendering.tsx"],"sourcesContent":["import { type ReactNode, Fragment, forwardRef, useRef, isValidElement, act } from 'react'\nimport { renderToReadableStream } from 'react-dom/server'\nimport { JSDOM } from 'jsdom'\nimport { render, screen } from '@testing-library/react'\nimport '@testing-library/jest-dom'\nimport { ServerInsertedHTMLContext } from 'next/navigation'\n\nimport { type Data, type ValueType, type DataType, ControlDefinition } from '@makeswift/controls'\n\nimport { type CacheData } from '../../../../api/api-resources-client'\nimport { ElementData } from '../../../../state/read-only-state'\nimport { setIsInBuilder } from '../../../../state/actions/internal/read-only-actions'\nimport { ReactRuntime } from '../../../../runtimes/react/react-runtime'\nimport { MakeswiftComponent } from '../../../../runtimes/react/components/MakeswiftComponent'\nimport { Page } from '../../page'\nimport { isServer } from '../../../../utils/is-server'\nimport * as Testing from '../../../testing'\n\nconst ROOT_ID = '00000000-0000-0000-0000-000000000000'\nconst ELEMENT_ID = '11111111-1111-1111-1111-111111111111'\n\nconst renderProp = (prop: any) =>\n prop === undefined ? 'undefined' : isValidElement(prop) ? prop : JSON.stringify(prop)\n\nconst propSnapshot = (prop: HTMLElement | null) =>\n prop?.childElementCount ? prop.childNodes : parseStringifiedProp(prop?.textContent ?? '')\n\nconst parseStringifiedProp = (prop: string) => (prop === 'undefined' ? undefined : JSON.parse(prop))\n\nasync function streamToString(stream: ReadableStream) {\n const reader = stream.getReader()\n const decoder = new TextDecoder()\n\n let result = ''\n\n while (true) {\n const { done, value } = await reader.read()\n if (done) break\n result += decoder.decode(value, { stream: true })\n }\n\n return result\n}\n\nasync function renderToString(element: ReactNode) {\n return await streamToString(await renderToReadableStream(element))\n}\n\nasync function serverSideRender(children: ReactNode) {\n // wrap the children in a context provider to capture server-inserted HTML, see\n // https://github.com/vercel/next.js/blob/canary/packages/next/src/server/app-render/server-inserted-html.tsx\n const serverInsertedCallbacks: (() => React.ReactNode)[] = []\n\n const elementTree = (\n <ServerInsertedHTMLContext.Provider value={handler => serverInsertedCallbacks.push(handler)}>\n {children}\n </ServerInsertedHTMLContext.Provider>\n )\n\n const elementsHTML = await renderToString(elementTree)\n\n const serverInsertedNodes = serverInsertedCallbacks.map((callback, index) => (\n <Fragment key={'__next_server_inserted__' + index}>{callback()}</Fragment>\n ))\n\n const headHTML = await renderToString(serverInsertedNodes)\n\n const dom = new JSDOM(\n `<!DOCTYPE html><head>${headHTML}</head><body><div id=\"root\">${elementsHTML}</div></body></div>`,\n {\n runScripts: 'dangerously',\n },\n )\n\n return dom.window.document\n}\n\n/**\n * In read-write mode, the runtime opens a `MessageChannel` to the builder\n * parent frame; jsdom doesn't implement `MessageChannel`, so stub them to keep\n * the read-write setup from throwing.\n */\nfunction stubBuilderMessageChannel(): () => void {\n const postMessageSpy = jest.spyOn(window, 'postMessage').mockImplementation(() => {})\n\n const originalMessageChannel = window.MessageChannel\n const stubPort = () => ({ onmessage: null, postMessage: () => {}, close: () => {} })\n window.MessageChannel = class {\n port1 = stubPort()\n port2 = stubPort()\n } as unknown as typeof MessageChannel\n\n return () => {\n postMessageSpy.mockRestore()\n window.MessageChannel = originalMessageChannel\n }\n}\n\nexport async function testPageControlPropRendering<D extends ControlDefinition>(\n controlDefinition: D,\n {\n toData,\n value,\n locale,\n cacheData,\n expectedRenders,\n registerComponents,\n action,\n rootElements = [],\n isInBuilder = false,\n isReadOnly = true,\n }: {\n toData?: (value: ValueType<D>) => DataType<D>\n value: ValueType<D> | undefined\n locale?: string | null\n cacheData?: Partial<CacheData>\n expectedRenders?: number\n registerComponents?: (runtime: ReactRuntime) => void\n action?: (element: HTMLElement) => Promise<void>\n rootElements?: ElementData[]\n isInBuilder?: boolean\n isReadOnly?: boolean\n },\n) {\n // Arrange\n const controlData: DataType<D> | Data =\n value !== undefined ? (toData ? toData(value) : controlDefinition.toData(value)) : undefined\n\n const testComponentMeta = {\n type: 'TestComponent',\n label: 'Test Component',\n }\n\n const testId = 'test-id'\n const renderCountTestId = 'render-count-test-id'\n const elementData: ElementData = {\n key: ELEMENT_ID,\n type: testComponentMeta.type,\n props: {\n propKey: controlData,\n },\n }\n\n const runtime = Testing.createReactRuntime()\n runtime.protoStore.dispatch(setIsInBuilder(isInBuilder))\n registerComponents?.(runtime)\n\n // Act\n runtime.registerComponent(\n forwardRef<HTMLDivElement, { propKey?: any }>(({ propKey }, ref) => {\n const renderCount = useRef(0)\n ++renderCount.current\n\n return (\n <div ref={ref}>\n <div data-testid={renderCountTestId}>{renderCount.current}</div>\n <div data-testid={testId}>{renderProp(propKey)}</div>\n </div>\n )\n }),\n {\n ...testComponentMeta,\n props: {\n propKey: controlDefinition as any,\n },\n },\n )\n\n const testElementTree = (component: ReactNode) => {\n // The runtime enters the read-write state when a non-null site version is\n // passed\n const siteVersion = isReadOnly ? null : { token: 'test-token', version: 'draft' }\n return (\n <Testing.ReactProvider runtime={runtime} siteVersion={siteVersion}>\n {component}\n </Testing.ReactProvider>\n )\n }\n\n if (!isServer()) {\n const restoreMessageChannel = isReadOnly ? null : stubBuilderMessageChannel()\n\n const rootElementData: ElementData = Testing.createRootComponent(\n [elementData, ...rootElements],\n ROOT_ID,\n )\n\n const snapshot = Testing.createMakeswiftPageSnapshot(rootElementData, { locale, cacheData })\n\n // Assert\n await act(async () => render(testElementTree(<Page snapshot={snapshot} />)))\n\n if (action) {\n await act(async () => {\n await action(screen.getByTestId(testId))\n })\n }\n\n expect(snapshot).toMatchSnapshot('snapshot')\n expect(propSnapshot(screen.getByTestId(testId))).toMatchSnapshot('resolvedValue')\n\n if (expectedRenders != null) {\n expect(Number(screen.getByTestId(renderCountTestId).textContent)).toBe(expectedRenders)\n }\n\n restoreMessageChannel?.()\n } else {\n // test server-side rendering using a component snapshot\n console.assert(action == null)\n console.assert(rootElements.length === 0)\n\n const snapshot = Testing.createMakeswiftComponentSnapshot(elementData, { locale, cacheData })\n const elementTree = testElementTree(\n <MakeswiftComponent snapshot={snapshot} {...testComponentMeta} />,\n )\n\n const document = await serverSideRender(elementTree)\n const getByTestId = (id: string): HTMLElement | null =>\n document.querySelector(`[data-testid=\"${id}\"]`)\n\n expect(propSnapshot(getByTestId(testId))).toMatchSnapshot('resolvedValue')\n expect([...document.querySelectorAll('style')].map(n => n.textContent)).toMatchSnapshot(\n 'component sty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AAO,aAAa,WAAW,CAAC;AAExC,UAAM,WAAW,QAAQ,iCAAiC,aAAa,EAAE,QAAQ,UAAU,CAAC;AAC5F,UAAM,cAAc;AAAA,MAClB,oBAAC,sBAAmB,UAAqB,GAAG,mBAAmB;AAAA,IACjE;AAEA,UAAM,WAAW,MAAM,iBAAiB,WAAW;AACnD,UAAM,cAAc,CAAC,OACnB,SAAS,cAAc,iBAAiB,EAAE,IAAI;AAEhD,WAAO,aAAa,YAAY,MAAM,CAAC,CAAC,EAAE,gBAAgB,eAAe;AACzE,WAAO,CAAC,GAAG,SAAS,iBAAiB,OAAO,CAAC,EAAE,IAAI,OAAK,EAAE,WAAW,CAAC,EAAE;AAAA,MACtE;AAAA,IACF;AACA,WAAO,OAAO,YAAY,iBAAiB,GAAG,WAAW,CAAC,EAAE,KAAK,CAAC;AAAA,EACpE;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../../../../src/next/components/tests/controls/page-control-prop-rendering.tsx"],"sourcesContent":["import { type ReactNode, Fragment, forwardRef, useRef, isValidElement, act } from 'react'\nimport { JSDOM } from 'jsdom'\nimport { render, screen } from '@testing-library/react'\nimport '@testing-library/jest-dom'\nimport { ServerInsertedHTMLContext } from 'next/navigation'\n\nimport { type Data, type ValueType, type DataType, ControlDefinition } from '@makeswift/controls'\n\nimport { type CacheData } from '../../../../api/api-resources-client'\nimport { ElementData } from '../../../../state/read-only-state'\nimport { setIsInBuilder } from '../../../../state/actions/internal/read-only-actions'\nimport { ReactRuntime } from '../../../../runtimes/react/react-runtime'\nimport { MakeswiftComponent } from '../../../../runtimes/react/components/MakeswiftComponent'\nimport { Page } from '../../page'\nimport { isServer } from '../../../../utils/is-server'\n\nimport { renderToString } from '../../../../runtimes/react/testing/render-to-string'\nimport * as Testing from '../../../testing'\n\nconst ROOT_ID = '00000000-0000-0000-0000-000000000000'\nconst ELEMENT_ID = '11111111-1111-1111-1111-111111111111'\n\nconst renderProp = (prop: any) =>\n prop === undefined ? 'undefined' : isValidElement(prop) ? prop : JSON.stringify(prop)\n\nconst propSnapshot = (prop: HTMLElement | null) =>\n prop?.childElementCount ? prop.childNodes : parseStringifiedProp(prop?.textContent ?? '')\n\nconst parseStringifiedProp = (prop: string) => (prop === 'undefined' ? undefined : JSON.parse(prop))\n\nasync function serverSideRender(children: ReactNode) {\n // wrap the children in a context provider to capture server-inserted HTML, see\n // https://github.com/vercel/next.js/blob/canary/packages/next/src/server/app-render/server-inserted-html.tsx\n const serverInsertedCallbacks: (() => React.ReactNode)[] = []\n\n const elementTree = (\n <ServerInsertedHTMLContext.Provider value={handler => serverInsertedCallbacks.push(handler)}>\n {children}\n </ServerInsertedHTMLContext.Provider>\n )\n\n const elementsHTML = await renderToString(elementTree)\n\n const serverInsertedNodes = serverInsertedCallbacks.map((callback, index) => (\n <Fragment key={'__next_server_inserted__' + index}>{callback()}</Fragment>\n ))\n\n const headHTML = await renderToString(serverInsertedNodes)\n\n const dom = new JSDOM(\n `<!DOCTYPE html><head>${headHTML}</head><body><div id=\"root\">${elementsHTML}</div></body></div>`,\n {\n runScripts: 'dangerously',\n },\n )\n\n return dom.window.document\n}\n\n/**\n * In read-write mode, the runtime opens a `MessageChannel` to the builder\n * parent frame; jsdom doesn't implement `MessageChannel`, so stub them to keep\n * the read-write setup from throwing.\n */\nfunction stubBuilderMessageChannel(): () => void {\n const postMessageSpy = jest.spyOn(window, 'postMessage').mockImplementation(() => {})\n\n const originalMessageChannel = window.MessageChannel\n const stubPort = () => ({ onmessage: null, postMessage: () => {}, close: () => {} })\n window.MessageChannel = class {\n port1 = stubPort()\n port2 = stubPort()\n } as unknown as typeof MessageChannel\n\n return () => {\n postMessageSpy.mockRestore()\n window.MessageChannel = originalMessageChannel\n }\n}\n\nexport async function testPageControlPropRendering<D extends ControlDefinition>(\n controlDefinition: D,\n {\n toData,\n value,\n locale,\n cacheData,\n expectedRenders,\n registerComponents,\n action,\n rootElements = [],\n isInBuilder = false,\n isReadOnly = true,\n }: {\n toData?: (value: ValueType<D>) => DataType<D>\n value: ValueType<D> | undefined\n locale?: string | null\n cacheData?: Partial<CacheData>\n expectedRenders?: number\n registerComponents?: (runtime: ReactRuntime) => void\n action?: (element: HTMLElement) => Promise<void>\n rootElements?: ElementData[]\n isInBuilder?: boolean\n isReadOnly?: boolean\n },\n) {\n // Arrange\n const controlData: DataType<D> | Data =\n value !== undefined ? (toData ? toData(value) : controlDefinition.toData(value)) : undefined\n\n const testComponentMeta = {\n type: 'TestComponent',\n label: 'Test Component',\n }\n\n const testId = 'test-id'\n const renderCountTestId = 'render-count-test-id'\n const elementData: ElementData = {\n key: ELEMENT_ID,\n type: testComponentMeta.type,\n props: {\n propKey: controlData,\n },\n }\n\n const runtime = Testing.createReactRuntime()\n runtime.protoStore.dispatch(setIsInBuilder(isInBuilder))\n registerComponents?.(runtime)\n\n // Act\n runtime.registerComponent(\n forwardRef<HTMLDivElement, { propKey?: any }>(({ propKey }, ref) => {\n const renderCount = useRef(0)\n ++renderCount.current\n\n return (\n <div ref={ref}>\n <div data-testid={renderCountTestId}>{renderCount.current}</div>\n <div data-testid={testId}>{renderProp(propKey)}</div>\n </div>\n )\n }),\n {\n ...testComponentMeta,\n props: {\n propKey: controlDefinition as any,\n },\n },\n )\n\n const testElementTree = (component: ReactNode) => {\n // The runtime enters the read-write state when a non-null site version is\n // passed\n const siteVersion = isReadOnly ? null : { token: 'test-token', version: 'draft' }\n return (\n <Testing.ReactProvider runtime={runtime} siteVersion={siteVersion}>\n {component}\n </Testing.ReactProvider>\n )\n }\n\n if (!isServer()) {\n const restoreMessageChannel = isReadOnly ? null : stubBuilderMessageChannel()\n\n const rootElementData: ElementData = Testing.createRootComponent(\n [elementData, ...rootElements],\n ROOT_ID,\n )\n\n const snapshot = Testing.createMakeswiftPageSnapshot(rootElementData, { locale, cacheData })\n\n // Assert\n await act(async () => render(testElementTree(<Page snapshot={snapshot} />)))\n\n if (action) {\n await act(async () => {\n await action(screen.getByTestId(testId))\n })\n }\n\n expect(snapshot).toMatchSnapshot('snapshot')\n expect(propSnapshot(screen.getByTestId(testId))).toMatchSnapshot('resolvedValue')\n\n if (expectedRenders != null) {\n expect(Number(screen.getByTestId(renderCountTestId).textContent)).toBe(expectedRenders)\n }\n\n restoreMessageChannel?.()\n } else {\n // test server-side rendering using a component snapshot\n console.assert(action == null)\n console.assert(rootElements.length === 0)\n\n const snapshot = Testing.createMakeswiftComponentSnapshot(elementData, { locale, cacheData })\n const elementTree = testElementTree(\n <MakeswiftComponent snapshot={snapshot} {...testComponentMeta} />,\n )\n\n const document = await serverSideRender(elementTree)\n const getByTestId = (id: string): HTMLElement | null =>\n document.querySelector(`[data-testid=\"${id}\"]`)\n\n expect(propSnapshot(getByTestId(testId))).toMatchSnapshot('resolvedValue')\n expect([...document.querySelectorAll('style')].map(n => n.textContent)).toMatchSnapshot(\n 'component styles',\n )\n expect(Number(getByTestId(renderCountTestId)?.textContent)).toBe(1)\n }\n}\n"],"mappings":"AAoCI,cAoGI,YApGJ;AApCJ,SAAyB,UAAU,YAAY,QAAQ,gBAAgB,WAAW;AAClF,SAAS,aAAa;AACtB,SAAS,QAAQ,cAAc;AAC/B,OAAO;AACP,SAAS,iCAAiC;AAM1C,SAAS,sBAAsB;AAE/B,SAAS,0BAA0B;AACnC,SAAS,YAAY;AACrB,SAAS,gBAAgB;AAEzB,SAAS,sBAAsB;AAC/B,YAAY,aAAa;AAEzB,MAAM,UAAU;AAChB,MAAM,aAAa;AAEnB,MAAM,aAAa,CAAC,SAClB,SAAS,SAAY,cAAc,eAAe,IAAI,IAAI,OAAO,KAAK,UAAU,IAAI;AAEtF,MAAM,eAAe,CAAC,SACpB,MAAM,oBAAoB,KAAK,aAAa,qBAAqB,MAAM,eAAe,EAAE;AAE1F,MAAM,uBAAuB,CAAC,SAAkB,SAAS,cAAc,SAAY,KAAK,MAAM,IAAI;AAElG,eAAe,iBAAiB,UAAqB;AAGnD,QAAM,0BAAqD,CAAC;AAE5D,QAAM,cACJ,oBAAC,0BAA0B,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,aAAO,OAAO,OAAO,YAAY,iBAAiB,EAAE,WAAW,CAAC,EAAE,KAAK,eAAe;AAAA,IACxF;AAEA,4BAAwB;AAAA,EAC1B,OAAO;AAEL,YAAQ,OAAO,UAAU,IAAI;AAC7B,YAAQ,OAAO,aAAa,WAAW,CAAC;AAExC,UAAM,WAAW,QAAQ,iCAAiC,aAAa,EAAE,QAAQ,UAAU,CAAC;AAC5F,UAAM,cAAc;AAAA,MAClB,oBAAC,sBAAmB,UAAqB,GAAG,mBAAmB;AAAA,IACjE;AAEA,UAAM,WAAW,MAAM,iBAAiB,WAAW;AACnD,UAAM,cAAc,CAAC,OACnB,SAAS,cAAc,iBAAiB,EAAE,IAAI;AAEhD,WAAO,aAAa,YAAY,MAAM,CAAC,CAAC,EAAE,gBAAgB,eAAe;AACzE,WAAO,CAAC,GAAG,SAAS,iBAAiB,OAAO,CAAC,EAAE,IAAI,OAAK,EAAE,WAAW,CAAC,EAAE;AAAA,MACtE;AAAA,IACF;AACA,WAAO,OAAO,YAAY,iBAAiB,GAAG,WAAW,CAAC,EAAE,KAAK,CAAC;AAAA,EACpE;AACF;","names":[]}
|
|
@@ -27,10 +27,12 @@ class ReactRuntimeCore extends RuntimeCore {
|
|
|
27
27
|
server = false,
|
|
28
28
|
props
|
|
29
29
|
}) {
|
|
30
|
+
const isServerComponent = server !== false;
|
|
31
|
+
const injectedProps = typeof server === "object" ? server.unstable_injectedProps : {};
|
|
30
32
|
validateComponentType(
|
|
31
33
|
// make sure we don't access `component?.name` and trigger loading of the server
|
|
32
34
|
// component unless we're running in the RSC environment
|
|
33
|
-
|
|
35
|
+
isServerComponent && !this.isRSCEnv() ? { type, componentName: label || "Unknown server component" } : {
|
|
34
36
|
type,
|
|
35
37
|
componentName: component?.name || label || "Unknown component"
|
|
36
38
|
}
|
|
@@ -38,7 +40,16 @@ class ReactRuntimeCore extends RuntimeCore {
|
|
|
38
40
|
const unregisterComponent = this.protoStore.dispatch(
|
|
39
41
|
registerComponentEffect(
|
|
40
42
|
type,
|
|
41
|
-
{
|
|
43
|
+
{
|
|
44
|
+
label,
|
|
45
|
+
icon,
|
|
46
|
+
hidden,
|
|
47
|
+
description,
|
|
48
|
+
builtinSuspense,
|
|
49
|
+
unstable_migration,
|
|
50
|
+
server: isServerComponent,
|
|
51
|
+
injectedProps
|
|
52
|
+
},
|
|
42
53
|
props ?? {}
|
|
43
54
|
)
|
|
44
55
|
);
|
|
@@ -47,7 +58,7 @@ class ReactRuntimeCore extends RuntimeCore {
|
|
|
47
58
|
"builtinSuspense is ignored in React >= 19.2; components are always wrapped in <Activity>."
|
|
48
59
|
);
|
|
49
60
|
}
|
|
50
|
-
if (
|
|
61
|
+
if (isServerComponent && !this.isRSCEnv()) {
|
|
51
62
|
return () => {
|
|
52
63
|
unregisterComponent();
|
|
53
64
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/runtimes/react/react-runtime-core.ts"],"sourcesContent":["import { ControlDefinition as UnifiedControlDefinition } from '@makeswift/controls'\n\nimport { type LegacyDescriptor, type DescriptorValueType } from '../../prop-controllers/descriptors'\n\nimport { supportsActivity } from './components/activity-with-fallback'\n\nimport {\n registerComponentEffect,\n registerReactComponentEffect,\n} from '../../state/actions/internal/read-only-actions'\n\nimport { ComponentIcon } from '../../state/modules/components-meta'\nimport type { ComponentType } from '../../state/read-only-state'\n\nimport { RuntimeCore } from './runtime-core'\n\nfunction validateComponentType({\n type,\n componentName,\n}: {\n type: string\n componentName: string\n}): void {\n if (typeof type !== 'string' || type === '') {\n throw new Error(\n `${componentName}: A non-empty string \\`type\\` is required for component registration, got ${type}`,\n )\n }\n}\n\nexport class ReactRuntimeCore extends RuntimeCore {\n registerComponent<\n ControlDef extends UnifiedControlDefinition,\n P extends Record<string, LegacyDescriptor | ControlDef>,\n
|
|
1
|
+
{"version":3,"sources":["../../../../src/runtimes/react/react-runtime-core.ts"],"sourcesContent":["import { type Component, type PropsWithoutRef, type ReactNode, type RefAttributes } from 'react'\n\nimport { ControlDefinition as UnifiedControlDefinition } from '@makeswift/controls'\n\nimport { type LegacyDescriptor, type DescriptorValueType } from '../../prop-controllers/descriptors'\n\nimport { supportsActivity } from './components/activity-with-fallback'\n\nimport {\n registerComponentEffect,\n registerReactComponentEffect,\n} from '../../state/actions/internal/read-only-actions'\n\nimport { ComponentIcon } from '../../state/modules/components-meta'\nimport type { ComponentType } from '../../state/read-only-state'\n\nimport { type InjectableProps } from './server/injectable-props'\n\nimport { RuntimeCore } from './runtime-core'\n\nfunction validateComponentType({\n type,\n componentName,\n}: {\n type: string\n componentName: string\n}): void {\n if (typeof type !== 'string' || type === '') {\n throw new Error(\n `${componentName}: A non-empty string \\`type\\` is required for component registration, got ${type}`,\n )\n }\n}\n\ntype InjectedPropsConfig = Record<string, keyof InjectableProps>\n\ntype ServerComponentConfig<I extends InjectedPropsConfig> =\n | boolean\n | {\n unstable_injectedProps: I\n }\n\ntype InjectedProps<I extends InjectedPropsConfig> = {\n [K in keyof I]: InjectableProps[I[K]]\n}\n\ntype ResolvedProps<P extends Record<string, LegacyDescriptor | UnifiedControlDefinition>> = {\n [K in keyof P]: DescriptorValueType<P[K]>\n}\n\ntype RegisteredComponentType<\n P extends Record<string, LegacyDescriptor | UnifiedControlDefinition>,\n I extends InjectedPropsConfig,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n T = any,\n> =\n | {\n new (\n props: PropsWithoutRef<ResolvedProps<P>> & InjectedProps<I> & RefAttributes<T>,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n context?: any,\n ): Component<ResolvedProps<P> & InjectedProps<I>>\n }\n | ((\n props: PropsWithoutRef<ResolvedProps<P>> & InjectedProps<I> & RefAttributes<T>,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n context?: any,\n ) => ReactNode)\n\nexport class ReactRuntimeCore extends RuntimeCore {\n registerComponent<\n ControlDef extends UnifiedControlDefinition,\n P extends Record<string, LegacyDescriptor | ControlDef>,\n // eslint-disable-next-line @typescript-eslint/no-empty-object-type\n const I extends InjectedPropsConfig = {},\n C extends RegisteredComponentType<P, I> = RegisteredComponentType<P, I>,\n >(\n component: C,\n {\n type,\n label,\n icon = ComponentIcon.Cube,\n hidden = false,\n description,\n builtinSuspense,\n unstable_migration,\n server = false,\n props,\n }: {\n type: string\n label: string\n icon?: ComponentIcon\n hidden?: boolean\n description?: string\n /**\n * In React <= 19.1, controls the default `<Suspense>` boundary.\n * Ignored in React >= 19.2; components are always wrapped in `<Activity>`.\n * Defaults to `true`.\n */\n builtinSuspense?: boolean\n /**\n * Marks this registration as superseded by `replacementType`. When\n * `replacementType` differs from `type`, the builder offers a way to\n * update existing instances.\n */\n unstable_migration?: { replacementType: string }\n server?: ServerComponentConfig<I>\n props?: P\n },\n ): () => void {\n const isServerComponent = server !== false\n const injectedProps = typeof server === 'object' ? server.unstable_injectedProps : {}\n\n validateComponentType(\n // make sure we don't access `component?.name` and trigger loading of the server\n // component unless we're running in the RSC environment\n isServerComponent && !this.isRSCEnv()\n ? { type, componentName: label || 'Unknown server component' }\n : {\n type,\n componentName: component?.name || label || 'Unknown component',\n },\n )\n\n const unregisterComponent = this.protoStore.dispatch(\n registerComponentEffect(\n type,\n {\n label,\n icon,\n hidden,\n description,\n builtinSuspense,\n unstable_migration,\n server: isServerComponent,\n injectedProps,\n },\n props ?? {},\n ),\n )\n\n if (supportsActivity() && builtinSuspense !== undefined) {\n console.warn(\n 'builtinSuspense is ignored in React >= 19.2; components are always wrapped in <Activity>.',\n )\n }\n\n if (isServerComponent && !this.isRSCEnv()) {\n // we can't load server components code outside of the RSC environment, but we also\n // don't need to: if everything is set up correctly, React has already rendered and\n // streamed the corresponding React elements to the client for us -- see\n // `ServerElementsCache` and `ElementDataServer`\n return () => {\n unregisterComponent()\n }\n }\n\n const unregisterReactComponent = this.protoStore.dispatch(\n registerReactComponentEffect(type, component as unknown as ComponentType),\n )\n\n return () => {\n unregisterComponent()\n unregisterReactComponent()\n }\n }\n\n protected isRSCEn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qC;AAAA,IAC1E;AAEA,WAAO,MAAM;AACX,0BAAoB;AACpB,+BAAyB;AAAA,IAC3B;AAAA,EACF;AAAA,EAEU,WAAW;AACnB,WAAO;AAAA,EACT;AACF;","names":[]}
|
|
@@ -17,7 +17,8 @@ import { resolveProps } from "../resolve-props";
|
|
|
17
17
|
async function ServerElementData({
|
|
18
18
|
documentKey,
|
|
19
19
|
context,
|
|
20
|
-
elementData
|
|
20
|
+
elementData,
|
|
21
|
+
injectedProps
|
|
21
22
|
}) {
|
|
22
23
|
const state = getStore(context).getState();
|
|
23
24
|
const Component = getReactComponent(state, elementData.type);
|
|
@@ -44,7 +45,10 @@ async function ServerElementData({
|
|
|
44
45
|
getBreakpoints(state),
|
|
45
46
|
elementData.key
|
|
46
47
|
);
|
|
47
|
-
const props =
|
|
48
|
+
const props = {
|
|
49
|
+
...await resolveProps(context, elementData, documentKey, definitions, stylesheet),
|
|
50
|
+
...injectedProps
|
|
51
|
+
};
|
|
48
52
|
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
49
53
|
/* @__PURE__ */ jsx(Component, { ...props }, elementData.key),
|
|
50
54
|
/* @__PURE__ */ jsx(InjectServerCSS, { collector: cssCollector, elementKey: elementData.key })
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../src/runtimes/react/server/components/element-data.tsx"],"sourcesContent":["import { type ReactNode } from 'react'\n\nimport { partitionRecord } from '../../../../utils/partition'\n\nimport {\n type State,\n type ElementData,\n getReactComponent,\n getBreakpoints,\n getComponentPropControllerDescriptors,\n} from '../../../../state/read-only-state'\n\nimport { FallbackComponent } from '../../../../components/shared/FallbackComponent'\nimport { isLegacyDescriptor } from '../../../../prop-controllers/descriptors'\n\nimport {\n ServerCSSCollector,\n createCollectingServerStylesheet,\n InjectServerCSS,\n} from '../css/server-css'\nimport { type ServerRenderContext, getStore } from '../render-context'\nimport { resolveProps } from '../resolve-props'\n\nexport async function ServerElementData({\n documentKey,\n context,\n elementData,\n}: {\n documentKey: string\n context: ServerRenderContext\n elementData: ElementData\n}): Promise<ReactNode> {\n const state = getStore(context).getState()\n\n const Component = getReactComponent(state, elementData.type)\n if (Component == null) {\n return (\n <FallbackComponent\n text=\"Component not found\"\n details={`Unknown component '${elementData.type}'`}\n />\n )\n }\n\n const [legacyDescriptors, definitions] = getControlDefs(state, elementData)\n const legacyKeys = Object.keys(legacyDescriptors)\n if (legacyKeys.length > 0) {\n console.warn(`Unexpected legacy control data in server element '${elementData.key}`, {\n elementData,\n legacyKeys,\n })\n }\n\n const cssCollector = new ServerCSSCollector()\n const stylesheet = createCollectingServerStylesheet(\n cssCollector,\n getBreakpoints(state),\n elementData.key,\n )\n\n const props = await resolveProps(context, elementData, documentKey, definitions, stylesheet)\n\n return (\n <>\n {/* Make the component the first child so that `findDOMNode` resolves to its first\n rendered DOM node (if any) rather than the component's `<style>` element */}\n <Component key={elementData.key} {...props} />\n <InjectServerCSS collector={cssCollector} elementKey={elementData.key} />\n </>\n )\n}\n\nconst getControlDefs = (state: State, elementData: ElementData) => {\n const descriptors = getComponentPropControllerDescriptors(state, elementData.type) ?? {}\n return partitionRecord(descriptors, isLegacyDescriptor)\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../../../../src/runtimes/react/server/components/element-data.tsx"],"sourcesContent":["import { type ReactNode } from 'react'\n\nimport { partitionRecord } from '../../../../utils/partition'\n\nimport {\n type State,\n type ElementData,\n getReactComponent,\n getBreakpoints,\n getComponentPropControllerDescriptors,\n} from '../../../../state/read-only-state'\n\nimport { FallbackComponent } from '../../../../components/shared/FallbackComponent'\nimport { isLegacyDescriptor } from '../../../../prop-controllers/descriptors'\n\nimport {\n ServerCSSCollector,\n createCollectingServerStylesheet,\n InjectServerCSS,\n} from '../css/server-css'\nimport { type ServerRenderContext, getStore } from '../render-context'\nimport { resolveProps } from '../resolve-props'\n\nexport async function ServerElementData({\n documentKey,\n context,\n elementData,\n injectedProps,\n}: {\n documentKey: string\n context: ServerRenderContext\n elementData: ElementData\n injectedProps: Record<string, unknown>\n}): Promise<ReactNode> {\n const state = getStore(context).getState()\n\n const Component = getReactComponent(state, elementData.type)\n if (Component == null) {\n return (\n <FallbackComponent\n text=\"Component not found\"\n details={`Unknown component '${elementData.type}'`}\n />\n )\n }\n\n const [legacyDescriptors, definitions] = getControlDefs(state, elementData)\n const legacyKeys = Object.keys(legacyDescriptors)\n if (legacyKeys.length > 0) {\n console.warn(`Unexpected legacy control data in server element '${elementData.key}`, {\n elementData,\n legacyKeys,\n })\n }\n\n const cssCollector = new ServerCSSCollector()\n const stylesheet = createCollectingServerStylesheet(\n cssCollector,\n getBreakpoints(state),\n elementData.key,\n )\n\n const props = {\n ...(await resolveProps(context, elementData, documentKey, definitions, stylesheet)),\n ...injectedProps,\n }\n\n return (\n <>\n {/* Make the component the first child so that `findDOMNode` resolves to its first\n rendered DOM node (if any) rather than the component's `<style>` element */}\n <Component key={elementData.key} {...props} />\n <InjectServerCSS collector={cssCollector} elementKey={elementData.key} />\n </>\n )\n}\n\nconst getControlDefs = (state: State, elementData: ElementData) => {\n const descriptors = getComponentPropControllerDescriptors(state, elementData.type) ?? {}\n return partitionRecord(descriptors, isLegacyDescriptor)\n}\n"],"mappings":"AAuCM,SA6BF,UA7BE,KA6BF,YA7BE;AArCN,SAAS,uBAAuB;AAEhC;AAAA,EAGE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAAS,yBAAyB;AAClC,SAAS,0BAA0B;AAEnC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAmC,gBAAgB;AACnD,SAAS,oBAAoB;AAE7B,eAAsB,kBAAkB;AAAA,EACtC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAKuB;AACrB,QAAM,QAAQ,SAAS,OAAO,EAAE,SAAS;AAEzC,QAAM,YAAY,kBAAkB,OAAO,YAAY,IAAI;AAC3D,MAAI,aAAa,MAAM;AACrB,WACE;AAAA,MAAC;AAAA;AAAA,QACC,MAAK;AAAA,QACL,SAAS,sBAAsB,YAAY,IAAI;AAAA;AAAA,IACjD;AAAA,EAEJ;AAEA,QAAM,CAAC,mBAAmB,WAAW,IAAI,eAAe,OAAO,WAAW;AAC1E,QAAM,aAAa,OAAO,KAAK,iBAAiB;AAChD,MAAI,WAAW,SAAS,GAAG;AACzB,YAAQ,KAAK,qDAAqD,YAAY,GAAG,IAAI;AAAA,MACnF;AAAA,MACA;AAAA,IACF,CAAC;AAAA,EACH;AAEA,QAAM,eAAe,IAAI,mBAAmB;AAC5C,QAAM,aAAa;AAAA,IACjB;AAAA,IACA,eAAe,KAAK;AAAA,IACpB,YAAY;AAAA,EACd;AAEA,QAAM,QAAQ;AAAA,IACZ,GAAI,MAAM,aAAa,SAAS,aAAa,aAAa,aAAa,UAAU;AAAA,IACjF,GAAG;AAAA,EACL;AAEA,SACE,iCAGE;AAAA,wBAAC,aAAiC,GAAG,SAArB,YAAY,GAAgB;AAAA,IAC5C,oBAAC,mBAAgB,WAAW,cAAc,YAAY,YAAY,KAAK;AAAA,KACzE;AAEJ;AAEA,MAAM,iBAAiB,CAAC,OAAc,gBAA6B;AACjE,QAAM,cAAc,sCAAsC,OAAO,YAAY,IAAI,KAAK,CAAC;AACvF,SAAO,gBAAgB,aAAa,kBAAkB;AACxD;","names":[]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { mapValues } from "@makeswift/controls";
|
|
2
3
|
import {
|
|
3
4
|
isElementReference,
|
|
4
5
|
getComponentsMeta
|
|
@@ -26,11 +27,28 @@ function ServerElement({
|
|
|
26
27
|
}
|
|
27
28
|
);
|
|
28
29
|
}
|
|
30
|
+
const elementKey = element.key;
|
|
29
31
|
const isRSC = elementMeta.server ?? false;
|
|
30
32
|
if (!isRSC) {
|
|
31
|
-
return /* @__PURE__ */ jsx(ClientElement, { element },
|
|
33
|
+
return /* @__PURE__ */ jsx(ClientElement, { element }, elementKey);
|
|
32
34
|
}
|
|
33
|
-
|
|
35
|
+
const injectableProps = {
|
|
36
|
+
elementKey,
|
|
37
|
+
documentKey
|
|
38
|
+
};
|
|
39
|
+
const injectedProps = mapValues(
|
|
40
|
+
elementMeta.injectedProps ?? {},
|
|
41
|
+
(propName) => injectableProps[propName]
|
|
42
|
+
);
|
|
43
|
+
return /* @__PURE__ */ jsx(
|
|
44
|
+
ServerElementData,
|
|
45
|
+
{
|
|
46
|
+
documentKey,
|
|
47
|
+
context,
|
|
48
|
+
elementData: element,
|
|
49
|
+
injectedProps
|
|
50
|
+
}
|
|
51
|
+
);
|
|
34
52
|
}
|
|
35
53
|
export {
|
|
36
54
|
ServerElement
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../src/runtimes/react/server/components/element.tsx"],"sourcesContent":["import { ReactNode } from 'react'\n\nimport {\n isElementReference,\n getComponentsMeta,\n type Element as ElementDataOrRef,\n} from '../../../../state/read-only-state'\n\nimport { FallbackComponent } from '../../../../components/shared/FallbackComponent'\n\nimport { Element as ClientElement } from '../../components/Element'\n\nimport { type ServerRenderContext, getStore } from '../render-context'\n\nimport { ServerElementData } from './element-data'\n\nexport function ServerElement({\n context,\n element,\n documentKey,\n}: {\n context: ServerRenderContext\n element: ElementDataOrRef\n documentKey: string\n}): ReactNode {\n // check for element references first to avoid looking them up as regular components\n if (isElementReference(element)) {\n return <FallbackComponent text=\"Element reference is not supported on server yet\" />\n }\n\n const state = getStore(context).getState()\n const elementMeta = getComponentsMeta(state).get(element.type)\n if (elementMeta == null) {\n return (\n <FallbackComponent\n text=\"Component not found\"\n details={`Missing component metadata for '${element.type}'`}\n />\n )\n }\n\n const isRSC = elementMeta.server ?? false\n if (!isRSC) {\n return <ClientElement key={
|
|
1
|
+
{"version":3,"sources":["../../../../../../src/runtimes/react/server/components/element.tsx"],"sourcesContent":["import { ReactNode } from 'react'\n\nimport { mapValues } from '@makeswift/controls'\n\nimport {\n isElementReference,\n getComponentsMeta,\n type Element as ElementDataOrRef,\n} from '../../../../state/read-only-state'\n\nimport { FallbackComponent } from '../../../../components/shared/FallbackComponent'\n\nimport { Element as ClientElement } from '../../components/Element'\n\nimport { type ServerRenderContext, getStore } from '../render-context'\nimport { type InjectableProps } from '../injectable-props'\n\nimport { ServerElementData } from './element-data'\n\nexport function ServerElement({\n context,\n element,\n documentKey,\n}: {\n context: ServerRenderContext\n element: ElementDataOrRef\n documentKey: string\n}): ReactNode {\n // check for element references first to avoid looking them up as regular components\n if (isElementReference(element)) {\n return <FallbackComponent text=\"Element reference is not supported on server yet\" />\n }\n\n const state = getStore(context).getState()\n const elementMeta = getComponentsMeta(state).get(element.type)\n if (elementMeta == null) {\n return (\n <FallbackComponent\n text=\"Component not found\"\n details={`Missing component metadata for '${element.type}'`}\n />\n )\n }\n\n const elementKey = element.key\n const isRSC = elementMeta.server ?? false\n if (!isRSC) {\n return <ClientElement key={elementKey} element={element} />\n }\n\n const injectableProps: InjectableProps = {\n elementKey,\n documentKey,\n }\n\n const injectedProps = mapValues(\n elementMeta.injectedProps ?? {},\n propName => injectableProps[propName],\n )\n\n return (\n <ServerElementData\n documentKey={documentKey}\n context={context}\n elementData={element}\n injectedProps={injectedProps}\n />\n )\n}\n"],"mappings":"AA8BW;AA5BX,SAAS,iBAAiB;AAE1B;AAAA,EACE;AAAA,EACA;AAAA,OAEK;AAEP,SAAS,yBAAyB;AAElC,SAAS,WAAW,qBAAqB;AAEzC,SAAmC,gBAAgB;AAGnD,SAAS,yBAAyB;AAE3B,SAAS,cAAc;AAAA,EAC5B;AAAA,EACA;AAAA,EACA;AACF,GAIc;AAEZ,MAAI,mBAAmB,OAAO,GAAG;AAC/B,WAAO,oBAAC,qBAAkB,MAAK,oDAAmD;AAAA,EACpF;AAEA,QAAM,QAAQ,SAAS,OAAO,EAAE,SAAS;AACzC,QAAM,cAAc,kBAAkB,KAAK,EAAE,IAAI,QAAQ,IAAI;AAC7D,MAAI,eAAe,MAAM;AACvB,WACE;AAAA,MAAC;AAAA;AAAA,QACC,MAAK;AAAA,QACL,SAAS,mCAAmC,QAAQ,IAAI;AAAA;AAAA,IAC1D;AAAA,EAEJ;AAEA,QAAM,aAAa,QAAQ;AAC3B,QAAM,QAAQ,YAAY,UAAU;AACpC,MAAI,CAAC,OAAO;AACV,WAAO,oBAAC,iBAA+B,WAAZ,UAA8B;AAAA,EAC3D;AAEA,QAAM,kBAAmC;AAAA,IACvC;AAAA,IACA;AAAA,EACF;AAEA,QAAM,gBAAgB;AAAA,IACpB,YAAY,iBAAiB,CAAC;AAAA,IAC9B,cAAY,gBAAgB,QAAQ;AAAA,EACtC;AAEA,SACE;AAAA,IAAC;AAAA;AAAA,MACC;AAAA,MACA;AAAA,MACA,aAAa;AAAA,MACb;AAAA;AAAA,EACF;AAEJ;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=injectable-props.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -2,10 +2,7 @@ import { TestOrigins } from "../../../testing/fixtures";
|
|
|
2
2
|
import { ReactRuntime } from "../react-runtime";
|
|
3
3
|
class TestReactRuntime extends ReactRuntime {
|
|
4
4
|
env;
|
|
5
|
-
constructor({
|
|
6
|
-
env,
|
|
7
|
-
...args
|
|
8
|
-
}) {
|
|
5
|
+
constructor({ env, ...args }) {
|
|
9
6
|
super(args);
|
|
10
7
|
this.env = env ?? "client";
|
|
11
8
|
}
|
|
@@ -15,6 +12,7 @@ class TestReactRuntime extends ReactRuntime {
|
|
|
15
12
|
}
|
|
16
13
|
function createReactRuntime({
|
|
17
14
|
breakpoints,
|
|
15
|
+
requestKey,
|
|
18
16
|
env
|
|
19
17
|
} = {}) {
|
|
20
18
|
return new TestReactRuntime({
|
|
@@ -22,6 +20,7 @@ function createReactRuntime({
|
|
|
22
20
|
// through the patched version instead of an eagerly captured reference to the original
|
|
23
21
|
fetch: (...args) => globalThis.fetch(...args),
|
|
24
22
|
breakpoints,
|
|
23
|
+
requestKey,
|
|
25
24
|
env,
|
|
26
25
|
...TestOrigins
|
|
27
26
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/runtimes/react/testing/react-runtime.tsx"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../../../../../src/runtimes/react/testing/react-runtime.tsx"],"sourcesContent":["import { TestOrigins } from '../../../testing/fixtures'\nimport { ReactRuntime } from '../react-runtime'\n\ntype RuntimeEnv = 'client' | 'ssr' | 'rsc'\ntype RuntimeArgs = ConstructorParameters<typeof ReactRuntime>[0]\n\nclass TestReactRuntime extends ReactRuntime {\n readonly env: RuntimeEnv\n\n constructor({ env, ...args }: RuntimeArgs & { env?: RuntimeEnv }) {\n super(args)\n this.env = env ?? 'client'\n }\n\n protected isRSCEnv() {\n return this.env === 'rsc'\n }\n}\n\nexport function createReactRuntime({\n breakpoints,\n requestKey,\n env,\n}: {\n breakpoints?: RuntimeArgs['breakpoints']\n requestKey?: RuntimeArgs['requestKey']\n env?: RuntimeEnv\n} = {}) {\n return new TestReactRuntime({\n // Mock Service Worker patches global `fetch` for interception; make sure our test calls go\n // through the patched version instead of an eagerly captured reference to the original\n fetch: (...args) => globalThis.fetch(...args),\n breakpoints,\n requestKey,\n env,\n ...TestOrigins,\n })\n}\n"],"mappings":"AAAA,SAAS,mBAAmB;AAC5B,SAAS,oBAAoB;AAK7B,MAAM,yBAAyB,aAAa;AAAA,EACjC;AAAA,EAET,YAAY,EAAE,KAAK,GAAG,KAAK,GAAuC;AAChE,UAAM,IAAI;AACV,SAAK,MAAM,OAAO;AAAA,EACpB;AAAA,EAEU,WAAW;AACnB,WAAO,KAAK,QAAQ;AAAA,EACtB;AACF;AAEO,SAAS,mBAAmB;AAAA,EACjC;AAAA,EACA;AAAA,EACA;AACF,IAII,CAAC,GAAG;AACN,SAAO,IAAI,iBAAiB;AAAA;AAAA;AAAA,IAG1B,OAAO,IAAI,SAAS,WAAW,MAAM,GAAG,IAAI;AAAA,IAC5C;AAAA,IACA;AAAA,IACA;AAAA,IACA,GAAG;AAAA,EACL,CAAC;AACH;","names":[]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { renderToReadableStream } from "react-dom/server";
|
|
2
|
+
async function streamToString(stream) {
|
|
3
|
+
const reader = stream.getReader();
|
|
4
|
+
const decoder = new TextDecoder();
|
|
5
|
+
let result = "";
|
|
6
|
+
while (true) {
|
|
7
|
+
const { done, value } = await reader.read();
|
|
8
|
+
if (done)
|
|
9
|
+
break;
|
|
10
|
+
result += decoder.decode(value, { stream: true });
|
|
11
|
+
}
|
|
12
|
+
return result;
|
|
13
|
+
}
|
|
14
|
+
async function renderToString(element) {
|
|
15
|
+
return await streamToString(await renderToReadableStream(element));
|
|
16
|
+
}
|
|
17
|
+
export {
|
|
18
|
+
renderToString
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=render-to-string.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/runtimes/react/testing/render-to-string.ts"],"sourcesContent":["import { type ReactNode } from 'react'\nimport { renderToReadableStream } from 'react-dom/server'\n\nasync function streamToString(stream: ReadableStream) {\n const reader = stream.getReader()\n const decoder = new TextDecoder()\n\n let result = ''\n\n while (true) {\n const { done, value } = await reader.read()\n if (done) break\n result += decoder.decode(value, { stream: true })\n }\n\n return result\n}\n\nexport async function renderToString(element: ReactNode) {\n return await streamToString(await renderToReadableStream(element))\n}\n"],"mappings":"AACA,SAAS,8BAA8B;AAEvC,eAAe,eAAe,QAAwB;AACpD,QAAM,SAAS,OAAO,UAAU;AAChC,QAAM,UAAU,IAAI,YAAY;AAEhC,MAAI,SAAS;AAEb,SAAO,MAAM;AACX,UAAM,EAAE,MAAM,MAAM,IAAI,MAAM,OAAO,KAAK;AAC1C,QAAI;AAAM;AACV,cAAU,QAAQ,OAAO,OAAO,EAAE,QAAQ,KAAK,CAAC;AAAA,EAClD;AAEA,SAAO;AACT;AAEA,eAAsB,eAAe,SAAoB;AACvD,SAAO,MAAM,eAAe,MAAM,uBAAuB,OAAO,CAAC;AACnE;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/state/modules/components-meta.ts"],"sourcesContent":["import { type Action, type UnknownAction, isKnownAction } from '../actions'\nimport { ReadOnlyActionTypes } from '../actions/internal/read-only-action-types'\n\nexport const ComponentIcon = {\n Accordion: 'accordion',\n Audio: 'audio',\n Billing: 'billing',\n Bolt: 'bolt',\n Button: 'button',\n Card: 'card',\n Cards: 'cards',\n Carousel: 'carousel',\n Chats: 'chats',\n Code: 'code',\n Countdown: 'countdown',\n Cube: 'cube',\n Database: 'database',\n Divider: 'divider',\n Form: 'form',\n Gallery: 'gallery',\n Grid: 'grid',\n Help: 'help',\n Image: 'image',\n Layout: 'layout',\n Lock: 'lock',\n Marker: 'marker',\n Navigation: 'navigation',\n Palette: 'palette',\n SocialLinks: 'social-links',\n Star: 'star',\n Table: 'table',\n Tabs: 'tabs',\n Text: 'text',\n Users: 'users',\n Video: 'video',\n} as const\n\nexport type ComponentIcon = (typeof ComponentIcon)[keyof typeof ComponentIcon]\n\nexport type ComponentMeta = {\n label: string\n icon: ComponentIcon\n hidden: boolean\n description?: string\n builtinSuspense?: boolean\n unstable_migration?: {\n replacementType: string\n }\n server?: boolean\n}\n\nexport type State = Map<string, ComponentMeta>\n\nexport function getInitialState({\n componentsMeta = new Map(),\n}: { componentsMeta?: Map<string, ComponentMeta> } = {}): State {\n return componentsMeta\n}\n\nexport function getComponentsMeta(state: State): Map<string, ComponentMeta> {\n return state\n}\n\nexport function getComponentMeta(state: State, type: string): ComponentMeta | null {\n return getComponentsMeta(state).get(type) ?? null\n}\n\nexport function reducer(state: State = getInitialState(), action: Action | UnknownAction): State {\n if (!isKnownAction(action)) return state\n\n switch (action.type) {\n case ReadOnlyActionTypes.REGISTER_COMPONENT:\n return new Map(state).set(action.payload.type, action.payload.meta)\n\n case ReadOnlyActionTypes.UNREGISTER_COMPONENT: {\n const nextState = new Map(state)\n\n const deleted = nextState.delete(action.payload.type)\n\n return deleted ? nextState : state\n }\n\n default:\n return state\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../../src/state/modules/components-meta.ts"],"sourcesContent":["import { InjectableProps } from '../../runtimes/react/server/injectable-props'\nimport { type Action, type UnknownAction, isKnownAction } from '../actions'\nimport { ReadOnlyActionTypes } from '../actions/internal/read-only-action-types'\n\nexport const ComponentIcon = {\n Accordion: 'accordion',\n Audio: 'audio',\n Billing: 'billing',\n Bolt: 'bolt',\n Button: 'button',\n Card: 'card',\n Cards: 'cards',\n Carousel: 'carousel',\n Chats: 'chats',\n Code: 'code',\n Countdown: 'countdown',\n Cube: 'cube',\n Database: 'database',\n Divider: 'divider',\n Form: 'form',\n Gallery: 'gallery',\n Grid: 'grid',\n Help: 'help',\n Image: 'image',\n Layout: 'layout',\n Lock: 'lock',\n Marker: 'marker',\n Navigation: 'navigation',\n Palette: 'palette',\n SocialLinks: 'social-links',\n Star: 'star',\n Table: 'table',\n Tabs: 'tabs',\n Text: 'text',\n Users: 'users',\n Video: 'video',\n} as const\n\nexport type ComponentIcon = (typeof ComponentIcon)[keyof typeof ComponentIcon]\n\nexport type ComponentMeta = {\n label: string\n icon: ComponentIcon\n hidden: boolean\n description?: string\n builtinSuspense?: boolean\n unstable_migration?: {\n replacementType: string\n }\n server?: boolean\n injectedProps?: Record<string, keyof InjectableProps>\n}\n\nexport type State = Map<string, ComponentMeta>\n\nexport function getInitialState({\n componentsMeta = new Map(),\n}: { componentsMeta?: Map<string, ComponentMeta> } = {}): State {\n return componentsMeta\n}\n\nexport function getComponentsMeta(state: State): Map<string, ComponentMeta> {\n return state\n}\n\nexport function getComponentMeta(state: State, type: string): ComponentMeta | null {\n return getComponentsMeta(state).get(type) ?? null\n}\n\nexport function reducer(state: State = getInitialState(), action: Action | UnknownAction): State {\n if (!isKnownAction(action)) return state\n\n switch (action.type) {\n case ReadOnlyActionTypes.REGISTER_COMPONENT:\n return new Map(state).set(action.payload.type, action.payload.meta)\n\n case ReadOnlyActionTypes.UNREGISTER_COMPONENT: {\n const nextState = new Map(state)\n\n const deleted = nextState.delete(action.payload.type)\n\n return deleted ? nextState : state\n }\n\n default:\n return state\n }\n}\n"],"mappings":"AACA,SAA0C,qBAAqB;AAC/D,SAAS,2BAA2B;AAE7B,MAAM,gBAAgB;AAAA,EAC3B,WAAW;AAAA,EACX,OAAO;AAAA,EACP,SAAS;AAAA,EACT,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,MAAM;AAAA,EACN,OAAO;AAAA,EACP,UAAU;AAAA,EACV,OAAO;AAAA,EACP,MAAM;AAAA,EACN,WAAW;AAAA,EACX,MAAM;AAAA,EACN,UAAU;AAAA,EACV,SAAS;AAAA,EACT,MAAM;AAAA,EACN,SAAS;AAAA,EACT,MAAM;AAAA,EACN,MAAM;AAAA,EACN,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,YAAY;AAAA,EACZ,SAAS;AAAA,EACT,aAAa;AAAA,EACb,MAAM;AAAA,EACN,OAAO;AAAA,EACP,MAAM;AAAA,EACN,MAAM;AAAA,EACN,OAAO;AAAA,EACP,OAAO;AACT;AAmBO,SAAS,gBAAgB;AAAA,EAC9B,iBAAiB,oBAAI,IAAI;AAC3B,IAAqD,CAAC,GAAU;AAC9D,SAAO;AACT;AAEO,SAAS,kBAAkB,OAA0C;AAC1E,SAAO;AACT;AAEO,SAAS,iBAAiB,OAAc,MAAoC;AACjF,SAAO,kBAAkB,KAAK,EAAE,IAAI,IAAI,KAAK;AAC/C;AAEO,SAAS,QAAQ,QAAe,gBAAgB,GAAG,QAAuC;AAC/F,MAAI,CAAC,cAAc,MAAM;AAAG,WAAO;AAEnC,UAAQ,OAAO,MAAM;AAAA,IACnB,KAAK,oBAAoB;AACvB,aAAO,IAAI,IAAI,KAAK,EAAE,IAAI,OAAO,QAAQ,MAAM,OAAO,QAAQ,IAAI;AAAA,IAEpE,KAAK,oBAAoB,sBAAsB;AAC7C,YAAM,YAAY,IAAI,IAAI,KAAK;AAE/B,YAAM,UAAU,UAAU,OAAO,OAAO,QAAQ,IAAI;AAEpD,aAAO,UAAU,YAAY;AAAA,IAC/B;AAAA,IAEA;AACE,aAAO;AAAA,EACX;AACF;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"page-control-prop-rendering.d.ts","sourceRoot":"","sources":["../../../../../../src/next/components/tests/controls/page-control-prop-rendering.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"page-control-prop-rendering.d.ts","sourceRoot":"","sources":["../../../../../../src/next/components/tests/controls/page-control-prop-rendering.tsx"],"names":[],"mappings":"AAGA,OAAO,2BAA2B,CAAA;AAGlC,OAAO,EAAa,KAAK,SAAS,EAAE,KAAK,QAAQ,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AAEjG,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,sCAAsC,CAAA;AACrE,OAAO,EAAE,WAAW,EAAE,MAAM,mCAAmC,CAAA;AAE/D,OAAO,EAAE,YAAY,EAAE,MAAM,0CAA0C,CAAA;AAqEvE,wBAAsB,4BAA4B,CAAC,CAAC,SAAS,iBAAiB,EAC5E,iBAAiB,EAAE,CAAC,EACpB,EACE,MAAM,EACN,KAAK,EACL,MAAM,EACN,SAAS,EACT,eAAe,EACf,kBAAkB,EAClB,MAAM,EACN,YAAiB,EACjB,WAAmB,EACnB,UAAiB,GAClB,EAAE;IACD,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAA;IAC7C,KAAK,EAAE,SAAS,CAAC,CAAC,CAAC,GAAG,SAAS,CAAA;IAC/B,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IACtB,SAAS,CAAC,EAAE,OAAO,CAAC,SAAS,CAAC,CAAA;IAC9B,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,kBAAkB,CAAC,EAAE,CAAC,OAAO,EAAE,YAAY,KAAK,IAAI,CAAA;IACpD,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,WAAW,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IAChD,YAAY,CAAC,EAAE,WAAW,EAAE,CAAA;IAC5B,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,UAAU,CAAC,EAAE,OAAO,CAAA;CACrB,iBAwGF"}
|
|
@@ -1,12 +1,24 @@
|
|
|
1
|
+
import { type Component, type PropsWithoutRef, type ReactNode, type RefAttributes } from 'react';
|
|
1
2
|
import { ControlDefinition as UnifiedControlDefinition } from '@makeswift/controls';
|
|
2
3
|
import { type LegacyDescriptor, type DescriptorValueType } from '../../prop-controllers/descriptors';
|
|
3
4
|
import { ComponentIcon } from '../../state/modules/components-meta';
|
|
4
|
-
import type
|
|
5
|
+
import { type InjectableProps } from './server/injectable-props';
|
|
5
6
|
import { RuntimeCore } from './runtime-core';
|
|
7
|
+
type InjectedPropsConfig = Record<string, keyof InjectableProps>;
|
|
8
|
+
type ServerComponentConfig<I extends InjectedPropsConfig> = boolean | {
|
|
9
|
+
unstable_injectedProps: I;
|
|
10
|
+
};
|
|
11
|
+
type InjectedProps<I extends InjectedPropsConfig> = {
|
|
12
|
+
[K in keyof I]: InjectableProps[I[K]];
|
|
13
|
+
};
|
|
14
|
+
type ResolvedProps<P extends Record<string, LegacyDescriptor | UnifiedControlDefinition>> = {
|
|
15
|
+
[K in keyof P]: DescriptorValueType<P[K]>;
|
|
16
|
+
};
|
|
17
|
+
type RegisteredComponentType<P extends Record<string, LegacyDescriptor | UnifiedControlDefinition>, I extends InjectedPropsConfig, T = any> = {
|
|
18
|
+
new (props: PropsWithoutRef<ResolvedProps<P>> & InjectedProps<I> & RefAttributes<T>, context?: any): Component<ResolvedProps<P> & InjectedProps<I>>;
|
|
19
|
+
} | ((props: PropsWithoutRef<ResolvedProps<P>> & InjectedProps<I> & RefAttributes<T>, context?: any) => ReactNode);
|
|
6
20
|
export declare class ReactRuntimeCore extends RuntimeCore {
|
|
7
|
-
registerComponent<ControlDef extends UnifiedControlDefinition, P extends Record<string, LegacyDescriptor | ControlDef>, C extends
|
|
8
|
-
[K in keyof P]: DescriptorValueType<P[K]>;
|
|
9
|
-
}>>(component: C, { type, label, icon, hidden, description, builtinSuspense, unstable_migration, server, props, }: {
|
|
21
|
+
registerComponent<ControlDef extends UnifiedControlDefinition, P extends Record<string, LegacyDescriptor | ControlDef>, const I extends InjectedPropsConfig = {}, C extends RegisteredComponentType<P, I> = RegisteredComponentType<P, I>>(component: C, { type, label, icon, hidden, description, builtinSuspense, unstable_migration, server, props, }: {
|
|
10
22
|
type: string;
|
|
11
23
|
label: string;
|
|
12
24
|
icon?: ComponentIcon;
|
|
@@ -26,9 +38,10 @@ export declare class ReactRuntimeCore extends RuntimeCore {
|
|
|
26
38
|
unstable_migration?: {
|
|
27
39
|
replacementType: string;
|
|
28
40
|
};
|
|
29
|
-
server?:
|
|
41
|
+
server?: ServerComponentConfig<I>;
|
|
30
42
|
props?: P;
|
|
31
43
|
}): () => void;
|
|
32
44
|
protected isRSCEnv(): boolean;
|
|
33
45
|
}
|
|
46
|
+
export {};
|
|
34
47
|
//# sourceMappingURL=react-runtime-core.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react-runtime-core.d.ts","sourceRoot":"","sources":["../../../../src/runtimes/react/react-runtime-core.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,IAAI,wBAAwB,EAAE,MAAM,qBAAqB,CAAA;AAEnF,OAAO,EAAE,KAAK,gBAAgB,EAAE,KAAK,mBAAmB,EAAE,MAAM,oCAAoC,CAAA;AASpG,OAAO,EAAE,aAAa,EAAE,MAAM,qCAAqC,CAAA;
|
|
1
|
+
{"version":3,"file":"react-runtime-core.d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GnB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"element.test.d.ts","sourceRoot":"","sources":["../../../../../../../src/runtimes/react/server/components/__tests__/element.test.tsx"],"names":[],"mappings":""}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { type ReactNode } from 'react';
|
|
2
2
|
import { type ElementData } from '../../../../state/read-only-state';
|
|
3
3
|
import { type ServerRenderContext } from '../render-context';
|
|
4
|
-
export declare function ServerElementData({ documentKey, context, elementData, }: {
|
|
4
|
+
export declare function ServerElementData({ documentKey, context, elementData, injectedProps, }: {
|
|
5
5
|
documentKey: string;
|
|
6
6
|
context: ServerRenderContext;
|
|
7
7
|
elementData: ElementData;
|
|
8
|
+
injectedProps: Record<string, unknown>;
|
|
8
9
|
}): Promise<ReactNode>;
|
|
9
10
|
//# sourceMappingURL=element-data.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"element-data.d.ts","sourceRoot":"","sources":["../../../../../../src/runtimes/react/server/components/element-data.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAA;AAItC,OAAO,EAEL,KAAK,WAAW,EAIjB,MAAM,mCAAmC,CAAA;AAU1C,OAAO,EAAE,KAAK,mBAAmB,EAAY,MAAM,mBAAmB,CAAA;AAGtE,wBAAsB,iBAAiB,CAAC,EACtC,WAAW,EACX,OAAO,EACP,WAAW,
|
|
1
|
+
{"version":3,"file":"element-data.d.ts","sourceRoot":"","sources":["../../../../../../src/runtimes/react/server/components/element-data.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAA;AAItC,OAAO,EAEL,KAAK,WAAW,EAIjB,MAAM,mCAAmC,CAAA;AAU1C,OAAO,EAAE,KAAK,mBAAmB,EAAY,MAAM,mBAAmB,CAAA;AAGtE,wBAAsB,iBAAiB,CAAC,EACtC,WAAW,EACX,OAAO,EACP,WAAW,EACX,aAAa,GACd,EAAE;IACD,WAAW,EAAE,MAAM,CAAA;IACnB,OAAO,EAAE,mBAAmB,CAAA;IAC5B,WAAW,EAAE,WAAW,CAAA;IACxB,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CACvC,GAAG,OAAO,CAAC,SAAS,CAAC,CA0CrB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"element.d.ts","sourceRoot":"","sources":["../../../../../../src/runtimes/react/server/components/element.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"element.d.ts","sourceRoot":"","sources":["../../../../../../src/runtimes/react/server/components/element.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAIjC,OAAO,EAGL,KAAK,OAAO,IAAI,gBAAgB,EACjC,MAAM,mCAAmC,CAAA;AAM1C,OAAO,EAAE,KAAK,mBAAmB,EAAY,MAAM,mBAAmB,CAAA;AAKtE,wBAAgB,aAAa,CAAC,EAC5B,OAAO,EACP,OAAO,EACP,WAAW,GACZ,EAAE;IACD,OAAO,EAAE,mBAAmB,CAAA;IAC5B,OAAO,EAAE,gBAAgB,CAAA;IACzB,WAAW,EAAE,MAAM,CAAA;CACpB,GAAG,SAAS,CAyCZ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"injectable-props.d.ts","sourceRoot":"","sources":["../../../../../src/runtimes/react/server/injectable-props.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,eAAe,GAAG;IAC5B,WAAW,EAAE,MAAM,CAAA;IACnB,UAAU,EAAE,MAAM,CAAA;CACnB,CAAA"}
|
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import { type BreakpointsInput } from '../../../state/modules/breakpoints';
|
|
2
1
|
import { ReactRuntime } from '../react-runtime';
|
|
3
2
|
type RuntimeEnv = 'client' | 'ssr' | 'rsc';
|
|
3
|
+
type RuntimeArgs = ConstructorParameters<typeof ReactRuntime>[0];
|
|
4
4
|
declare class TestReactRuntime extends ReactRuntime {
|
|
5
5
|
readonly env: RuntimeEnv;
|
|
6
|
-
constructor({ env, ...args }:
|
|
6
|
+
constructor({ env, ...args }: RuntimeArgs & {
|
|
7
7
|
env?: RuntimeEnv;
|
|
8
8
|
});
|
|
9
9
|
protected isRSCEnv(): boolean;
|
|
10
10
|
}
|
|
11
|
-
export declare function createReactRuntime({ breakpoints, env, }?: {
|
|
12
|
-
breakpoints?:
|
|
11
|
+
export declare function createReactRuntime({ breakpoints, requestKey, env, }?: {
|
|
12
|
+
breakpoints?: RuntimeArgs['breakpoints'];
|
|
13
|
+
requestKey?: RuntimeArgs['requestKey'];
|
|
13
14
|
env?: RuntimeEnv;
|
|
14
15
|
}): TestReactRuntime;
|
|
15
16
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react-runtime.d.ts","sourceRoot":"","sources":["../../../../../src/runtimes/react/testing/react-runtime.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"react-runtime.d.ts","sourceRoot":"","sources":["../../../../../src/runtimes/react/testing/react-runtime.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAE/C,KAAK,UAAU,GAAG,QAAQ,GAAG,KAAK,GAAG,KAAK,CAAA;AAC1C,KAAK,WAAW,GAAG,qBAAqB,CAAC,OAAO,YAAY,CAAC,CAAC,CAAC,CAAC,CAAA;AAEhE,cAAM,gBAAiB,SAAQ,YAAY;IACzC,QAAQ,CAAC,GAAG,EAAE,UAAU,CAAA;gBAEZ,EAAE,GAAG,EAAE,GAAG,IAAI,EAAE,EAAE,WAAW,GAAG;QAAE,GAAG,CAAC,EAAE,UAAU,CAAA;KAAE;IAKhE,SAAS,CAAC,QAAQ;CAGnB;AAED,wBAAgB,kBAAkB,CAAC,EACjC,WAAW,EACX,UAAU,EACV,GAAG,GACJ,GAAE;IACD,WAAW,CAAC,EAAE,WAAW,CAAC,aAAa,CAAC,CAAA;IACxC,UAAU,CAAC,EAAE,WAAW,CAAC,YAAY,CAAC,CAAA;IACtC,GAAG,CAAC,EAAE,UAAU,CAAA;CACZ,oBAUL"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render-to-string.d.ts","sourceRoot":"","sources":["../../../../../src/runtimes/react/testing/render-to-string.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAA;AAkBtC,wBAAsB,cAAc,CAAC,OAAO,EAAE,SAAS,mBAEtD"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { InjectableProps } from '../../runtimes/react/server/injectable-props';
|
|
1
2
|
import { type Action, type UnknownAction } from '../actions';
|
|
2
3
|
export declare const ComponentIcon: {
|
|
3
4
|
readonly Accordion: "accordion";
|
|
@@ -43,6 +44,7 @@ export type ComponentMeta = {
|
|
|
43
44
|
replacementType: string;
|
|
44
45
|
};
|
|
45
46
|
server?: boolean;
|
|
47
|
+
injectedProps?: Record<string, keyof InjectableProps>;
|
|
46
48
|
};
|
|
47
49
|
export type State = Map<string, ComponentMeta>;
|
|
48
50
|
export declare function getInitialState({ componentsMeta, }?: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"components-meta.d.ts","sourceRoot":"","sources":["../../../../src/state/modules/components-meta.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,MAAM,EAAE,KAAK,aAAa,EAAiB,MAAM,YAAY,CAAA;AAG3E,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgChB,CAAA;AAEV,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,aAAa,CAAC,CAAC,MAAM,OAAO,aAAa,CAAC,CAAA;AAE9E,MAAM,MAAM,aAAa,GAAG;IAC1B,KAAK,EAAE,MAAM,CAAA;IACb,IAA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KAAK,EAAE,KAAK,GAAG,GAAG,CAAC,MAAM,EAAE,aAAa,CAAC,CAE1E;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,GAAG,aAAa,GAAG,IAAI,CAEjF;AAED,wBAAgB,OAAO,CAAC,KAAK,EAAE,KAAK,YAAoB,EAAE,MAAM,EAAE,MAAM,GAAG,aAAa,GAAG,KAAK,CAkB/F"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@makeswift/runtime",
|
|
3
|
-
"version": "0.28.10-canary.
|
|
3
|
+
"version": "0.28.10-canary.6",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"url": "makeswift/makeswift",
|
|
@@ -244,8 +244,8 @@
|
|
|
244
244
|
"use-sync-external-store": "^1.5.0",
|
|
245
245
|
"uuid": "^9.0.0",
|
|
246
246
|
"zod": "^3.21.4",
|
|
247
|
-
"@makeswift/controls": "0.1.22-canary.0",
|
|
248
247
|
"@makeswift/next-plugin": "0.6.1",
|
|
248
|
+
"@makeswift/controls": "0.1.22-canary.0",
|
|
249
249
|
"@makeswift/prop-controllers": "0.4.16-canary.0"
|
|
250
250
|
},
|
|
251
251
|
"devDependencies": {
|