@makeswift/runtime 0.23.1-canary.0 → 0.23.2

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.
Files changed (104) hide show
  1. package/dist/cjs/jest-setup.js +3 -0
  2. package/dist/cjs/jest-setup.js.map +1 -1
  3. package/dist/cjs/next/api-handler/handlers/manifest.js +1 -1
  4. package/dist/cjs/next/api-handler/handlers/proxy-draft-mode.js +12 -2
  5. package/dist/cjs/next/api-handler/handlers/proxy-draft-mode.js.map +1 -1
  6. package/dist/cjs/next/components/tests/controls/color-control/fixtures.js +51 -0
  7. package/dist/cjs/next/components/tests/controls/color-control/fixtures.js.map +1 -0
  8. package/dist/cjs/next/components/tests/controls/page-control-prop-rendering.js +91 -35
  9. package/dist/cjs/next/components/tests/controls/page-control-prop-rendering.js.map +1 -1
  10. package/dist/cjs/next/components/tests/controls/rich-text-v2-control/fixtures.js +91 -0
  11. package/dist/cjs/next/components/tests/controls/rich-text-v2-control/fixtures.js.map +1 -0
  12. package/dist/cjs/next/components/tests/controls/style-control/fixtures.js +60 -0
  13. package/dist/cjs/next/components/tests/controls/style-control/fixtures.js.map +1 -0
  14. package/dist/cjs/next/components/tests/prop-controllers/page-prop-controller.js +20 -11
  15. package/dist/cjs/next/components/tests/prop-controllers/page-prop-controller.js.map +1 -1
  16. package/dist/cjs/next/root-style-registry.js +20 -19
  17. package/dist/cjs/next/root-style-registry.js.map +1 -1
  18. package/dist/cjs/runtimes/react/hooks/use-resolved-props.js +3 -2
  19. package/dist/cjs/runtimes/react/hooks/use-resolved-props.js.map +1 -1
  20. package/dist/cjs/{utils/tests/breakpoint-test-util.js → runtimes/react/testing/breakpoints.js} +4 -4
  21. package/dist/cjs/runtimes/react/testing/breakpoints.js.map +1 -0
  22. package/dist/cjs/{utils/tests/element-data-test-test.js → runtimes/react/testing/element-data.js} +33 -7
  23. package/dist/cjs/runtimes/react/testing/element-data.js.map +1 -0
  24. package/dist/cjs/runtimes/react/testing/index.js +27 -0
  25. package/dist/cjs/runtimes/react/testing/index.js.map +1 -0
  26. package/dist/cjs/runtimes/react/testing/react-provider.js +38 -0
  27. package/dist/cjs/runtimes/react/testing/react-provider.js.map +1 -0
  28. package/dist/cjs/runtimes/react/use-style.js +2 -2
  29. package/dist/cjs/runtimes/react/use-style.js.map +1 -1
  30. package/dist/esm/jest-setup.js +4 -1
  31. package/dist/esm/jest-setup.js.map +1 -1
  32. package/dist/esm/next/api-handler/handlers/manifest.js +1 -1
  33. package/dist/esm/next/api-handler/handlers/proxy-draft-mode.js +12 -2
  34. package/dist/esm/next/api-handler/handlers/proxy-draft-mode.js.map +1 -1
  35. package/dist/esm/next/components/tests/controls/color-control/fixtures.js +24 -0
  36. package/dist/esm/next/components/tests/controls/color-control/fixtures.js.map +1 -0
  37. package/dist/esm/next/components/tests/controls/page-control-prop-rendering.js +82 -39
  38. package/dist/esm/next/components/tests/controls/page-control-prop-rendering.js.map +1 -1
  39. package/dist/esm/next/components/tests/controls/rich-text-v2-control/fixtures.js +56 -0
  40. package/dist/esm/next/components/tests/controls/rich-text-v2-control/fixtures.js.map +1 -0
  41. package/dist/esm/next/components/tests/controls/style-control/fixtures.js +35 -0
  42. package/dist/esm/next/components/tests/controls/style-control/fixtures.js.map +1 -0
  43. package/dist/esm/next/components/tests/prop-controllers/page-prop-controller.js +7 -11
  44. package/dist/esm/next/components/tests/prop-controllers/page-prop-controller.js.map +1 -1
  45. package/dist/esm/next/root-style-registry.js +20 -19
  46. package/dist/esm/next/root-style-registry.js.map +1 -1
  47. package/dist/esm/runtimes/react/hooks/use-resolved-props.js +3 -2
  48. package/dist/esm/runtimes/react/hooks/use-resolved-props.js.map +1 -1
  49. package/dist/esm/{utils/tests/breakpoint-test-util.js → runtimes/react/testing/breakpoints.js} +1 -1
  50. package/dist/esm/runtimes/react/testing/breakpoints.js.map +1 -0
  51. package/dist/esm/{utils/tests/element-data-test-test.js → runtimes/react/testing/element-data.js} +29 -4
  52. package/dist/esm/runtimes/react/testing/element-data.js.map +1 -0
  53. package/dist/esm/runtimes/react/testing/index.js +4 -0
  54. package/dist/esm/runtimes/react/testing/index.js.map +1 -0
  55. package/dist/esm/runtimes/react/testing/react-provider.js +14 -0
  56. package/dist/esm/runtimes/react/testing/react-provider.js.map +1 -0
  57. package/dist/esm/runtimes/react/use-style.js +2 -2
  58. package/dist/esm/runtimes/react/use-style.js.map +1 -1
  59. package/dist/types/next/api-handler/handlers/proxy-draft-mode.test.d.ts +2 -0
  60. package/dist/types/next/api-handler/handlers/proxy-draft-mode.test.d.ts.map +1 -0
  61. package/dist/types/next/components/tests/controls/color-control/client.test.d.ts +3 -0
  62. package/dist/types/next/components/tests/controls/color-control/client.test.d.ts.map +1 -0
  63. package/dist/types/next/components/tests/controls/color-control/fixtures.d.ts +11 -0
  64. package/dist/types/next/components/tests/controls/color-control/fixtures.d.ts.map +1 -0
  65. package/dist/types/next/components/tests/controls/color-control/server.test.d.ts +2 -0
  66. package/dist/types/next/components/tests/controls/color-control/server.test.d.ts.map +1 -0
  67. package/dist/types/next/components/tests/controls/page-control-prop-rendering.d.ts +2 -3
  68. package/dist/types/next/components/tests/controls/page-control-prop-rendering.d.ts.map +1 -1
  69. package/dist/types/next/components/tests/controls/rich-text-v2-control/client.test.d.ts +2 -0
  70. package/dist/types/next/components/tests/controls/rich-text-v2-control/client.test.d.ts.map +1 -0
  71. package/dist/types/next/components/tests/controls/rich-text-v2-control/fixtures.d.ts +42 -0
  72. package/dist/types/next/components/tests/controls/rich-text-v2-control/fixtures.d.ts.map +1 -0
  73. package/dist/types/next/components/tests/controls/rich-text-v2-control/server.test.d.ts +2 -0
  74. package/dist/types/next/components/tests/controls/rich-text-v2-control/server.test.d.ts.map +1 -0
  75. package/dist/types/next/components/tests/controls/style-control/client.test.d.ts +2 -0
  76. package/dist/types/next/components/tests/controls/style-control/client.test.d.ts.map +1 -0
  77. package/dist/types/next/components/tests/controls/style-control/fixtures.d.ts +6 -0
  78. package/dist/types/next/components/tests/controls/style-control/fixtures.d.ts.map +1 -0
  79. package/dist/types/next/components/tests/controls/style-control/server.test.d.ts +2 -0
  80. package/dist/types/next/components/tests/controls/style-control/server.test.d.ts.map +1 -0
  81. package/dist/types/next/components/tests/prop-controllers/page-prop-controller.d.ts.map +1 -1
  82. package/dist/types/next/root-style-registry.d.ts.map +1 -1
  83. package/dist/types/runtimes/react/hooks/use-resolved-props.d.ts.map +1 -1
  84. package/dist/types/{utils/tests/breakpoint-test-util.d.ts → runtimes/react/testing/breakpoints.d.ts} +1 -1
  85. package/dist/types/runtimes/react/testing/breakpoints.d.ts.map +1 -0
  86. package/dist/types/{utils/tests/element-data-test-test.d.ts → runtimes/react/testing/element-data.d.ts} +7 -3
  87. package/dist/types/runtimes/react/testing/element-data.d.ts.map +1 -0
  88. package/dist/types/runtimes/react/testing/index.d.ts +4 -0
  89. package/dist/types/runtimes/react/testing/index.d.ts.map +1 -0
  90. package/dist/types/runtimes/react/testing/react-provider.d.ts +8 -0
  91. package/dist/types/runtimes/react/testing/react-provider.d.ts.map +1 -0
  92. package/package.json +5 -3
  93. package/dist/cjs/utils/tests/breakpoint-test-util.js.map +0 -1
  94. package/dist/cjs/utils/tests/element-data-test-test.js.map +0 -1
  95. package/dist/esm/utils/tests/breakpoint-test-util.js.map +0 -1
  96. package/dist/esm/utils/tests/element-data-test-test.js.map +0 -1
  97. package/dist/types/next/components/tests/controls/color-control.test.d.ts +0 -3
  98. package/dist/types/next/components/tests/controls/color-control.test.d.ts.map +0 -1
  99. package/dist/types/next/components/tests/controls/rich-text-v2-control.test.d.ts +0 -2
  100. package/dist/types/next/components/tests/controls/rich-text-v2-control.test.d.ts.map +0 -1
  101. package/dist/types/next/components/tests/controls/style-control.test.d.ts +0 -2
  102. package/dist/types/next/components/tests/controls/style-control.test.d.ts.map +0 -1
  103. package/dist/types/utils/tests/breakpoint-test-util.d.ts.map +0 -1
  104. package/dist/types/utils/tests/element-data-test-test.d.ts.map +0 -1
@@ -1,20 +1,50 @@
1
1
  import { jsx, jsxs } from "react/jsx-runtime";
2
- import { forwardRef, useRef, isValidElement } from "react";
2
+ import { Fragment, forwardRef, useRef, isValidElement } from "react";
3
+ import { renderToReadableStream } from "react-dom/server";
4
+ import { JSDOM } from "jsdom";
3
5
  import { act } from "react-dom/test-utils";
4
6
  import { render, screen } from "@testing-library/react";
5
7
  import "@testing-library/jest-dom";
6
- import { Page } from "../../page";
7
- import { ReactRuntimeProvider } from "../../../../runtimes/react";
8
+ import { ServerInsertedHTMLContext } from "next/navigation";
8
9
  import { ReactRuntime } from "../../../../react";
9
- import {
10
- createMakeswiftPageSnapshot,
11
- createRootComponent
12
- } from "../../../../utils/tests/element-data-test-test";
10
+ import { MakeswiftComponent } from "../../MakeswiftComponent";
11
+ import { Page } from "../../page";
12
+ import { isServer } from "../../../../utils/is-server";
13
+ import * as Testing from "../../../../runtimes/react/testing";
13
14
  const ROOT_ID = "00000000-0000-0000-0000-000000000000";
14
15
  const ELEMENT_ID = "11111111-1111-1111-1111-111111111111";
15
16
  const renderProp = (prop) => prop === void 0 ? "undefined" : isValidElement(prop) ? prop : JSON.stringify(prop);
16
- const propSnapshot = (prop) => prop.childElementCount ? prop.childNodes : parseStringifiedProp(prop.textContent ?? "");
17
+ const propSnapshot = (prop) => prop?.childElementCount ? prop.childNodes : parseStringifiedProp(prop?.textContent ?? "");
17
18
  const parseStringifiedProp = (prop) => prop === "undefined" ? void 0 : JSON.parse(prop);
19
+ async function streamToString(stream) {
20
+ const reader = stream.getReader();
21
+ const decoder = new TextDecoder();
22
+ let result = "";
23
+ while (true) {
24
+ const { done, value } = await reader.read();
25
+ if (done)
26
+ break;
27
+ result += decoder.decode(value, { stream: true });
28
+ }
29
+ return result;
30
+ }
31
+ async function renderToString(element) {
32
+ return await streamToString(await renderToReadableStream(element));
33
+ }
34
+ async function serverSideRender(children) {
35
+ const serverInsertedCallbacks = [];
36
+ const elementTree = /* @__PURE__ */ jsx(ServerInsertedHTMLContext.Provider, { value: (handler) => serverInsertedCallbacks.push(handler), children });
37
+ const elementsHTML = await renderToString(elementTree);
38
+ const serverInsertedNodes = serverInsertedCallbacks.map((callback, index) => /* @__PURE__ */ jsx(Fragment, { children: callback() }, "__next_server_inserted__" + index));
39
+ const headHTML = await renderToString(serverInsertedNodes);
40
+ const dom = new JSDOM(
41
+ `<!DOCTYPE html><head>${headHTML}</head><body><div id="root">${elementsHTML}</div></body></div>`,
42
+ {
43
+ runScripts: "dangerously"
44
+ }
45
+ );
46
+ return dom.window.document;
47
+ }
18
48
  async function testPageControlPropRendering(controlDefinition, {
19
49
  toData,
20
50
  value,
@@ -26,23 +56,19 @@ async function testPageControlPropRendering(controlDefinition, {
26
56
  rootElements = []
27
57
  }) {
28
58
  const controlData = value !== void 0 ? toData ? toData(value) : controlDefinition.toData(value) : void 0;
29
- const TestComponentType = "TestComponent";
59
+ const testComponentMeta = {
60
+ type: "TestComponent",
61
+ label: "Test Component"
62
+ };
30
63
  const testId = "test-id";
31
64
  const renderCountTestId = "render-count-test-id";
32
- const elementData = createRootComponent(
33
- [
34
- {
35
- key: ELEMENT_ID,
36
- type: TestComponentType,
37
- props: {
38
- propKey: controlData
39
- }
40
- },
41
- ...rootElements
42
- ],
43
- ROOT_ID
44
- );
45
- const snapshot = createMakeswiftPageSnapshot(elementData, { locale, cacheData });
65
+ const elementData = {
66
+ key: ELEMENT_ID,
67
+ type: testComponentMeta.type,
68
+ props: {
69
+ propKey: controlData
70
+ }
71
+ };
46
72
  const runtime = new ReactRuntime();
47
73
  registerComponents?.(runtime);
48
74
  runtime.registerComponent(
@@ -55,27 +81,44 @@ async function testPageControlPropRendering(controlDefinition, {
55
81
  ] });
56
82
  }),
57
83
  {
58
- type: TestComponentType,
59
- label: "TestComponent",
84
+ ...testComponentMeta,
60
85
  props: {
61
86
  propKey: controlDefinition
62
87
  }
63
88
  }
64
89
  );
65
- await act(
66
- async () => render(
67
- /* @__PURE__ */ jsx(ReactRuntimeProvider, { runtime, previewMode: false, children: /* @__PURE__ */ jsx(Page, { snapshot }) })
68
- )
69
- );
70
- if (action) {
71
- await act(async () => {
72
- await action(screen.getByTestId(testId));
73
- });
74
- }
75
- expect(snapshot).toMatchSnapshot("snapshot");
76
- expect(propSnapshot(screen.getByTestId(testId))).toMatchSnapshot("resolvedValue");
77
- if (expectedRenders != null) {
78
- expect(Number(screen.getByTestId(renderCountTestId).textContent)).toBe(expectedRenders);
90
+ const testElementTree = (component) => /* @__PURE__ */ jsx(Testing.ReactProvider, { runtime, children: component });
91
+ if (!isServer()) {
92
+ const rootElementData = Testing.createRootComponent(
93
+ [elementData, ...rootElements],
94
+ ROOT_ID
95
+ );
96
+ const snapshot = Testing.createMakeswiftPageSnapshot(rootElementData, { locale, cacheData });
97
+ await act(async () => render(testElementTree(/* @__PURE__ */ jsx(Page, { snapshot }))));
98
+ if (action) {
99
+ await act(async () => {
100
+ await action(screen.getByTestId(testId));
101
+ });
102
+ }
103
+ expect(snapshot).toMatchSnapshot("snapshot");
104
+ expect(propSnapshot(screen.getByTestId(testId))).toMatchSnapshot("resolvedValue");
105
+ if (expectedRenders != null) {
106
+ expect(Number(screen.getByTestId(renderCountTestId).textContent)).toBe(expectedRenders);
107
+ }
108
+ } else {
109
+ console.assert(action == null);
110
+ console.assert(rootElements.length === 0);
111
+ const snapshot = Testing.createMakeswiftComponentSnapshot(elementData, { locale, cacheData });
112
+ const elementTree = testElementTree(
113
+ /* @__PURE__ */ jsx(MakeswiftComponent, { snapshot, ...testComponentMeta })
114
+ );
115
+ const document = await serverSideRender(elementTree);
116
+ const getByTestId = (id) => document.querySelector(`[data-testid="${id}"]`);
117
+ expect(propSnapshot(getByTestId(testId))).toMatchSnapshot("resolvedValue");
118
+ expect([...document.querySelectorAll("style")].map((n) => n.textContent)).toMatchSnapshot(
119
+ "component styles"
120
+ );
121
+ expect(Number(getByTestId(renderCountTestId)?.textContent)).toBe(1);
79
122
  }
80
123
  }
81
124
  export {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../src/next/components/tests/controls/page-control-prop-rendering.tsx"],"sourcesContent":["/** @jest-environment jsdom */\n\nimport { forwardRef, useRef, isValidElement } from 'react'\nimport { act } from 'react-dom/test-utils'\nimport { render, screen } from '@testing-library/react'\nimport '@testing-library/jest-dom'\n\nimport { type Data, type ValueType, type DataType, ControlDefinition } from '@makeswift/controls'\n\nimport { ElementData } from '../../../../state/react-page'\nimport { Page } from '../../page'\nimport { ReactRuntimeProvider } from '../../../../runtimes/react'\nimport { ReactRuntime } from '../../../../react'\n\nimport {\n createMakeswiftPageSnapshot,\n createRootComponent,\n} from '../../../../utils/tests/element-data-test-test'\n\nimport { type MakeswiftPageSnapshot } from '../../../../next'\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) =>\n prop.childElementCount ? prop.childNodes : parseStringifiedProp(prop.textContent ?? '')\n\nconst parseStringifiedProp = (prop: string) => (prop === 'undefined' ? undefined : JSON.parse(prop))\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 }: {\n toData?: (value: ValueType<D>) => DataType<D>\n value: ValueType<D> | undefined\n locale?: string | null\n cacheData?: Partial<MakeswiftPageSnapshot['cacheData']>\n expectedRenders?: number\n registerComponents?: (runtime: ReactRuntime) => void\n action?: (element: HTMLElement) => Promise<void>\n rootElements?: ElementData[]\n },\n) {\n // Arrange\n const controlData: DataType<D> | Data =\n value !== undefined ? (toData ? toData(value) : controlDefinition.toData(value)) : undefined\n\n const TestComponentType = 'TestComponent'\n const testId = 'test-id'\n const renderCountTestId = 'render-count-test-id'\n const elementData: ElementData = createRootComponent(\n [\n {\n key: ELEMENT_ID,\n type: TestComponentType,\n props: {\n propKey: controlData,\n },\n },\n ...rootElements,\n ],\n ROOT_ID,\n )\n const snapshot = createMakeswiftPageSnapshot(elementData, { locale, cacheData })\n const runtime = new ReactRuntime()\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 type: TestComponentType,\n label: 'TestComponent',\n props: {\n propKey: controlDefinition as any,\n },\n },\n )\n\n // Assert\n await act(async () =>\n render(\n <ReactRuntimeProvider runtime={runtime} previewMode={false}>\n <Page snapshot={snapshot} />\n </ReactRuntimeProvider>,\n ),\n )\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"],"mappings":"AAqFQ,SACE,KADF;AAnFR,SAAS,YAAY,QAAQ,sBAAsB;AACnD,SAAS,WAAW;AACpB,SAAS,QAAQ,cAAc;AAC/B,OAAO;AAKP,SAAS,YAAY;AACrB,SAAS,4BAA4B;AACrC,SAAS,oBAAoB;AAE7B;AAAA,EACE;AAAA,EACA;AAAA,OACK;AAIP,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,KAAK,oBAAoB,KAAK,aAAa,qBAAqB,KAAK,eAAe,EAAE;AAExF,MAAM,uBAAuB,CAAC,SAAkB,SAAS,cAAc,SAAY,KAAK,MAAM,IAAI;AAElG,eAAsB,6BAC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aAAa,OAAO,YAAY,MAAM,CAAC,CAAC,EAAE,gBAAgB,eAAe;AAEhF,MAAI,mBAAmB,MAAM;AAC3B,WAAO,OAAO,OAAO,YAAY,iBAAiB,EAAE,WAAW,CAAC,EAAE,KAAK,eAAe;AAAA,EACxF;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../../../../src/next/components/tests/controls/page-control-prop-rendering.tsx"],"sourcesContent":["import { type ReactNode, Fragment, forwardRef, useRef, isValidElement } from 'react'\nimport { renderToReadableStream } from 'react-dom/server'\nimport { JSDOM } from 'jsdom'\nimport { act } from 'react-dom/test-utils'\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/react'\nimport { ElementData } from '../../../../state/react-page'\nimport { ReactRuntime } from '../../../../react'\nimport { MakeswiftComponent } from '../../MakeswiftComponent'\nimport { Page } from '../../page'\nimport { isServer } from '../../../../utils/is-server'\nimport * as Testing from '../../../../runtimes/react/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\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 }: {\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 },\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 = new ReactRuntime()\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 <Testing.ReactProvider runtime={runtime}>{component}</Testing.ReactProvider>\n )\n\n if (!isServer()) {\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 } 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":"AAsDI,cA0EI,YA1EJ;AAtDJ,SAAyB,UAAU,YAAY,QAAQ,sBAAsB;AAC7E,SAAS,8BAA8B;AACvC,SAAS,aAAa;AACtB,SAAS,WAAW;AACpB,SAAS,QAAQ,cAAc;AAC/B,OAAO;AACP,SAAS,iCAAiC;AAM1C,SAAS,oBAAoB;AAC7B,SAAS,0BAA0B;AACnC,SAAS,YAAY;AACrB,SAAS,gBAAgB;AACzB,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AAQ,EAAE,gBAAgB,UAAU;AAC3C,WAAO,aAAa,OAAO,YAAY,MAAM,CAAC,CAAC,EAAE,gBAAgB,eAAe;AAEhF,QAAI,mBAAmB,MAAM;AAC3B,aAAO,OAAO,OAAO,YAAY,iBAAiB,EAAE,WAAW,CAAC,EAAE,KAAK,eAAe;AAAA,IACxF;AAAA,EACF,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":[]}
@@ -0,0 +1,56 @@
1
+ import { APIResourceType } from "../../../../../api";
2
+ import * as Fixture from "../fixtures/rich-text-v2";
3
+ const swatchId = "U3dhdGNoOmJkODYxMWM5LTNiZjItNDM3MS1iMmU4LTBmMmNlMDZjNDE1OA==";
4
+ const swatch = {
5
+ __typename: APIResourceType.Swatch,
6
+ id: swatchId,
7
+ hue: 238,
8
+ saturation: 87,
9
+ lightness: 49
10
+ };
11
+ const typographyId = "VHlwb2dyYXBoeTowNGI4OTZlMC0wZWEyLTRkMTMtYmU3ZS0xYmY1M2VmMjBiZjc=";
12
+ const typography = {
13
+ __typename: APIResourceType.Typography,
14
+ id: typographyId,
15
+ name: "Body",
16
+ style: [
17
+ {
18
+ deviceId: "desktop",
19
+ value: {
20
+ fontFamily: "Lato",
21
+ fontSize: { value: 16, unit: "px" },
22
+ color: null,
23
+ lineHeight: null,
24
+ letterSpacing: null,
25
+ fontWeight: null,
26
+ textAlign: null,
27
+ uppercase: null,
28
+ underline: null,
29
+ strikethrough: null,
30
+ italic: null
31
+ }
32
+ }
33
+ ]
34
+ };
35
+ const value = Fixture.data;
36
+ const cacheData = () => ({
37
+ apiResources: {
38
+ Swatch: [
39
+ {
40
+ id: swatchId,
41
+ value: swatch
42
+ }
43
+ ],
44
+ Typography: [
45
+ {
46
+ id: typographyId,
47
+ value: typography
48
+ }
49
+ ]
50
+ }
51
+ });
52
+ export {
53
+ cacheData,
54
+ value
55
+ };
56
+ //# sourceMappingURL=fixtures.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../src/next/components/tests/controls/rich-text-v2-control/fixtures.tsx"],"sourcesContent":["import { APIResourceType, type Swatch, type Typography } from '../../../../../api'\n\nimport * as Fixture from '../fixtures/rich-text-v2'\nimport { type CacheData } from '../../../../../api/react'\n\nconst swatchId = 'U3dhdGNoOmJkODYxMWM5LTNiZjItNDM3MS1iMmU4LTBmMmNlMDZjNDE1OA=='\nconst swatch: Swatch = {\n __typename: APIResourceType.Swatch,\n id: swatchId,\n hue: 238,\n saturation: 87,\n lightness: 49,\n}\n\nconst typographyId = 'VHlwb2dyYXBoeTowNGI4OTZlMC0wZWEyLTRkMTMtYmU3ZS0xYmY1M2VmMjBiZjc='\nconst typography: Typography = {\n __typename: APIResourceType.Typography,\n id: typographyId,\n name: 'Body',\n style: [\n {\n deviceId: 'desktop',\n value: {\n fontFamily: 'Lato',\n fontSize: { value: 16, unit: 'px' },\n color: null,\n lineHeight: null,\n letterSpacing: null,\n fontWeight: null,\n textAlign: null,\n uppercase: null,\n underline: null,\n strikethrough: null,\n italic: null,\n },\n },\n ],\n}\n\nexport const value = Fixture.data\nexport const cacheData = (): Partial<CacheData> => ({\n apiResources: {\n Swatch: [\n {\n id: swatchId,\n value: swatch,\n },\n ],\n Typography: [\n {\n id: typographyId,\n value: typography,\n },\n ],\n },\n})\n"],"mappings":"AAAA,SAAS,uBAAqD;AAE9D,YAAY,aAAa;AAGzB,MAAM,WAAW;AACjB,MAAM,SAAiB;AAAA,EACrB,YAAY,gBAAgB;AAAA,EAC5B,IAAI;AAAA,EACJ,KAAK;AAAA,EACL,YAAY;AAAA,EACZ,WAAW;AACb;AAEA,MAAM,eAAe;AACrB,MAAM,aAAyB;AAAA,EAC7B,YAAY,gBAAgB;AAAA,EAC5B,IAAI;AAAA,EACJ,MAAM;AAAA,EACN,OAAO;AAAA,IACL;AAAA,MACE,UAAU;AAAA,MACV,OAAO;AAAA,QACL,YAAY;AAAA,QACZ,UAAU,EAAE,OAAO,IAAI,MAAM,KAAK;AAAA,QAClC,OAAO;AAAA,QACP,YAAY;AAAA,QACZ,eAAe;AAAA,QACf,YAAY;AAAA,QACZ,WAAW;AAAA,QACX,WAAW;AAAA,QACX,WAAW;AAAA,QACX,eAAe;AAAA,QACf,QAAQ;AAAA,MACV;AAAA,IACF;AAAA,EACF;AACF;AAEO,MAAM,QAAQ,QAAQ;AACtB,MAAM,YAAY,OAA2B;AAAA,EAClD,cAAc;AAAA,IACZ,QAAQ;AAAA,MACN;AAAA,QACE,IAAI;AAAA,QACJ,OAAO;AAAA,MACT;AAAA,IACF;AAAA,IACA,YAAY;AAAA,MACV;AAAA,QACE,IAAI;AAAA,QACJ,OAAO;AAAA,MACT;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
@@ -0,0 +1,35 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { Style, TextInput } from "../../../../../controls";
3
+ import { MakeswiftComponentType } from "../../../../../components/builtin/constants";
4
+ function Button({ className, title }) {
5
+ return /* @__PURE__ */ jsx("button", { className, children: title });
6
+ }
7
+ const value = {
8
+ width: [{ deviceId: "desktop", value: { value: 80, unit: "%" } }],
9
+ margin: [
10
+ {
11
+ deviceId: "desktop",
12
+ value: {
13
+ marginTop: { value: 4, unit: "px" },
14
+ marginLeft: void 0,
15
+ marginRight: void 0,
16
+ marginBottom: void 0
17
+ }
18
+ }
19
+ ]
20
+ };
21
+ const registerComponents = (runtime) => {
22
+ runtime.registerComponent(Button, {
23
+ type: MakeswiftComponentType.Button,
24
+ label: "Button",
25
+ props: {
26
+ className: Style(),
27
+ title: TextInput({ defaultValue: "Button" })
28
+ }
29
+ });
30
+ };
31
+ export {
32
+ registerComponents,
33
+ value
34
+ };
35
+ //# sourceMappingURL=fixtures.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../src/next/components/tests/controls/style-control/fixtures.tsx"],"sourcesContent":["import { type ValueType } from '@makeswift/controls'\nimport { Style, StyleDefinition, TextInput } from '../../../../../controls'\nimport { MakeswiftComponentType } from '../../../../../components/builtin/constants'\nimport { ReactRuntime } from '../../../../../react'\n\nfunction Button({ className, title }: { className: string; title: string }) {\n return <button className={className}>{title}</button>\n}\n\nexport const value: ValueType<StyleDefinition> = {\n width: [{ deviceId: 'desktop', value: { value: 80, unit: '%' } }],\n margin: [\n {\n deviceId: 'desktop',\n value: {\n marginTop: { value: 4, unit: 'px' },\n marginLeft: undefined,\n marginRight: undefined,\n marginBottom: undefined,\n },\n },\n ],\n}\n\nexport const registerComponents = (runtime: ReactRuntime) => {\n runtime.registerComponent(Button, {\n type: MakeswiftComponentType.Button,\n label: 'Button',\n props: {\n className: Style(),\n title: TextInput({ defaultValue: 'Button' }),\n },\n })\n}\n"],"mappings":"AAMS;AALT,SAAS,OAAwB,iBAAiB;AAClD,SAAS,8BAA8B;AAGvC,SAAS,OAAO,EAAE,WAAW,MAAM,GAAyC;AAC1E,SAAO,oBAAC,YAAO,WAAuB,iBAAM;AAC9C;AAEO,MAAM,QAAoC;AAAA,EAC/C,OAAO,CAAC,EAAE,UAAU,WAAW,OAAO,EAAE,OAAO,IAAI,MAAM,IAAI,EAAE,CAAC;AAAA,EAChE,QAAQ;AAAA,IACN;AAAA,MACE,UAAU;AAAA,MACV,OAAO;AAAA,QACL,WAAW,EAAE,OAAO,GAAG,MAAM,KAAK;AAAA,QAClC,YAAY;AAAA,QACZ,aAAa;AAAA,QACb,cAAc;AAAA,MAChB;AAAA,IACF;AAAA,EACF;AACF;AAEO,MAAM,qBAAqB,CAAC,YAA0B;AAC3D,UAAQ,kBAAkB,QAAQ;AAAA,IAChC,MAAM,uBAAuB;AAAA,IAC7B,OAAO;AAAA,IACP,OAAO;AAAA,MACL,WAAW,MAAM;AAAA,MACjB,OAAO,UAAU,EAAE,cAAc,SAAS,CAAC;AAAA,IAC7C;AAAA,EACF,CAAC;AACH;","names":[]}
@@ -7,12 +7,8 @@ import {
7
7
  import { randomUUID } from "crypto";
8
8
  import { Page } from "../../page";
9
9
  import { act } from "react-dom/test-utils";
10
- import { ReactRuntimeProvider } from "../../../../runtimes/react";
11
10
  import { ReactRuntime } from "../../../../react";
12
- import {
13
- createMakeswiftPageSnapshot,
14
- createRootComponent
15
- } from "../../../../utils/tests/element-data-test-test";
11
+ import * as Testing from "../../../../runtimes/react/testing";
16
12
  const pagePropControllerTest = (propDef, value, component, assert, options) => describe("Page", () => {
17
13
  test(`can render ${propDef.type} v0 data`, async () => {
18
14
  const descriptorV0 = {
@@ -21,7 +17,7 @@ const pagePropControllerTest = (propDef, value, component, assert, options) => d
21
17
  };
22
18
  const TestComponentType = "TestComponent";
23
19
  const testId = "test-id";
24
- const elementData = createRootComponent([
20
+ const elementData = Testing.createRootComponent([
25
21
  {
26
22
  key: randomUUID(),
27
23
  type: TestComponentType,
@@ -30,7 +26,7 @@ const pagePropControllerTest = (propDef, value, component, assert, options) => d
30
26
  }
31
27
  }
32
28
  ]);
33
- const snapshot = createMakeswiftPageSnapshot(elementData);
29
+ const snapshot = Testing.createMakeswiftPageSnapshot(elementData);
34
30
  const runtime = new ReactRuntime();
35
31
  runtime.registerComponent(component(testId), {
36
32
  type: TestComponentType,
@@ -41,7 +37,7 @@ const pagePropControllerTest = (propDef, value, component, assert, options) => d
41
37
  });
42
38
  await act(
43
39
  async () => render(
44
- /* @__PURE__ */ jsx(ReactRuntimeProvider, { runtime, previewMode: false, children: /* @__PURE__ */ jsx(Page, { snapshot }) })
40
+ /* @__PURE__ */ jsx(Testing.ReactProvider, { runtime, children: /* @__PURE__ */ jsx(Page, { snapshot }) })
45
41
  )
46
42
  );
47
43
  assert(screen.getByTestId(testId));
@@ -54,7 +50,7 @@ const pagePropControllerTest = (propDef, value, component, assert, options) => d
54
50
  };
55
51
  const TestComponentType = "TestComponent";
56
52
  const testId = "test-id";
57
- const elementData = createRootComponent([
53
+ const elementData = Testing.createRootComponent([
58
54
  {
59
55
  key: randomUUID(),
60
56
  type: TestComponentType,
@@ -63,7 +59,7 @@ const pagePropControllerTest = (propDef, value, component, assert, options) => d
63
59
  }
64
60
  }
65
61
  ]);
66
- const snapshot = createMakeswiftPageSnapshot(elementData);
62
+ const snapshot = Testing.createMakeswiftPageSnapshot(elementData);
67
63
  const runtime = new ReactRuntime();
68
64
  runtime.registerComponent(component(testId), {
69
65
  type: TestComponentType,
@@ -74,7 +70,7 @@ const pagePropControllerTest = (propDef, value, component, assert, options) => d
74
70
  });
75
71
  await act(
76
72
  async () => render(
77
- /* @__PURE__ */ jsx(ReactRuntimeProvider, { runtime, previewMode: false, children: /* @__PURE__ */ jsx(Page, { snapshot }) })
73
+ /* @__PURE__ */ jsx(Testing.ReactProvider, { runtime, children: /* @__PURE__ */ jsx(Page, { snapshot }) })
78
74
  )
79
75
  );
80
76
  assert(screen.getByTestId(testId));
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../src/next/components/tests/prop-controllers/page-prop-controller.tsx"],"sourcesContent":["/** @jest-environment jsdom */\n\nimport { render, screen } from '@testing-library/react'\nimport '@testing-library/jest-dom'\n\nimport {\n type OptionsType,\n Types,\n type Descriptor,\n type PropDef,\n type Value,\n} from '@makeswift/prop-controllers'\n\nimport { type ElementData, type ComponentType } from '../../../../state/react-page'\nimport { randomUUID } from 'crypto'\n\nimport { Page } from '../../page'\nimport { act } from 'react-dom/test-utils'\nimport { ReactRuntimeProvider } from '../../../../runtimes/react'\nimport { ReactRuntime } from '../../../../react'\nimport {\n createMakeswiftPageSnapshot,\n createRootComponent,\n} from '../../../../utils/tests/element-data-test-test'\n\nexport const pagePropControllerTest = <\n P extends PropDef & ((options?: any) => any),\n C extends ComponentType<{ propKey: Value<P> | undefined }>,\n>(\n propDef: P,\n value: Value<typeof propDef>,\n component: (testId: string) => C,\n assert: (element: HTMLElement) => void,\n options?: OptionsType<P>,\n) =>\n describe('Page', () => {\n test(`can render ${propDef.type} v0 data`, async () => {\n // Arrange\n const descriptorV0: Descriptor<typeof propDef> = {\n type: propDef.type,\n options,\n }\n\n const TestComponentType = 'TestComponent'\n const testId = 'test-id'\n\n const elementData: ElementData = createRootComponent([\n {\n key: randomUUID(),\n type: TestComponentType,\n props: {\n propKey: propDef.toPropData(value, descriptorV0),\n },\n },\n ])\n const snapshot = createMakeswiftPageSnapshot(elementData)\n const runtime = new ReactRuntime()\n\n runtime.registerComponent(component(testId), {\n type: TestComponentType,\n label: 'TestComponent',\n props: {\n propKey: propDef(options),\n },\n })\n\n await act(async () =>\n render(\n <ReactRuntimeProvider runtime={runtime} previewMode={false}>\n <Page snapshot={snapshot} />\n </ReactRuntimeProvider>,\n ),\n )\n\n assert(screen.getByTestId(testId))\n })\n\n test(`can render ${propDef.type} v1 data`, async () => {\n // Arrange\n const gapXDefinitionV1: Descriptor<typeof propDef> = {\n type: Types.GapX,\n version: 1,\n options: {},\n }\n\n const TestComponentType = 'TestComponent'\n const testId = 'test-id'\n const elementData: ElementData = createRootComponent([\n {\n key: randomUUID(),\n type: TestComponentType,\n props: {\n propKey: propDef.toPropData(value, gapXDefinitionV1),\n },\n },\n ])\n const snapshot = createMakeswiftPageSnapshot(elementData)\n const runtime = new ReactRuntime()\n\n runtime.registerComponent(component(testId), {\n type: TestComponentType,\n label: 'TestComponent',\n props: {\n propKey: propDef(options),\n },\n })\n\n await act(async () =>\n render(\n <ReactRuntimeProvider runtime={runtime} previewMode={false}>\n <Page snapshot={snapshot} />\n </ReactRuntimeProvider>,\n ),\n )\n\n assert(screen.getByTestId(testId))\n })\n })\n"],"mappings":"AAqEY;AAnEZ,SAAS,QAAQ,cAAc;AAC/B,OAAO;AAEP;AAAA,EAEE;AAAA,OAIK;AAGP,SAAS,kBAAkB;AAE3B,SAAS,YAAY;AACrB,SAAS,WAAW;AACpB,SAAS,4BAA4B;AACrC,SAAS,oBAAoB;AAC7B;AAAA,EACE;AAAA,EACA;AAAA,OACK;AAEA,MAAM,yBAAyB,CAIpC,SACA,OACA,WACA,QACA,YAEA,SAAS,QAAQ,MAAM;AACrB,OAAK,cAAc,QAAQ,IAAI,YAAY,YAAY;AAErD,UAAM,eAA2C;AAAA,MAC/C,MAAM,QAAQ;AAAA,MACd;AAAA,IACF;AAEA,UAAM,oBAAoB;AAC1B,UAAM,SAAS;AAEf,UAAM,cAA2B,oBAAoB;AAAA,MACnD;AAAA,QACE,KAAK,WAAW;AAAA,QAChB,MAAM;AAAA,QACN,OAAO;AAAA,UACL,SAAS,QAAQ,WAAW,OAAO,YAAY;AAAA,QACjD;AAAA,MACF;AAAA,IACF,CAAC;AACD,UAAM,WAAW,4BAA4B,WAAW;AACxD,UAAM,UAAU,IAAI,aAAa;AAEjC,YAAQ,kBAAkB,UAAU,MAAM,GAAG;AAAA,MAC3C,MAAM;AAAA,MACN,OAAO;AAAA,MACP,OAAO;AAAA,QACL,SAAS,QAAQ,OAAO;AAAA,MAC1B;AAAA,IACF,CAAC;AAED,UAAM;AAAA,MAAI,YACR;AAAA,QACE,oBAAC,wBAAqB,SAAkB,aAAa,OACnD,8BAAC,QAAK,UAAoB,GAC5B;AAAA,MACF;AAAA,IACF;AAEA,WAAO,OAAO,YAAY,MAAM,CAAC;AAAA,EACnC,CAAC;AAED,OAAK,cAAc,QAAQ,IAAI,YAAY,YAAY;AAErD,UAAM,mBAA+C;AAAA,MACnD,MAAM,MAAM;AAAA,MACZ,SAAS;AAAA,MACT,SAAS,CAAC;AAAA,IACZ;AAEA,UAAM,oBAAoB;AAC1B,UAAM,SAAS;AACf,UAAM,cAA2B,oBAAoB;AAAA,MACnD;AAAA,QACE,KAAK,WAAW;AAAA,QAChB,MAAM;AAAA,QACN,OAAO;AAAA,UACL,SAAS,QAAQ,WAAW,OAAO,gBAAgB;AAAA,QACrD;AAAA,MACF;AAAA,IACF,CAAC;AACD,UAAM,WAAW,4BAA4B,WAAW;AACxD,UAAM,UAAU,IAAI,aAAa;AAEjC,YAAQ,kBAAkB,UAAU,MAAM,GAAG;AAAA,MAC3C,MAAM;AAAA,MACN,OAAO;AAAA,MACP,OAAO;AAAA,QACL,SAAS,QAAQ,OAAO;AAAA,MAC1B;AAAA,IACF,CAAC;AAED,UAAM;AAAA,MAAI,YACR;AAAA,QACE,oBAAC,wBAAqB,SAAkB,aAAa,OACnD,8BAAC,QAAK,UAAoB,GAC5B;AAAA,MACF;AAAA,IACF;AAEA,WAAO,OAAO,YAAY,MAAM,CAAC;AAAA,EACnC,CAAC;AACH,CAAC;","names":[]}
1
+ {"version":3,"sources":["../../../../../../src/next/components/tests/prop-controllers/page-prop-controller.tsx"],"sourcesContent":["/** @jest-environment jsdom */\n\nimport { render, screen } from '@testing-library/react'\nimport '@testing-library/jest-dom'\n\nimport {\n type OptionsType,\n Types,\n type Descriptor,\n type PropDef,\n type Value,\n} from '@makeswift/prop-controllers'\n\nimport { type ElementData, type ComponentType } from '../../../../state/react-page'\nimport { randomUUID } from 'crypto'\n\nimport { Page } from '../../page'\nimport { act } from 'react-dom/test-utils'\nimport { ReactRuntime } from '../../../../react'\nimport * as Testing from '../../../../runtimes/react/testing'\n\nexport const pagePropControllerTest = <\n P extends PropDef & ((options?: any) => any),\n C extends ComponentType<{ propKey: Value<P> | undefined }>,\n>(\n propDef: P,\n value: Value<typeof propDef>,\n component: (testId: string) => C,\n assert: (element: HTMLElement) => void,\n options?: OptionsType<P>,\n) =>\n describe('Page', () => {\n test(`can render ${propDef.type} v0 data`, async () => {\n // Arrange\n const descriptorV0: Descriptor<typeof propDef> = {\n type: propDef.type,\n options,\n }\n\n const TestComponentType = 'TestComponent'\n const testId = 'test-id'\n\n const elementData: ElementData = Testing.createRootComponent([\n {\n key: randomUUID(),\n type: TestComponentType,\n props: {\n propKey: propDef.toPropData(value, descriptorV0),\n },\n },\n ])\n const snapshot = Testing.createMakeswiftPageSnapshot(elementData)\n const runtime = new ReactRuntime()\n\n runtime.registerComponent(component(testId), {\n type: TestComponentType,\n label: 'TestComponent',\n props: {\n propKey: propDef(options),\n },\n })\n\n await act(async () =>\n render(\n <Testing.ReactProvider runtime={runtime}>\n <Page snapshot={snapshot} />\n </Testing.ReactProvider>,\n ),\n )\n\n assert(screen.getByTestId(testId))\n })\n\n test(`can render ${propDef.type} v1 data`, async () => {\n // Arrange\n const gapXDefinitionV1: Descriptor<typeof propDef> = {\n type: Types.GapX,\n version: 1,\n options: {},\n }\n\n const TestComponentType = 'TestComponent'\n const testId = 'test-id'\n const elementData: ElementData = Testing.createRootComponent([\n {\n key: randomUUID(),\n type: TestComponentType,\n props: {\n propKey: propDef.toPropData(value, gapXDefinitionV1),\n },\n },\n ])\n const snapshot = Testing.createMakeswiftPageSnapshot(elementData)\n const runtime = new ReactRuntime()\n\n runtime.registerComponent(component(testId), {\n type: TestComponentType,\n label: 'TestComponent',\n props: {\n propKey: propDef(options),\n },\n })\n\n await act(async () =>\n render(\n <Testing.ReactProvider runtime={runtime}>\n <Page snapshot={snapshot} />\n </Testing.ReactProvider>,\n ),\n )\n\n assert(screen.getByTestId(testId))\n })\n })\n"],"mappings":"AAiEY;AA/DZ,SAAS,QAAQ,cAAc;AAC/B,OAAO;AAEP;AAAA,EAEE;AAAA,OAIK;AAGP,SAAS,kBAAkB;AAE3B,SAAS,YAAY;AACrB,SAAS,WAAW;AACpB,SAAS,oBAAoB;AAC7B,Y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UAAM,UAAU,IAAI,aAAa;AAEjC,YAAQ,kBAAkB,UAAU,MAAM,GAAG;AAAA,MAC3C,MAAM;AAAA,MACN,OAAO;AAAA,MACP,OAAO;AAAA,QACL,SAAS,QAAQ,OAAO;AAAA,MAC1B;AAAA,IACF,CAAC;AAED,UAAM;AAAA,MAAI,YACR;AAAA,QACE,oBAAC,QAAQ,eAAR,EAAsB,SACrB,8BAAC,QAAK,UAAoB,GAC5B;AAAA,MACF;AAAA,IACF;AAEA,WAAO,OAAO,YAAY,MAAM,CAAC;AAAA,EACnC,CAAC;AACH,CAAC;","names":[]}
@@ -5,26 +5,27 @@ import { cache } from "@emotion/css";
5
5
  import { useServerInsertedHTML } from "next/navigation";
6
6
  import { createContext, useContext, useState } from "react";
7
7
  const CacheContext = createContext(cache);
8
+ const createRootStyleCache = () => {
9
+ const cache2 = createCache({ key: "css" });
10
+ cache2.compat = true;
11
+ const prevInsert = cache2.insert;
12
+ let inserted = [];
13
+ cache2.insert = (...args) => {
14
+ const serialized = args[1];
15
+ if (cache2.inserted[serialized.name] === void 0) {
16
+ inserted.push(serialized.name);
17
+ }
18
+ return prevInsert(...args);
19
+ };
20
+ const flush = () => {
21
+ const prevInserted = inserted;
22
+ inserted = [];
23
+ return prevInserted;
24
+ };
25
+ return { cache: cache2, flush };
26
+ };
8
27
  function RootStyleRegistry({ children }) {
9
- const [{ cache: cache2, flush }] = useState(() => {
10
- const cache3 = createCache({ key: "css" });
11
- cache3.compat = true;
12
- const prevInsert = cache3.insert;
13
- let inserted = [];
14
- cache3.insert = (...args) => {
15
- const serialized = args[1];
16
- if (cache3.inserted[serialized.name] === void 0) {
17
- inserted.push(serialized.name);
18
- }
19
- return prevInsert(...args);
20
- };
21
- const flush2 = () => {
22
- const prevInserted = inserted;
23
- inserted = [];
24
- return prevInserted;
25
- };
26
- return { cache: cache3, flush: flush2 };
27
- });
28
+ const [{ cache: cache2, flush }] = useState(() => createRootStyleCache());
28
29
  useServerInsertedHTML(() => {
29
30
  const names = flush();
30
31
  if (names.length === 0)
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/next/root-style-registry.tsx"],"sourcesContent":["'use client'\n\nimport createCache, { EmotionCache } from '@emotion/cache'\nimport { cache } from '@emotion/css'\nimport { useServerInsertedHTML } from 'next/navigation'\nimport { ReactNode, createContext, useContext, useState } from 'react'\n\nconst CacheContext = createContext(cache)\n\nexport function RootStyleRegistry({ children }: { children: ReactNode }) {\n const [{ cache, flush }] = useState(() => {\n const cache = createCache({ key: 'css' })\n cache.compat = true\n const prevInsert = cache.insert\n let inserted: string[] = []\n cache.insert = (...args) => {\n const serialized = args[1]\n if (cache.inserted[serialized.name] === undefined) {\n inserted.push(serialized.name)\n }\n return prevInsert(...args)\n }\n const flush = () => {\n const prevInserted = inserted\n inserted = []\n return prevInserted\n }\n return { cache, flush }\n })\n\n useServerInsertedHTML(() => {\n const names = flush()\n if (names.length === 0) return null\n let styles = ''\n for (const name of names) {\n styles += cache.inserted[name]\n }\n return (\n <style\n data-emotion={`${cache.key} ${names.join(' ')}`}\n dangerouslySetInnerHTML={{\n __html: styles,\n }}\n />\n )\n })\n\n return <CacheContext.Provider value={cache}>{children}</CacheContext.Provider>\n}\n\nexport function useCache(): EmotionCache {\n return useContext(CacheContext)\n}\n"],"mappings":";AAsCM;AApCN,OAAO,iBAAmC;AAC1C,SAAS,aAAa;AACtB,SAAS,6BAA6B;AACtC,SAAoB,eAAe,YAAY,gBAAgB;AAE/D,MAAM,eAAe,cAAc,KAAK;AAEjC,SAAS,kBAAkB,EAAE,SAAS,GAA4B;AACvE,QAAM,CAAC,EAAE,OAAAA,QAAO,MAAM,CAAC,IAAI,SAAS,MAAM;AACxC,UAAMA,SAAQ,YAAY,EAAE,KAAK,MAAM,CAAC;AACxC,IAAAA,OAAM,SAAS;AACf,UAAM,aAAaA,OAAM;AACzB,QAAI,WAAqB,CAAC;AAC1B,IAAAA,OAAM,SAAS,IAAI,SAAS;AAC1B,YAAM,aAAa,KAAK,CAAC;AACzB,UAAIA,OAAM,SAAS,WAAW,IAAI,MAAM,QAAW;AACjD,iBAAS,KAAK,WAAW,IAAI;AAAA,MAC/B;AACA,aAAO,WAAW,GAAG,IAAI;AAAA,IAC3B;AACA,UAAMC,SAAQ,MAAM;AAClB,YAAM,eAAe;AACrB,iBAAW,CAAC;AACZ,aAAO;AAAA,IACT;AACA,WAAO,EAAE,OAAAD,QAAO,OAAAC,OAAM;AAAA,EACxB,CAAC;AAED,wBAAsB,MAAM;AAC1B,UAAM,QAAQ,MAAM;AACpB,QAAI,MAAM,WAAW;AAAG,aAAO;AAC/B,QAAI,SAAS;AACb,eAAW,QAAQ,OAAO;AACxB,gBAAUD,OAAM,SAAS,IAAI;AAAA,IAC/B;AACA,WACE;AAAA,MAAC;AAAA;AAAA,QACC,gBAAc,GAAGA,OAAM,GAAG,IAAI,MAAM,KAAK,GAAG,CAAC;AAAA,QAC7C,yBAAyB;AAAA,UACvB,QAAQ;AAAA,QACV;AAAA;AAAA,IACF;AAAA,EAEJ,CAAC;AAED,SAAO,oBAAC,aAAa,UAAb,EAAsB,OAAOA,QAAQ,UAAS;AACxD;AAEO,SAAS,WAAyB;AACvC,SAAO,WAAW,YAAY;AAChC;","names":["cache","flush"]}
1
+ {"version":3,"sources":["../../../src/next/root-style-registry.tsx"],"sourcesContent":["'use client'\n\nimport createCache, { EmotionCache } from '@emotion/cache'\nimport { cache } from '@emotion/css'\nimport { useServerInsertedHTML } from 'next/navigation'\nimport { ReactNode, createContext, useContext, useState } from 'react'\n\nconst CacheContext = createContext(cache)\n\nconst createRootStyleCache = () => {\n const cache = createCache({ key: 'css' })\n cache.compat = true\n\n const prevInsert = cache.insert\n let inserted: string[] = []\n\n cache.insert = (...args) => {\n const serialized = args[1]\n if (cache.inserted[serialized.name] === undefined) {\n inserted.push(serialized.name)\n }\n return prevInsert(...args)\n }\n\n const flush = () => {\n const prevInserted = inserted\n inserted = []\n return prevInserted\n }\n\n return { cache, flush }\n}\n\nexport function RootStyleRegistry({ children }: { children: ReactNode }) {\n const [{ cache, flush }] = useState(() => createRootStyleCache())\n\n useServerInsertedHTML(() => {\n const names = flush()\n if (names.length === 0) return null\n let styles = ''\n for (const name of names) {\n styles += cache.inserted[name]\n }\n\n return (\n <style\n data-emotion={`${cache.key} ${names.join(' ')}`}\n dangerouslySetInnerHTML={{\n __html: styles,\n }}\n />\n )\n })\n\n return <CacheContext.Provider value={cache}>{children}</CacheContext.Provider>\n}\n\nexport function useCache(): EmotionCache {\n return useContext(CacheContext)\n}\n"],"mappings":";AA6CM;AA3CN,OAAO,iBAAmC;AAC1C,SAAS,aAAa;AACtB,SAAS,6BAA6B;AACtC,SAAoB,eAAe,YAAY,gBAAgB;AAE/D,MAAM,eAAe,cAAc,KAAK;AAExC,MAAM,uBAAuB,MAAM;AACjC,QAAMA,SAAQ,YAAY,EAAE,KAAK,MAAM,CAAC;AACxC,EAAAA,OAAM,SAAS;AAEf,QAAM,aAAaA,OAAM;AACzB,MAAI,WAAqB,CAAC;AAE1B,EAAAA,OAAM,SAAS,IAAI,SAAS;AAC1B,UAAM,aAAa,KAAK,CAAC;AACzB,QAAIA,OAAM,SAAS,WAAW,IAAI,MAAM,QAAW;AACjD,eAAS,KAAK,WAAW,IAAI;AAAA,IAC/B;AACA,WAAO,WAAW,GAAG,IAAI;AAAA,EAC3B;AAEA,QAAM,QAAQ,MAAM;AAClB,UAAM,eAAe;AACrB,eAAW,CAAC;AACZ,WAAO;AAAA,EACT;AAEA,SAAO,EAAE,OAAAA,QAAO,MAAM;AACxB;AAEO,SAAS,kBAAkB,EAAE,SAAS,GAA4B;AACvE,QAAM,CAAC,EAAE,OAAAA,QAAO,MAAM,CAAC,IAAI,SAAS,MAAM,qBAAqB,CAAC;AAEhE,wBAAsB,MAAM;AAC1B,UAAM,QAAQ,MAAM;AACpB,QAAI,MAAM,WAAW;AAAG,aAAO;AAC/B,QAAI,SAAS;AACb,eAAW,QAAQ,OAAO;AACxB,gBAAUA,OAAM,SAAS,IAAI;AAAA,IAC/B;AAEA,WACE;AAAA,MAAC;AAAA;AAAA,QACC,gBAAc,GAAGA,OAAM,GAAG,IAAI,MAAM,KAAK,GAAG,CAAC;AAAA,QAC7C,yBAAyB;AAAA,UACvB,QAAQ;AAAA,QACV;AAAA;AAAA,IACF;AAAA,EAEJ,CAAC;AAED,SAAO,oBAAC,aAAa,UAAb,EAAsB,OAAOA,QAAQ,UAAS;AACxD;AAEO,SAAS,WAAyB;AACvC,SAAO,WAAW,YAAY;AAChC;","names":["cache"]}
@@ -53,11 +53,12 @@ function useResolvedProps(propDefs, elementData, elementKey) {
53
53
  [propDefs, resolveProp]
54
54
  );
55
55
  const props = useMemo(() => resolvableRecord(resolvables), [resolvables]);
56
- stylesheetFactory.useDefinedStyles();
57
56
  useEffect(() => {
58
57
  props.triggerResolve();
59
58
  }, []);
60
- return useSyncExternalStore(props.subscribe, props.readStable, props.readStable);
59
+ const resolvedProps = useSyncExternalStore(props.subscribe, props.readStable, props.readStable);
60
+ stylesheetFactory.useDefinedStyles();
61
+ return resolvedProps;
61
62
  }
62
63
  export {
63
64
  useResolvedProps
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/runtimes/react/hooks/use-resolved-props.ts"],"sourcesContent":["import { useMemo, useEffect, useRef, useSyncExternalStore, useCallback } from 'react'\nimport {\n ControlDefinition,\n ControlInstance,\n mapValues,\n type Data,\n type Resolvable,\n} from '@makeswift/controls'\n\nimport * as ReactPage from '../../../state/react-page'\nimport { useResourceResolver } from './use-resource-resolver'\nimport { useDocumentKey } from './use-document-context'\nimport { useSelector } from './use-selector'\n\nimport { useStylesheetFactory } from './use-stylesheet-factory'\n\nimport { resolvableRecord } from '../resolvable-record'\nimport { propErrorHandlingProxy } from '../utils/prop-error-handling-proxy'\n\nfunction useControlInstances(elementKey: string): Record<string, ControlInstance> | null {\n const documentKey = useDocumentKey()\n\n return useSelector(state => {\n if (documentKey == null) return null\n\n return ReactPage.getPropControllers(state, documentKey, elementKey)\n })\n}\n\ntype CacheItem = {\n data: Data\n control: ControlInstance | undefined\n resolvedValue: Resolvable<unknown>\n}\n\nexport function useResolvedProps(\n propDefs: Record<string, ControlDefinition>,\n elementData: Record<string, Data>,\n elementKey: string,\n): Record<string, unknown> {\n const stylesheetFactory = useStylesheetFactory()\n const resourceResolver = useResourceResolver()\n const controls = useControlInstances(elementKey)\n\n const cache = useRef<Record<string, CacheItem>>({}).current\n const resolveProp = useCallback(\n (def: ControlDefinition, propName: string) => {\n const data = elementData[propName]\n const control = controls?.[propName]\n\n if (\n cache[propName] != null &&\n data === cache[propName].data &&\n control === cache[propName].control\n ) {\n return cache[propName].resolvedValue\n }\n\n const resolvedValue = def.resolveValue(\n data,\n resourceResolver,\n stylesheetFactory.get(propName),\n control,\n )\n\n cache[propName] = { data, control, resolvedValue }\n return resolvedValue\n },\n [controls, elementData, resourceResolver, stylesheetFactory],\n )\n\n const resolvables = useMemo(\n () =>\n mapValues(propDefs, (def, propName) => {\n const defaultValue = (def.config as any)?.defaultValue\n return propErrorHandlingProxy(resolveProp(def, propName), defaultValue, error => {\n console.warn(\n `Error reading value for prop \"${propName}\", falling back to \\`${defaultValue}\\`.`,\n { control: def, error },\n )\n })\n }),\n [propDefs, resolveProp],\n )\n\n const props = useMemo(() => resolvableRecord(resolvables), [resolvables])\n\n stylesheetFactory.useDefinedStyles()\n\n useEffect(() => {\n props.triggerResolve()\n }, [])\n\n return useSyncExternalStore(props.subscribe, props.readStable, props.readStable)\n}\n"],"mappings":"AAAA,SAAS,SAAS,WAAW,QAAQ,sBAAsB,mBAAmB;AAC9E;AAAA,EAGE;AAAA,OAGK;AAEP,YAAY,eAAe;AAC3B,SAAS,2BAA2B;AACpC,SAAS,sBAAsB;AAC/B,SAAS,mBAAmB;AAE5B,SAAS,4BAA4B;AAErC,SAAS,wBAAwB;AACjC,SAAS,8BAA8B;AAEvC,SAAS,oBAAoB,YAA4D;AACvF,QAAM,cAAc,eAAe;AAEnC,SAAO,YAAY,WAAS;A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AAAA,EACvB,GAAG,CAAC,CAAC;AAEL,SAAO,qBAAqB,MAAM,WAAW,MAAM,YAAY,MAAM,UAAU;AACjF;","names":[]}
1
+ {"version":3,"sources":["../../../../../src/runtimes/react/hooks/use-resolved-props.ts"],"sourcesContent":["import { useMemo, useEffect, useRef, useSyncExternalStore, useCallback } from 'react'\nimport {\n ControlDefinition,\n ControlInstance,\n mapValues,\n type Data,\n type Resolvable,\n} from '@makeswift/controls'\n\nimport * as ReactPage from '../../../state/react-page'\nimport { useResourceResolver } from './use-resource-resolver'\nimport { useDocumentKey } from './use-document-context'\nimport { useSelector } from './use-selector'\n\nimport { useStylesheetFactory } from './use-stylesheet-factory'\n\nimport { resolvableRecord } from '../resolvable-record'\nimport { propErrorHandlingProxy } from '../utils/prop-error-handling-proxy'\n\nfunction useControlInstances(elementKey: string): Record<string, ControlInstance> | null {\n const documentKey = useDocumentKey()\n\n return useSelector(state => {\n if (documentKey == null) return null\n\n return ReactPage.getPropControllers(state, documentKey, elementKey)\n })\n}\n\ntype CacheItem = {\n data: Data\n control: ControlInstance | undefined\n resolvedValue: Resolvable<unknown>\n}\n\nexport function useResolvedProps(\n propDefs: Record<string, ControlDefinition>,\n elementData: Record<string, Data>,\n elementKey: string,\n): Record<string, unknown> {\n const stylesheetFactory = useStylesheetFactory()\n const resourceResolver = useResourceResolver()\n const controls = useControlInstances(elementKey)\n\n const cache = useRef<Record<string, CacheItem>>({}).current\n const resolveProp = useCallback(\n (def: ControlDefinition, propName: string) => {\n const data = elementData[propName]\n const control = controls?.[propName]\n\n if (\n cache[propName] != null &&\n data === cache[propName].data &&\n control === cache[propName].control\n ) {\n return cache[propName].resolvedValue\n }\n\n const resolvedValue = def.resolveValue(\n data,\n resourceResolver,\n stylesheetFactory.get(propName),\n control,\n )\n\n cache[propName] = { data, control, resolvedValue }\n return resolvedValue\n },\n [controls, elementData, resourceResolver, stylesheetFactory],\n )\n\n const resolvables = useMemo(\n () =>\n mapValues(propDefs, (def, propName) => {\n const defaultValue = (def.config as any)?.defaultValue\n return propErrorHandlingProxy(resolveProp(def, propName), defaultValue, error => {\n console.warn(\n `Error reading value for prop \"${propName}\", falling back to \\`${defaultValue}\\`.`,\n { control: def, error },\n )\n })\n }),\n [propDefs, resolveProp],\n )\n\n const props = useMemo(() => resolvableRecord(resolvables), [resolvables])\n\n // no need to call `triggerResolve` on the server, all the resources should already be in\n // the host API client's cache (populated from the snapshot's cache)\n useEffect(() => {\n props.triggerResolve()\n }, [])\n\n // the order is important here, the styles are defined in the process of the props resolution,\n // calling `useDefinedStyles` before the props are resolved would effectively be a noop\n const resolvedProps = useSyncExternalStore(props.subscribe, props.readStable, props.readStable)\n\n stylesheetFactory.useDefinedStyles()\n\n return resolvedProps\n}\n"],"mappings":"AAAA,SAAS,SAAS,WAAW,QAAQ,sBAAsB,mBAAmB;AAC9E;AAAA,EAGE;AAAA,OAGK;AAEP,YAAY,eAAe;AAC3B,SAAS,2BAA2B;AACpC,SAAS,sBAAsB;AAC/B,SAAS,mBAAmB;AAE5B,SAAS,4BAA4B;AAErC,SAAS,wBAAwB;AACjC,SAAS,8BAA8B;AAEvC,SAAS,oBAAoB,YAA4D;AACvF,QAAM,cAAc,eAAe;AAEnC,SAAO,YAAY,WAAS;AAC1B,QAAI,eAAe;AAAM,aAAO;AAEhC,WAAO,UAAU,mBAAmB,OAAO,aAAa,UAAU;AAAA,EACpE,CAAC;AACH;AAQO,SAAS,iBACd,UACA,aACA,YACyB;AACzB,QAAM,oBAAoB,qBAAqB;AAC/C,QAAM,mBAAmB,oBAAoB;AAC7C,QAAM,WAAW,oBAAoB,UAAU;AAE/C,QAAM,QAAQ,OAAkC,CAAC,CAAC,EAAE;AACpD,QAAM,cAAc;AAAA,IAClB,CAAC,KAAwB,aAAqB;AAC5C,YAAM,OAAO,YAAY,QAAQ;AACjC,YAAM,UAAU,WAAW,QAAQ;AAEnC,UACE,MAAM,QAAQ,KAAK,QACnB,SAAS,MAAM,QAAQ,EAAE,QACzB,YAAY,MAAM,QAAQ,EAAE,SAC5B;AACA,eAAO,MAAM,QAAQ,EAAE;AAAA,MACzB;AAEA,YAAM,gBAAgB,IAAI;AAAA,QACxB;AAAA,QACA;AAAA,QACA,kBAAkB,IAAI,QAAQ;AAAA,QAC9B;AAAA,MACF;AAEA,YAAM,QAAQ,IAAI,EAAE,MAAM,SAAS,cAAc;AACjD,aAAO;AAAA,IACT;AAAA,IACA,CAAC,UAAU,aAAa,kBAAkB,iBAAiB;AAAA,EAC7D;AAEA,QAAM,cAAc;AAAA,IAClB,MACE,UAAU,UAAU,CAAC,KAAK,aAAa;AACrC,YAAM,eAAgB,IAAI,QAAgB;AAC1C,aAAO,uBAAuB,YAAY,KAAK,QAAQ,GAAG,cAAc,WAAS;AAC/E,gBAAQ;AAAA,UACN,iCAAiC,QAAQ,wBAAwB,YAAY;AAAA,UAC7E,EAAE,SAAS,KAAK,MAAM;AAAA,QACxB;AAAA,MACF,CAAC;AAAA,IACH,CAAC;AAAA,IACH,CAAC,UAAU,WAAW;AAAA,EACxB;AAEA,QAAM,QAAQ,QAAQ,MAAM,iBAAiB,WAAW,GAAG,CAAC,WAAW,CAAC;AAIxE,YAAU,MAAM;AACd,UAAM,eAAe;AAAA,EACvB,GAAG,CAAC,CAAC;AAIL,QAAM,gBAAgB,qBAAqB,MAAM,WAAW,MAAM,YAAY,MAAM,UAAU;AAE9F,oBAAkB,iBAAiB;AAEnC,SAAO;AACT;","names":[]}
@@ -6,4 +6,4 @@ export {
6
6
  MOBILE_MEDIA_QUERY,
7
7
  TABLET_MEDIA_QUERY
8
8
  };
9
- //# sourceMappingURL=breakpoint-test-util.js.map
9
+ //# sourceMappingURL=breakpoints.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../src/runtimes/react/testing/breakpoints.ts"],"sourcesContent":["export const DESKTOP_MEDIA_QUERY = 'only screen and (min-width: 769px)'\nexport const TABLET_MEDIA_QUERY = 'only screen and (min-width: 769px)'\nexport const MOBILE_MEDIA_QUERY = 'only screen and (min-width: 769px)'\n"],"mappings":"AAAO,MAAM,sBAAsB;AAC5B,MAAM,qBAAqB;AAC3B,MAAM,qBAAqB;","names":[]}
@@ -1,5 +1,6 @@
1
1
  import { randomUUID } from "crypto";
2
- import { MakeswiftComponentType } from "../../components";
2
+ import { CacheData } from "../../../api/react";
3
+ import { MakeswiftComponentType } from "../../../components";
3
4
  function createRootComponent(elements, rootId) {
4
5
  return {
5
6
  key: rootId ?? randomUUID(),
@@ -37,14 +38,38 @@ function createMakeswiftPageSnapshot(elementData, {
37
38
  locale
38
39
  },
39
40
  cacheData: {
40
- apiResources: {},
41
- localizedResourcesMap: {},
41
+ ...CacheData.empty(),
42
+ ...cacheData
43
+ }
44
+ };
45
+ }
46
+ function createMakeswiftComponentSnapshot(elementData, {
47
+ cacheData = {},
48
+ locale = null
49
+ } = {}) {
50
+ return {
51
+ key: randomUUID(),
52
+ document: {
53
+ id: "test-component-id",
54
+ name: "Test Component Document",
55
+ siteId: "test-site-id",
56
+ data: elementData,
57
+ inheritsFromParent: false,
58
+ locale
59
+ },
60
+ meta: {
61
+ allowLocaleFallback: false,
62
+ requestedLocale: locale
63
+ },
64
+ cacheData: {
65
+ ...CacheData.empty(),
42
66
  ...cacheData
43
67
  }
44
68
  };
45
69
  }
46
70
  export {
71
+ createMakeswiftComponentSnapshot,
47
72
  createMakeswiftPageSnapshot,
48
73
  createRootComponent
49
74
  };
50
- //# sourceMappingURL=element-data-test-test.js.map
75
+ //# sourceMappingURL=element-data.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../src/runtimes/react/testing/element-data.ts"],"sourcesContent":["import { randomUUID } from 'crypto'\nimport { type MakeswiftPageSnapshot, type MakeswiftComponentSnapshot } from '../../../next/client'\nimport { type ElementData } from '../../../state/react-page'\nimport { CacheData } from '../../../api/react'\nimport { MakeswiftComponentType } from '../../../components'\n\nexport function createRootComponent(elements: ElementData[], rootId?: string) {\n return {\n key: rootId ?? randomUUID(),\n type: MakeswiftComponentType.Root,\n props: {\n children: {\n columns: [\n {\n deviceId: 'desktop',\n value: {\n count: 12,\n spans: elements?.map(() => [12]),\n },\n },\n ],\n elements,\n },\n },\n }\n}\n\nexport function createMakeswiftPageSnapshot(\n elementData: ElementData,\n {\n cacheData = {},\n locale = null,\n }: { cacheData?: Partial<MakeswiftPageSnapshot['cacheData']>; locale?: string | null } = {},\n): MakeswiftPageSnapshot {\n return {\n document: {\n id: 'test-page-id',\n site: { id: 'test-site-id' },\n data: elementData,\n snippets: [],\n fonts: [],\n meta: {},\n seo: {},\n localizedPages: [],\n locale,\n },\n cacheData: {\n ...CacheData.empty(),\n ...cacheData,\n },\n }\n}\n\nexport function createMakeswiftComponentSnapshot(\n elementData: ElementData,\n {\n cacheData = {},\n locale = null,\n }: { cacheData?: Partial<MakeswiftComponentSnapshot['cacheData']>; locale?: string | null } = {},\n): MakeswiftComponentSnapshot {\n return {\n key: randomUUID(),\n document: {\n id: 'test-component-id',\n name: 'Test Component Document',\n siteId: 'test-site-id',\n data: elementData,\n inheritsFromParent: false,\n locale,\n },\n meta: {\n allowLocaleFallback: false,\n requestedLocale: locale,\n },\n cacheData: {\n ...CacheData.empty(),\n ...cacheData,\n },\n }\n}\n"],"mappings":"AAAA,SAAS,kBAAkB;AAG3B,SAAS,iBAAiB;AAC1B,SAAS,8BAA8B;AAEhC,SAAS,oBAAoB,UAAyB,QAAiB;AAC5E,SAAO;AAAA,IACL,KAAK,UAAU,WAAW;AAAA,IAC1B,MAAM,uBAAuB;AAAA,IAC7B,OAAO;AAAA,MACL,UAAU;AAAA,QACR,SAAS;AAAA,UACP;AAAA,YACE,UAAU;AAAA,YACV,OAAO;AAAA,cACL,OAAO;AAAA,cACP,OAAO,UAAU,IAAI,MAAM,CAAC,EAAE,CAAC;AAAA,YACjC;AAAA,UACF;AAAA,QACF;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;AAEO,SAAS,4BACd,aACA;AAAA,EACE,YAAY,CAAC;AAAA,EACb,SAAS;AACX,IAAyF,CAAC,GACnE;AACvB,SAAO;AAAA,IACL,UAAU;AAAA,MACR,IAAI;AAAA,MACJ,MAAM,EAAE,IAAI,eAAe;AAAA,MAC3B,MAAM;AAAA,MACN,UAAU,CAAC;AAAA,MACX,OAAO,CAAC;AAAA,MACR,MAAM,CAAC;AAAA,MACP,KAAK,CAAC;AAAA,MACN,gBAAgB,CAAC;AAAA,MACjB;AAAA,IACF;AAAA,IACA,WAAW;AAAA,MACT,GAAG,UAAU,MAAM;AAAA,MACnB,GAAG;AAAA,IACL;AAAA,EACF;AACF;AAEO,SAAS,iCACd,aACA;AAAA,EACE,YAAY,CAAC;AAAA,EACb,SAAS;AACX,IAA8F,CAAC,GACnE;AAC5B,SAAO;AAAA,IACL,KAAK,WAAW;AAAA,IAChB,UAAU;AAAA,MACR,IAAI;AAAA,MACJ,MAAM;AAAA,MACN,QAAQ;AAAA,MACR,MAAM;AAAA,MACN,oBAAoB;AAAA,MACpB;AAAA,IACF;AAAA,IACA,MAAM;AAAA,MACJ,qBAAqB;AAAA,MACrB,iBAAiB;AAAA,IACnB;AAAA,IACA,WAAW;AAAA,MACT,GAAG,UAAU,MAAM;AAAA,MACnB,GAAG;AAAA,IACL;AAAA,EACF;AACF;","names":[]}
@@ -0,0 +1,4 @@
1
+ export * from "./breakpoints";
2
+ export * from "./element-data";
3
+ export * from "./react-provider";
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../src/runtimes/react/testing/index.ts"],"sourcesContent":["export * from './breakpoints'\nexport * from './element-data'\nexport * from './react-provider'\n"],"mappings":"AAAA,cAAc;AACd,cAAc;AACd,cAAc;","names":[]}
@@ -0,0 +1,14 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { RootStyleRegistry } from "../../../next";
3
+ import { ReactRuntimeProvider } from "../components/RuntimeProvider";
4
+ function ReactProvider({
5
+ children,
6
+ runtime,
7
+ previewMode = false
8
+ }) {
9
+ return /* @__PURE__ */ jsx(ReactRuntimeProvider, { previewMode, runtime, children: /* @__PURE__ */ jsx(RootStyleRegistry, { children }) });
10
+ }
11
+ export {
12
+ ReactProvider
13
+ };
14
+ //# sourceMappingURL=react-provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../src/runtimes/react/testing/react-provider.tsx"],"sourcesContent":["import { RootStyleRegistry } from '../../../next'\nimport { ReactRuntimeProvider } from '../components/RuntimeProvider'\nimport { ReactRuntime } from '../react-runtime'\n\nexport function ReactProvider({\n children,\n runtime,\n previewMode = false,\n}: {\n children: React.ReactNode\n runtime: ReactRuntime\n previewMode?: boolean\n}) {\n return (\n <ReactRuntimeProvider previewMode={previewMode} runtime={runtime}>\n <RootStyleRegistry>{children}</RootStyleRegistry>\n </ReactRuntimeProvider>\n )\n}\n"],"mappings":"AAeM;AAfN,SAAS,yBAAyB;AAClC,SAAS,4BAA4B;AAG9B,SAAS,cAAc;AAAA,EAC5B;AAAA,EACA;AAAA,EACA,cAAc;AAChB,GAIG;AACD,SACE,oBAAC,wBAAqB,aAA0B,SAC9C,8BAAC,qBAAmB,UAAS,GAC/B;AAEJ;","names":[]}
@@ -2,7 +2,7 @@ import React from "react";
2
2
  import { serializeStyles } from "@emotion/serialize";
3
3
  import { registerStyles, insertStyles } from "@emotion/utils";
4
4
  import { useCache } from "../../next/root-style-registry";
5
- const isServer = typeof window === "undefined";
5
+ import { isServer } from "../../utils/is-server";
6
6
  const useInsertionEffectSpecifier = "useInsertionEffect";
7
7
  const useInsertionEffect = React[useInsertionEffectSpecifier] ?? React.useLayoutEffect;
8
8
  function useStyle(style) {
@@ -22,7 +22,7 @@ function useStyles(cache, styles) {
22
22
  }
23
23
  function useUniversalInsertionEffect(effect) {
24
24
  useInsertionEffect(effect);
25
- if (isServer)
25
+ if (isServer())
26
26
  effect();
27
27
  }
28
28
  function serializedStyleClassName(cache, serialized) {