@makeswift/runtime 0.28.3-canary.3 → 0.28.3-canary.5

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 (157) hide show
  1. package/dist/cjs/api/client.js +2 -4
  2. package/dist/cjs/api/client.js.map +1 -1
  3. package/dist/cjs/api-handler/handlers/manifest.js +1 -1
  4. package/dist/cjs/builder/core/index.js.map +1 -1
  5. package/dist/cjs/client/index.js +15 -18
  6. package/dist/cjs/client/index.js.map +1 -1
  7. package/dist/cjs/components/builtin/Box/Box.js +2 -1
  8. package/dist/cjs/components/builtin/Box/Box.js.map +1 -1
  9. package/dist/cjs/controls/rich-text/control.js.map +1 -1
  10. package/dist/cjs/controls/rich-text-v2/control.js.map +1 -1
  11. package/dist/cjs/next/components/tests/controls/page-control-prop-rendering.js +1 -1
  12. package/dist/cjs/next/components/tests/controls/page-control-prop-rendering.js.map +1 -1
  13. package/dist/cjs/prop-controllers/instances.js.map +1 -1
  14. package/dist/cjs/runtimes/react/components/RuntimeProvider.js +11 -7
  15. package/dist/cjs/runtimes/react/components/RuntimeProvider.js.map +1 -1
  16. package/dist/cjs/runtimes/react/element-imperative-handle.js.map +1 -1
  17. package/dist/cjs/runtimes/react/hooks/use-store.js +9 -2
  18. package/dist/cjs/runtimes/react/hooks/use-store.js.map +1 -1
  19. package/dist/cjs/runtimes/react/hooks/use-stylesheet-factory.js.map +1 -1
  20. package/dist/cjs/runtimes/react/host-api-client.js +2 -2
  21. package/dist/cjs/runtimes/react/host-api-client.js.map +1 -1
  22. package/dist/cjs/runtimes/react/poll-box-model.js.map +1 -1
  23. package/dist/cjs/runtimes/react/react-runtime-core.js +2 -2
  24. package/dist/cjs/runtimes/react/react-runtime-core.js.map +1 -1
  25. package/dist/cjs/runtimes/react/react-runtime.js.map +1 -1
  26. package/dist/cjs/runtimes/react/runtime-core.js +62 -26
  27. package/dist/cjs/runtimes/react/runtime-core.js.map +1 -1
  28. package/dist/cjs/state/actions/internal/read-only-actions.js +1 -15
  29. package/dist/cjs/state/actions/internal/read-only-actions.js.map +1 -1
  30. package/dist/cjs/state/builder-api/actions.js.map +1 -1
  31. package/dist/cjs/state/makeswift-api-client.js +3 -27
  32. package/dist/cjs/state/makeswift-api-client.js.map +1 -1
  33. package/dist/cjs/state/middleware/read-write/builder-api/index.js +8 -2
  34. package/dist/cjs/state/middleware/read-write/builder-api/index.js.map +1 -1
  35. package/dist/cjs/state/middleware/read-write/builder-api/initialize-connection.js +6 -8
  36. package/dist/cjs/state/middleware/read-write/builder-api/initialize-connection.js.map +1 -1
  37. package/dist/cjs/state/modules/locale.js +0 -3
  38. package/dist/cjs/state/modules/locale.js.map +1 -1
  39. package/dist/cjs/state/modules/read-write/box-models.js +17 -2
  40. package/dist/cjs/state/modules/read-write/box-models.js.map +1 -1
  41. package/dist/cjs/state/modules/site-version.js +0 -3
  42. package/dist/cjs/state/modules/site-version.js.map +1 -1
  43. package/dist/cjs/state/read-only-state.js +8 -1
  44. package/dist/cjs/state/read-only-state.js.map +1 -1
  45. package/dist/cjs/state/read-write-state.js.map +1 -1
  46. package/dist/cjs/state/store.js +75 -48
  47. package/dist/cjs/state/store.js.map +1 -1
  48. package/dist/cjs/unstable-framework-support/index.js.map +1 -1
  49. package/dist/cjs/utils/ref-counted-map.js +111 -0
  50. package/dist/cjs/utils/ref-counted-map.js.map +1 -0
  51. package/dist/esm/api/client.js +2 -4
  52. package/dist/esm/api/client.js.map +1 -1
  53. package/dist/esm/api-handler/handlers/manifest.js +1 -1
  54. package/dist/esm/builder/core/index.js.map +1 -1
  55. package/dist/esm/client/index.js +15 -18
  56. package/dist/esm/client/index.js.map +1 -1
  57. package/dist/esm/components/builtin/Box/Box.js +7 -2
  58. package/dist/esm/components/builtin/Box/Box.js.map +1 -1
  59. package/dist/esm/controls/rich-text/control.js.map +1 -1
  60. package/dist/esm/controls/rich-text-v2/control.js.map +1 -1
  61. package/dist/esm/next/components/tests/controls/page-control-prop-rendering.js +1 -1
  62. package/dist/esm/next/components/tests/controls/page-control-prop-rendering.js.map +1 -1
  63. package/dist/esm/prop-controllers/instances.js.map +1 -1
  64. package/dist/esm/runtimes/react/components/RuntimeProvider.js +12 -8
  65. package/dist/esm/runtimes/react/components/RuntimeProvider.js.map +1 -1
  66. package/dist/esm/runtimes/react/element-imperative-handle.js.map +1 -1
  67. package/dist/esm/runtimes/react/hooks/use-store.js +8 -2
  68. package/dist/esm/runtimes/react/hooks/use-store.js.map +1 -1
  69. package/dist/esm/runtimes/react/hooks/use-stylesheet-factory.js.map +1 -1
  70. package/dist/esm/runtimes/react/host-api-client.js +2 -2
  71. package/dist/esm/runtimes/react/host-api-client.js.map +1 -1
  72. package/dist/esm/runtimes/react/poll-box-model.js.map +1 -1
  73. package/dist/esm/runtimes/react/react-runtime-core.js +2 -2
  74. package/dist/esm/runtimes/react/react-runtime-core.js.map +1 -1
  75. package/dist/esm/runtimes/react/react-runtime.js.map +1 -1
  76. package/dist/esm/runtimes/react/runtime-core.js +65 -30
  77. package/dist/esm/runtimes/react/runtime-core.js.map +1 -1
  78. package/dist/esm/state/actions/internal/read-only-actions.js +1 -13
  79. package/dist/esm/state/actions/internal/read-only-actions.js.map +1 -1
  80. package/dist/esm/state/builder-api/actions.js.map +1 -1
  81. package/dist/esm/state/makeswift-api-client.js +4 -28
  82. package/dist/esm/state/makeswift-api-client.js.map +1 -1
  83. package/dist/esm/state/middleware/read-write/builder-api/index.js +8 -2
  84. package/dist/esm/state/middleware/read-write/builder-api/index.js.map +1 -1
  85. package/dist/esm/state/middleware/read-write/builder-api/initialize-connection.js +6 -8
  86. package/dist/esm/state/middleware/read-write/builder-api/initialize-connection.js.map +1 -1
  87. package/dist/esm/state/modules/locale.js +0 -3
  88. package/dist/esm/state/modules/locale.js.map +1 -1
  89. package/dist/esm/state/modules/read-write/box-models.js +16 -2
  90. package/dist/esm/state/modules/read-write/box-models.js.map +1 -1
  91. package/dist/esm/state/modules/site-version.js +0 -3
  92. package/dist/esm/state/modules/site-version.js.map +1 -1
  93. package/dist/esm/state/read-only-state.js +7 -1
  94. package/dist/esm/state/read-only-state.js.map +1 -1
  95. package/dist/esm/state/read-write-state.js.map +1 -1
  96. package/dist/esm/state/store.js +74 -47
  97. package/dist/esm/state/store.js.map +1 -1
  98. package/dist/esm/unstable-framework-support/index.js.map +1 -1
  99. package/dist/esm/utils/ref-counted-map.js +87 -0
  100. package/dist/esm/utils/ref-counted-map.js.map +1 -0
  101. package/dist/types/api/client.d.ts +2 -2
  102. package/dist/types/api/client.d.ts.map +1 -1
  103. package/dist/types/api-handler/handlers/webhook/diff-projection.d.ts +6 -6
  104. package/dist/types/api-handler/handlers/webhook/types.d.ts +20 -20
  105. package/dist/types/builder/core/index.d.ts +1 -1
  106. package/dist/types/builder/core/index.d.ts.map +1 -1
  107. package/dist/types/client/index.d.ts +1 -0
  108. package/dist/types/client/index.d.ts.map +1 -1
  109. package/dist/types/components/builtin/Box/Box.d.ts.map +1 -1
  110. package/dist/types/controls/rich-text/control.d.ts +3 -3
  111. package/dist/types/controls/rich-text/control.d.ts.map +1 -1
  112. package/dist/types/controls/rich-text-v2/control.d.ts +3 -3
  113. package/dist/types/controls/rich-text-v2/control.d.ts.map +1 -1
  114. package/dist/types/prop-controllers/instances.d.ts +5 -6
  115. package/dist/types/prop-controllers/instances.d.ts.map +1 -1
  116. package/dist/types/runtimes/react/components/RuntimeProvider.d.ts.map +1 -1
  117. package/dist/types/runtimes/react/element-imperative-handle.d.ts +2 -3
  118. package/dist/types/runtimes/react/element-imperative-handle.d.ts.map +1 -1
  119. package/dist/types/runtimes/react/hooks/use-store.d.ts +29 -0
  120. package/dist/types/runtimes/react/hooks/use-store.d.ts.map +1 -1
  121. package/dist/types/runtimes/react/poll-box-model.d.ts +2 -2
  122. package/dist/types/runtimes/react/poll-box-model.d.ts.map +1 -1
  123. package/dist/types/runtimes/react/react-runtime.d.ts +1 -0
  124. package/dist/types/runtimes/react/react-runtime.d.ts.map +1 -1
  125. package/dist/types/runtimes/react/runtime-core.d.ts +15 -13
  126. package/dist/types/runtimes/react/runtime-core.d.ts.map +1 -1
  127. package/dist/types/state/__tests__/test-store.d.ts +4 -2
  128. package/dist/types/state/__tests__/test-store.d.ts.map +1 -1
  129. package/dist/types/state/actions/index.d.ts +0 -2
  130. package/dist/types/state/actions/index.d.ts.map +1 -1
  131. package/dist/types/state/actions/internal/index.d.ts +0 -2
  132. package/dist/types/state/actions/internal/index.d.ts.map +1 -1
  133. package/dist/types/state/actions/internal/read-only-actions.d.ts +1 -13
  134. package/dist/types/state/actions/internal/read-only-actions.d.ts.map +1 -1
  135. package/dist/types/state/builder-api/actions.d.ts +3 -3
  136. package/dist/types/state/builder-api/actions.d.ts.map +1 -1
  137. package/dist/types/state/makeswift-api-client.d.ts +2 -2
  138. package/dist/types/state/makeswift-api-client.d.ts.map +1 -1
  139. package/dist/types/state/middleware/read-write/builder-api/index.d.ts.map +1 -1
  140. package/dist/types/state/middleware/read-write/builder-api/initialize-connection.d.ts.map +1 -1
  141. package/dist/types/state/modules/locale.d.ts.map +1 -1
  142. package/dist/types/state/modules/read-write/box-models.d.ts +12 -9
  143. package/dist/types/state/modules/read-write/box-models.d.ts.map +1 -1
  144. package/dist/types/state/modules/site-version.d.ts.map +1 -1
  145. package/dist/types/state/read-only-state.d.ts +6 -2
  146. package/dist/types/state/read-only-state.d.ts.map +1 -1
  147. package/dist/types/state/read-write-state.d.ts +6 -4
  148. package/dist/types/state/read-write-state.d.ts.map +1 -1
  149. package/dist/types/state/store.d.ts +47 -14
  150. package/dist/types/state/store.d.ts.map +1 -1
  151. package/dist/types/unstable-framework-support/index.d.ts +1 -1
  152. package/dist/types/unstable-framework-support/index.d.ts.map +1 -1
  153. package/dist/types/utils/__tests__/ref-counted-map.test.d.ts +2 -0
  154. package/dist/types/utils/__tests__/ref-counted-map.test.d.ts.map +1 -0
  155. package/dist/types/utils/ref-counted-map.d.ts +26 -0
  156. package/dist/types/utils/ref-counted-map.d.ts.map +1 -0
  157. package/package.json +3 -3
@@ -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/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\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 }: {\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 },\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.store.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 <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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;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,SA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,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;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,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 { 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/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\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 }: {\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 },\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 <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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;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,Q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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 +1 @@
1
- {"version":3,"sources":["../../../src/prop-controllers/instances.ts"],"sourcesContent":["import { type Descriptor, isLegacyDescriptor } from './descriptors'\nimport { type BoxModel } from '../state/modules/read-write/box-models'\nimport { Types as PropControllerTypes } from '@makeswift/prop-controllers'\n\nimport {\n type ControlMessage,\n type SendMessage,\n type InstanceType,\n ControlInstance,\n DefaultControlInstance,\n} from '@makeswift/controls'\n\nexport type PropControllerMessage = ControlMessage\n\nexport const TableFormFieldsMessageType = {\n TABLE_FORM_LAYOUT_CHANGE: 'TABLE_FORM_LAYOUT_CHANGE',\n TABLE_FORM_FIELD_LAYOUT_CHANGE: 'TABLE_FORM_FIELD_LAYOUT_CHANGE',\n} as const\n\ntype TableLayoutTableFormFieldsMessage = {\n type: typeof TableFormFieldsMessageType.TABLE_FORM_LAYOUT_CHANGE\n payload: { layout: BoxModel }\n}\n\ntype TableFieldLayoutTableFormFieldsMessage = {\n type: typeof TableFormFieldsMessageType.TABLE_FORM_FIELD_LAYOUT_CHANGE\n payload: { layout: BoxModel; index: number }\n}\n\nexport type TableFormFieldsMessage =\n | TableLayoutTableFormFieldsMessage\n | TableFieldLayoutTableFormFieldsMessage\n\nexport class TableFormFieldsPropController extends ControlInstance<TableFormFieldsMessage> {\n recv = () => {}\n child(_key: string): ControlInstance | undefined {\n return undefined\n }\n\n tableFormLayoutChange(payload: { layout: BoxModel }) {\n this.sendMessage({ type: TableFormFieldsMessageType.TABLE_FORM_LAYOUT_CHANGE, payload })\n }\n\n tableFormFieldLayoutChange(payload: { layout: BoxModel; index: number }) {\n this.sendMessage({ type: TableFormFieldsMessageType.TABLE_FORM_FIELD_LAYOUT_CHANGE, payload })\n }\n}\n\ntype DescriptorPropController<T extends Descriptor> = T extends {\n type: typeof PropControllerTypes.TableFormFields\n}\n ? TableFormFieldsPropController\n : InstanceType<T>\n\nexport type DescriptorsPropControllers<T extends Record<string, Descriptor>> = {\n [K in keyof T]: undefined extends T[K]\n ? DescriptorPropController<Exclude<T[K], undefined>>\n : DescriptorPropController<T[K]>\n}\n\nexport type AnyPropController = ControlInstance<any> | TableFormFieldsPropController\n\nexport function createPropController(\n descriptor: Descriptor,\n send: SendMessage<PropControllerMessage>,\n): AnyPropController {\n if (!isLegacyDescriptor(descriptor)) {\n return descriptor.createInstance(send)\n }\n\n switch (descriptor.type) {\n case PropControllerTypes.TableFormFields:\n return new TableFormFieldsPropController(send as SendMessage<TableFormFieldsMessage>)\n\n default:\n return new DefaultControlInstance(send as SendMessage)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,yBAAoD;AAEpD,8BAA6C;AAE7C,sBAMO;AAIA,MAAM,6BAA6B;AAAA,EACxC,0BAA0B;AAAA,EAC1B,gCAAgC;AAClC;AAgBO,MAAM,sCAAsC,gCAAwC;AAAA,EACzF,OAAO,MAAM;AAAA,EAAC;AAAA,EACd,MAAM,MAA2C;AAC/C,WAAO;AAAA,EACT;AAAA,EAEA,sBAAsB,SAA+B;AACnD,SAAK,YAAY,EAAE,MAAM,2BAA2B,0BAA0B,QAAQ,CAAC;AAAA,EACzF;AAAA,EAEA,2BAA2B,SAA8C;AACvE,SAAK,YAAY,EAAE,MAAM,2BAA2B,gCAAgC,QAAQ,CAAC;AAAA,EAC/F;AACF;AAgBO,SAAS,qBACd,YACA,MACmB;AACnB,MAAI,KAAC,uCAAmB,UAAU,GAAG;AACnC,WAAO,WAAW,eAAe,IAAI;AAAA,EACvC;AAEA,UAAQ,WAAW,MAAM;AAAA,IACvB,KAAK,wBAAAA,MAAoB;AACvB,aAAO,IAAI,8BAA8B,IAA2C;AAAA,IAEtF;AACE,aAAO,IAAI,uCAAuB,IAAmB;AAAA,EACzD;AACF;","names":["PropControllerTypes"]}
1
+ {"version":3,"sources":["../../../src/prop-controllers/instances.ts"],"sourcesContent":["import { type Descriptor, isLegacyDescriptor } from './descriptors'\nimport { Types as PropControllerTypes } from '@makeswift/prop-controllers'\n\nimport {\n type BoxDisplayModel,\n type ControlMessage,\n type SendMessage,\n type InstanceType,\n ControlInstance,\n DefaultControlInstance,\n} from '@makeswift/controls'\n\nexport type PropControllerMessage = ControlMessage\n\nexport const TableFormFieldsMessageType = {\n TABLE_FORM_LAYOUT_CHANGE: 'TABLE_FORM_LAYOUT_CHANGE',\n TABLE_FORM_FIELD_LAYOUT_CHANGE: 'TABLE_FORM_FIELD_LAYOUT_CHANGE',\n} as const\n\ntype TableLayoutTableFormFieldsMessage = {\n type: typeof TableFormFieldsMessageType.TABLE_FORM_LAYOUT_CHANGE\n payload: { layout: BoxDisplayModel }\n}\n\ntype TableFieldLayoutTableFormFieldsMessage = {\n type: typeof TableFormFieldsMessageType.TABLE_FORM_FIELD_LAYOUT_CHANGE\n payload: { layout: BoxDisplayModel; index: number }\n}\n\nexport type TableFormFieldsMessage =\n | TableLayoutTableFormFieldsMessage\n | TableFieldLayoutTableFormFieldsMessage\n\nexport class TableFormFieldsPropController extends ControlInstance<TableFormFieldsMessage> {\n recv = () => {}\n child(_key: string): ControlInstance | undefined {\n return undefined\n }\n\n tableFormLayoutChange(payload: { layout: BoxDisplayModel }) {\n this.sendMessage({ type: TableFormFieldsMessageType.TABLE_FORM_LAYOUT_CHANGE, payload })\n }\n\n tableFormFieldLayoutChange(payload: { layout: BoxDisplayModel; index: number }) {\n this.sendMessage({ type: TableFormFieldsMessageType.TABLE_FORM_FIELD_LAYOUT_CHANGE, payload })\n }\n}\n\ntype DescriptorPropController<T extends Descriptor> = T extends {\n type: typeof PropControllerTypes.TableFormFields\n}\n ? TableFormFieldsPropController\n : InstanceType<T>\n\nexport type DescriptorsPropControllers<T extends Record<string, Descriptor>> = {\n [K in keyof T]: undefined extends T[K]\n ? DescriptorPropController<Exclude<T[K], undefined>>\n : DescriptorPropController<T[K]>\n}\n\nexport type AnyPropController = ControlInstance<any> | TableFormFieldsPropController\n\nexport function createPropController(\n descriptor: Descriptor,\n send: SendMessage<PropControllerMessage>,\n): AnyPropController {\n if (!isLegacyDescriptor(descriptor)) {\n return descriptor.createInstance(send)\n }\n\n switch (descriptor.type) {\n case PropControllerTypes.TableFormFields:\n return new TableFormFieldsPropController(send as SendMessage<TableFormFieldsMessage>)\n\n default:\n return new DefaultControlInstance(send as SendMessage)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,yBAAoD;AACpD,8BAA6C;AAE7C,sBAOO;AAIA,MAAM,6BAA6B;AAAA,EACxC,0BAA0B;AAAA,EAC1B,gCAAgC;AAClC;AAgBO,MAAM,sCAAsC,gCAAwC;AAAA,EACzF,OAAO,MAAM;AAAA,EAAC;AAAA,EACd,MAAM,MAA2C;AAC/C,WAAO;AAAA,EACT;AAAA,EAEA,sBAAsB,SAAsC;AAC1D,SAAK,YAAY,EAAE,MAAM,2BAA2B,0BAA0B,QAAQ,CAAC;AAAA,EACzF;AAAA,EAEA,2BAA2B,SAAqD;AAC9E,SAAK,YAAY,EAAE,MAAM,2BAA2B,gCAAgC,QAAQ,CAAC;AAAA,EAC/F;AACF;AAgBO,SAAS,qBACd,YACA,MACmB;AACnB,MAAI,KAAC,uCAAmB,UAAU,GAAG;AACnC,WAAO,WAAW,eAAe,IAAI;AAAA,EACvC;AAEA,UAAQ,WAAW,MAAM;AAAA,IACvB,KAAK,wBAAAA,MAAoB;AACvB,aAAO,IAAI,8BAA8B,IAA2C;AAAA,IAEtF;AACE,aAAO,IAAI,uCAAuB,IAAmB;AAAA,EACzD;AACF;","names":["PropControllerTypes"]}
@@ -26,6 +26,7 @@ var import_jsx_runtime = require("react/jsx-runtime");
26
26
  var import_react = require("react");
27
27
  var import_use_react_runtime = require("../hooks/use-react-runtime");
28
28
  var import_use_async_effect = require("../hooks/use-async-effect");
29
+ var import_use_store = require("../hooks/use-store");
29
30
  var import_preview_switcher = require("./preview-switcher/preview-switcher");
30
31
  function RuntimeProvider({
31
32
  children,
@@ -35,16 +36,19 @@ function RuntimeProvider({
35
36
  }) {
36
37
  const siteVersion = siteVersionProp ?? null;
37
38
  const isPreview = siteVersion != null;
38
- const isReadOnly = siteVersion == null;
39
- (0, import_react.useMemo)(
40
- () => runtime.setIdempotent({ siteVersion, isReadOnly, locale }),
41
- [runtime, siteVersion, isReadOnly, locale]
39
+ const store = (0, import_react.useMemo)(
40
+ () => runtime.getOrCreateStore({ siteVersion, locale }),
41
+ [runtime, siteVersion, locale]
42
42
  );
43
- (0, import_use_async_effect.useAsyncEffect)(() => runtime.setupStore({ isReadOnly }), [runtime, isReadOnly]);
44
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_use_react_runtime.ReactRuntimeContext.Provider, { value: runtime, children: [
43
+ (0, import_react.useEffect)(() => {
44
+ runtime.retainStore({ siteVersion, locale }, store);
45
+ return () => runtime.releaseStore({ siteVersion, locale }, store);
46
+ }, [runtime, siteVersion, locale, store]);
47
+ (0, import_use_async_effect.useAsyncEffect)(() => store.loadReadWriteStateIfNeeded(), [store]);
48
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_use_react_runtime.ReactRuntimeContext.Provider, { value: runtime, children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_use_store.StoreContext.Provider, { value: store, children: [
45
49
  children,
46
50
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_preview_switcher.PreviewSwitcher, { isPreview })
47
- ] });
51
+ ] }) });
48
52
  }
49
53
  // Annotate the CommonJS export names for ESM import in node:
50
54
  0 && (module.exports = {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/runtimes/react/components/RuntimeProvider.tsx"],"sourcesContent":["'use client'\n\nimport { ReactNode, useMemo } from 'react'\n\nimport { type SiteVersion } from '../../../api/site-version'\n\nimport { ReactRuntimeContext } from '../hooks/use-react-runtime'\nimport { useAsyncEffect } from '../hooks/use-async-effect'\nimport { type ReactRuntimeCore } from '../react-runtime-core'\n\nimport { PreviewSwitcher } from './preview-switcher/preview-switcher'\n\nexport function RuntimeProvider({\n children,\n runtime,\n siteVersion: siteVersionProp,\n locale = undefined,\n}: {\n children: ReactNode\n runtime: ReactRuntimeCore\n siteVersion: SiteVersion | null | undefined\n locale?: string\n}) {\n const siteVersion = siteVersionProp ?? null\n const isPreview = siteVersion != null\n // TODO: we need to decouple editability from the site version; specifically, previewing\n // a draft version of the site should not lead to switching to the read-write state\n const isReadOnly = siteVersion == null\n\n // setting idempotent part of the state on render to have parity between server-side and\n // client-side rendering depending on this state; `useMemo` here is purely a performance\n // optimization; prior art for performing idempotent side effects on render:\n // https://github.com/TanStack/query/blob/8f9f183f11df3709a1a38c4efce1452788041f88/packages/react-query/src/HydrationBoundary.tsx#L41\n useMemo(\n () => runtime.setIdempotent({ siteVersion, isReadOnly, locale }),\n [runtime, siteVersion, isReadOnly, locale],\n )\n\n useAsyncEffect(() => runtime.setupStore({ isReadOnly }), [runtime, isReadOnly])\n\n return (\n <ReactRuntimeContext.Provider value={runtime}>\n {children}\n <PreviewSwitcher isPreview={isPreview} />\n </ReactRuntimeContext.Provider>\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAyCI;AAvCJ,mBAAmC;AAInC,+BAAoC;AACpC,8BAA+B;AAG/B,8BAAgC;AAEzB,SAAS,gBAAgB;AAAA,EAC9B;AAAA,EACA;AAAA,EACA,aAAa;AAAA,EACb,SAAS;AACX,GAKG;AACD,QAAM,cAAc,mBAAmB;AACvC,QAAM,YAAY,eAAe;AAGjC,QAAM,aAAa,eAAe;AAMlC;AAAA,IACE,MAAM,QAAQ,cAAc,EAAE,aAAa,YAAY,OAAO,CAAC;AAAA,IAC/D,CAAC,SAAS,aAAa,YAAY,MAAM;AAAA,EAC3C;AAEA,8CAAe,MAAM,QAAQ,WAAW,EAAE,WAAW,CAAC,GAAG,CAAC,SAAS,UAAU,CAAC;AAE9E,SACE,6CAAC,6CAAoB,UAApB,EAA6B,OAAO,SAClC;AAAA;AAAA,IACD,4CAAC,2CAAgB,WAAsB;AAAA,KACzC;AAEJ;","names":[]}
1
+ {"version":3,"sources":["../../../../../src/runtimes/react/components/RuntimeProvider.tsx"],"sourcesContent":["'use client'\n\nimport { ReactNode, useEffect, useMemo } from 'react'\n\nimport { type SiteVersion } from '../../../api/site-version'\n\nimport { ReactRuntimeContext } from '../hooks/use-react-runtime'\nimport { useAsyncEffect } from '../hooks/use-async-effect'\nimport { StoreContext } from '../hooks/use-store'\nimport { type ReactRuntimeCore } from '../react-runtime-core'\n\nimport { PreviewSwitcher } from './preview-switcher/preview-switcher'\n\nexport function RuntimeProvider({\n children,\n runtime,\n siteVersion: siteVersionProp,\n locale = undefined,\n}: {\n children: ReactNode\n runtime: ReactRuntimeCore\n siteVersion: SiteVersion | null | undefined\n locale?: string\n}) {\n const siteVersion = siteVersionProp ?? null\n const isPreview = siteVersion != null\n\n // see `getOrCreateStore` for the description of the stores' lifecycle\n const store = useMemo(\n () => runtime.getOrCreateStore({ siteVersion, locale }),\n [runtime, siteVersion, locale],\n )\n\n useEffect(() => {\n runtime.retainStore({ siteVersion, locale }, store)\n return () => runtime.releaseStore({ siteVersion, locale }, store)\n }, [runtime, siteVersion, locale, store])\n\n // if we're in the read-write mode, the reducers & middleware required for builder\n // interactions are loaded only on client side, lazily and asynchronously\n useAsyncEffect(() => store.loadReadWriteStateIfNeeded(), [store])\n\n return (\n <ReactRuntimeContext.Provider value={runtime}>\n <StoreContext.Provider value={store}>\n {children}\n <PreviewSwitcher isPreview={isPreview} />\n </StoreContext.Provider>\n </ReactRuntimeContext.Provider>\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA4CM;AA1CN,mBAA8C;AAI9C,+BAAoC;AACpC,8BAA+B;AAC/B,uBAA6B;AAG7B,8BAAgC;AAEzB,SAAS,gBAAgB;AAAA,EAC9B;AAAA,EACA;AAAA,EACA,aAAa;AAAA,EACb,SAAS;AACX,GAKG;AACD,QAAM,cAAc,mBAAmB;AACvC,QAAM,YAAY,eAAe;AAGjC,QAAM,YAAQ;AAAA,IACZ,MAAM,QAAQ,iBAAiB,EAAE,aAAa,OAAO,CAAC;AAAA,IACtD,CAAC,SAAS,aAAa,MAAM;AAAA,EAC/B;AAEA,8BAAU,MAAM;AACd,YAAQ,YAAY,EAAE,aAAa,OAAO,GAAG,KAAK;AAClD,WAAO,MAAM,QAAQ,aAAa,EAAE,aAAa,OAAO,GAAG,KAAK;AAAA,EAClE,GAAG,CAAC,SAAS,aAAa,QAAQ,KAAK,CAAC;AAIxC,8CAAe,MAAM,MAAM,2BAA2B,GAAG,CAAC,KAAK,CAAC;AAEhE,SACE,4CAAC,6CAAoB,UAApB,EAA6B,OAAO,SACnC,uDAAC,8BAAa,UAAb,EAAsB,OAAO,OAC3B;AAAA;AAAA,IACD,4CAAC,2CAAgB,WAAsB;AAAA,KACzC,GACF;AAEJ;","names":[]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/runtimes/react/element-imperative-handle.ts"],"sourcesContent":["import { BoxModel } from '@makeswift/controls'\nimport { BoxModelHandle } from '../../state/modules/read-write/box-models'\nimport { Descriptor } from '../../prop-controllers/descriptors'\nimport { DescriptorsPropControllers } from '../../prop-controllers/instances'\nimport { isMeasurable, measure } from '../../state/modules/read-write/box-models'\nimport {\n isPropControllersHandle,\n PropControllersHandle,\n} from '../../state/modules/prop-controller-handles'\n\nexport class ElementImperativeHandle<\n T extends Record<string, Descriptor> = Record<string, Descriptor>,\n >\n implements BoxModelHandle, PropControllersHandle<T>\n{\n private getCurrent: () => unknown = () => null\n private lastPropControllers: DescriptorsPropControllers<T> | null = null\n\n callback(getCurrent: () => unknown) {\n const current = this.getCurrent()\n\n if (current === null) this.setPropControllers(null)\n\n this.getCurrent = getCurrent\n\n if (this.lastPropControllers !== null) this.setPropControllers(this.lastPropControllers)\n }\n\n getBoxModel(): BoxModel | null {\n const current = this.getCurrent()\n\n return isMeasurable(current) ? measure(current) : null\n }\n\n setPropControllers(propControllers: DescriptorsPropControllers<T> | null): void {\n const current = this.getCurrent()\n\n if (isPropControllersHandle(current)) current.setPropControllers(propControllers)\n\n this.lastPropControllers = propControllers\n }\n\n getDomNode(): Element | null {\n const current = this.getCurrent()\n\n if (isDomNodeHandle(current)) return current.getDomNode()\n\n return current instanceof Element ? current : null\n }\n}\n\ntype DomNodeHandle = {\n getDomNode(): Element | null\n}\n\nexport function isDomNodeHandle(value: unknown): value is DomNodeHandle {\n if (\n typeof value === 'object' &&\n value !== null &&\n 'getDomNode' in value &&\n typeof (value as { getDomNode: unknown }).getDomNode === 'function'\n ) {\n return true\n }\n\n return false\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,IAAAA,qBAAsC;AACtC,qCAGO;AAEA,MAAM,wBAIb;AAAA,EACU,aAA4B,MAAM;AAAA,EAClC,sBAA4D;AAAA,EAEpE,SAAS,YAA2B;AAClC,UAAM,UAAU,KAAK,WAAW;AAEhC,QAAI,YAAY;AAAM,WAAK,mBAAmB,IAAI;AAElD,SAAK,aAAa;AAElB,QAAI,KAAK,wBAAwB;AAAM,WAAK,mBAAmB,KAAK,mBAAmB;AAAA,EACzF;AAAA,EAEA,cAA+B;AAC7B,UAAM,UAAU,KAAK,WAAW;AAEhC,eAAO,iCAAa,OAAO,QAAI,4BAAQ,OAAO,IAAI;AAAA,EACpD;AAAA,EAEA,mBAAmB,iBAA6D;AAC9E,UAAM,UAAU,KAAK,WAAW;AAEhC,YAAI,wDAAwB,OAAO;AAAG,cAAQ,mBAAmB,eAAe;AAEhF,SAAK,sBAAsB;AAAA,EAC7B;AAAA,EAEA,aAA6B;AAC3B,UAAM,UAAU,KAAK,WAAW;AAEhC,QAAI,gBAAgB,OAAO;AAAG,aAAO,QAAQ,WAAW;AAExD,WAAO,mBAAmB,UAAU,UAAU;AAAA,EAChD;AACF;AAMO,SAAS,gBAAgB,OAAwC;AACtE,MACE,OAAO,UAAU,YACjB,UAAU,QACV,gBAAgB,SAChB,OAAQ,MAAkC,eAAe,YACzD;AACA,WAAO;AAAA,EACT;AAEA,SAAO;AACT;","names":["import_box_models"]}
1
+ {"version":3,"sources":["../../../../src/runtimes/react/element-imperative-handle.ts"],"sourcesContent":["import { BoxModelHandle, type BoxDisplayModel } from '../../state/modules/read-write/box-models'\nimport { Descriptor } from '../../prop-controllers/descriptors'\nimport { DescriptorsPropControllers } from '../../prop-controllers/instances'\nimport { isMeasurable, measure } from '../../state/modules/read-write/box-models'\nimport {\n isPropControllersHandle,\n PropControllersHandle,\n} from '../../state/modules/prop-controller-handles'\n\nexport class ElementImperativeHandle<\n T extends Record<string, Descriptor> = Record<string, Descriptor>,\n >\n implements BoxModelHandle, PropControllersHandle<T>\n{\n private getCurrent: () => unknown = () => null\n private lastPropControllers: DescriptorsPropControllers<T> | null = null\n\n callback(getCurrent: () => unknown) {\n const current = this.getCurrent()\n\n if (current === null) this.setPropControllers(null)\n\n this.getCurrent = getCurrent\n\n if (this.lastPropControllers !== null) this.setPropControllers(this.lastPropControllers)\n }\n\n getBoxModel(): BoxDisplayModel | null {\n const current = this.getCurrent()\n\n return isMeasurable(current) ? measure(current) : null\n }\n\n setPropControllers(propControllers: DescriptorsPropControllers<T> | null): void {\n const current = this.getCurrent()\n\n if (isPropControllersHandle(current)) current.setPropControllers(propControllers)\n\n this.lastPropControllers = propControllers\n }\n\n getDomNode(): Element | null {\n const current = this.getCurrent()\n\n if (isDomNodeHandle(current)) return current.getDomNode()\n\n return current instanceof Element ? current : null\n }\n}\n\ntype DomNodeHandle = {\n getDomNode(): Element | null\n}\n\nexport function isDomNodeHandle(value: unknown): value is DomNodeHandle {\n if (\n typeof value === 'object' &&\n value !== null &&\n 'getDomNode' in value &&\n typeof (value as { getDomNode: unknown }).getDomNode === 'function'\n ) {\n return true\n }\n\n return false\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,IAAAA,qBAAsC;AACtC,qCAGO;AAEA,MAAM,wBAIb;AAAA,EACU,aAA4B,MAAM;AAAA,EAClC,sBAA4D;AAAA,EAEpE,SAAS,YAA2B;AAClC,UAAM,UAAU,KAAK,WAAW;AAEhC,QAAI,YAAY;AAAM,WAAK,mBAAmB,IAAI;AAElD,SAAK,aAAa;AAElB,QAAI,KAAK,wBAAwB;AAAM,WAAK,mBAAmB,KAAK,mBAAmB;AAAA,EACzF;AAAA,EAEA,cAAsC;AACpC,UAAM,UAAU,KAAK,WAAW;AAEhC,eAAO,iCAAa,OAAO,QAAI,4BAAQ,OAAO,IAAI;AAAA,EACpD;AAAA,EAEA,mBAAmB,iBAA6D;AAC9E,UAAM,UAAU,KAAK,WAAW;AAEhC,YAAI,wDAAwB,OAAO;AAAG,cAAQ,mBAAmB,eAAe;AAEhF,SAAK,sBAAsB;AAAA,EAC7B;AAAA,EAEA,aAA6B;AAC3B,UAAM,UAAU,KAAK,WAAW;AAEhC,QAAI,gBAAgB,OAAO;AAAG,aAAO,QAAQ,WAAW;AAExD,WAAO,mBAAmB,UAAU,UAAU;AAAA,EAChD;AACF;AAMO,SAAS,gBAAgB,OAAwC;AACtE,MACE,OAAO,UAAU,YACjB,UAAU,QACV,gBAAgB,SAChB,OAAQ,MAAkC,eAAe,YACzD;AACA,WAAO;AAAA,EACT;AAEA,SAAO;AACT;","names":["import_box_models"]}
@@ -19,15 +19,22 @@ var __copyProps = (to, from, except, desc) => {
19
19
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
20
  var use_store_exports = {};
21
21
  __export(use_store_exports, {
22
+ StoreContext: () => StoreContext,
22
23
  useStore: () => useStore
23
24
  });
24
25
  module.exports = __toCommonJS(use_store_exports);
25
- var import_use_react_runtime = require("./use-react-runtime");
26
+ var import_react = require("react");
27
+ const StoreContext = (0, import_react.createContext)(null);
26
28
  function useStore() {
27
- return (0, import_use_react_runtime.useReactRuntime)().store;
29
+ const store = (0, import_react.useContext)(StoreContext);
30
+ if (store == null) {
31
+ throw new Error("`useStore` must be used within a `StoreProvider`");
32
+ }
33
+ return store;
28
34
  }
29
35
  // Annotate the CommonJS export names for ESM import in node:
30
36
  0 && (module.exports = {
37
+ StoreContext,
31
38
  useStore
32
39
  });
33
40
  //# sourceMappingURL=use-store.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/runtimes/react/hooks/use-store.ts"],"sourcesContent":["'use client'\n\nimport { type Store } from '../../../state/store'\nimport { useReactRuntime } from './use-react-runtime'\n\nexport function useStore(): Store {\n return useReactRuntime().store\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,+BAAgC;AAEzB,SAAS,WAAkB;AAChC,aAAO,0CAAgB,EAAE;AAC3B;","names":[]}
1
+ {"version":3,"sources":["../../../../../src/runtimes/react/hooks/use-store.ts"],"sourcesContent":["'use client'\n\nimport { createContext, useContext } from 'react'\nimport { type Store } from '../../../state/store'\n\nexport const StoreContext = createContext<Store | null>(null)\n\nexport function useStore(): Store {\n const store = useContext(StoreContext)\n if (store == null) {\n throw new Error('`useStore` must be used within a `StoreProvider`')\n }\n\n return store\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAA0C;AAGnC,MAAM,mBAAe,4BAA4B,IAAI;AAErD,SAAS,WAAkB;AAChC,QAAM,YAAQ,yBAAW,YAAY;AACrC,MAAI,SAAS,MAAM;AACjB,UAAM,IAAI,MAAM,kDAAkD;AAAA,EACpE;AAEA,SAAO;AACT;","names":[]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/runtimes/react/hooks/use-stylesheet-factory.ts"],"sourcesContent":["import { useMemo, useEffect, useRef } from 'react'\nimport { type CSSObject, serializeStyles } from '@emotion/serialize'\nimport { type EmotionCache } from '@emotion/cache'\nimport { type SerializedStyles } from '@emotion/utils'\n\nimport {\n type Breakpoints,\n type BoxModel,\n type Stylesheet,\n type ResolvedStyle,\n type ResolvedStyleV2,\n type ResolvedTypographyStyle,\n isNotNil,\n getBaseBreakpoint,\n getBreakpointMediaQuery,\n} from '@makeswift/controls'\n\nimport { useCache } from '../root-style-registry'\nimport { styleV1Css } from '../controls/style'\nimport { typographyCss } from '../controls/typography'\n\nimport { useBreakpoints } from './use-breakpoints'\nimport { useCssId } from './use-css-id'\nimport { useStyles, serializedStyleClassName } from '../use-style'\nimport { pollBoxModel } from '../poll-box-model'\n\nexport type StylesheetFactory = {\n get(propName: string): Stylesheet\n useDefinedStyles(): void\n}\n\nexport function useStylesheetFactory(): StylesheetFactory {\n const breakpoints = useBreakpoints()\n const cache = useCache()\n const componentUid = useCssId()\n\n const computedStyles = useRef<Record<string, SerializedStyles>>({}).current\n const boxModelCallbacks = useRef<Record<string, (boxModel: BoxModel | null) => void>>({}).current\n\n return useMemo(() => {\n const getStylesheet = (styleSheetId: string): Stylesheet => ({\n breakpoints(): Breakpoints {\n return breakpoints\n },\n\n defineStyle(\n style: ResolvedStyle,\n onBoxModelChange?: (boxModel: BoxModel | null) => void,\n ): string {\n const serialized = serializeStyle(breakpoints, style, cache)\n const uid = `u-${componentUid}-${styleSheetId}`\n computedStyles[uid] = serialized\n\n const className = serializedStyleClassName(cache, serialized)\n if (!onBoxModelChange) return className\n\n boxModelCallbacks[uid] = onBoxModelChange\n return `${className} ${uid}`\n },\n\n child(id: string): Stylesheet {\n return getStylesheet(`${styleSheetId}-${id}`)\n },\n })\n\n return {\n get(propName: string): Stylesheet {\n return getStylesheet(propName)\n },\n\n useDefinedStyles() {\n useStyles(cache, Object.values(computedStyles))\n\n useEffect(() => {\n const unsubscribes = Object.entries(boxModelCallbacks)\n .map(([uid, callback]) =>\n callback != null\n ? pollBoxModel({\n element: document.querySelector(`.${uid}`),\n onBoxModelChange: callback,\n })\n : undefined,\n )\n .filter(isNotNil)\n\n return () => unsubscribes.forEach(fn => fn())\n }, [Object.keys(boxModelCallbacks).join(' ')])\n },\n }\n }, [breakpoints, cache, componentUid])\n}\n\nfunction isTypographyStyle(style: ResolvedStyle): style is ResolvedTypographyStyle {\n return Array.isArray(style)\n}\n\nfunction isStyleV2(style: ResolvedStyle): style is ResolvedStyleV2 {\n return typeof style === 'object' && 'getStyle' in style && typeof style.getStyle === 'function'\n}\n\nfunction styleV2Css(breakpoints: Breakpoints, style: ResolvedStyleV2<CSSObject>): CSSObject {\n return {\n ...style.getStyle(getBaseBreakpoint(breakpoints)),\n ...breakpoints.reduce(\n (styles, breakpoint) => ({\n ...styles,\n [getBreakpointMediaQuery(breakpoint)]: style.getStyle(breakpoint),\n }),\n {},\n ),\n }\n}\n\nfunction resolvedStyleToCss(breakpoints: Breakpoints, style: ResolvedStyle) {\n if (isTypographyStyle(style)) {\n return typographyCss(breakpoints, style)\n }\n\n if (isStyleV2(style)) {\n return styleV2Css(breakpoints, style as ResolvedStyleV2<CSSObject>)\n }\n\n const { properties, styleData } = style\n return styleV1Css(breakpoints, styleData, properties)\n}\n\nfunction serializeStyle(\n breakpoints: Breakpoints,\n style: ResolvedStyle,\n cache: EmotionCache,\n): SerializedStyles {\n const css = resolvedStyleToCss(breakpoints, style)\n return serializeStyles([css], cache.registered)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA2C;AAC3C,uBAAgD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AAM,GAAG,CAAC;AAAA,QAC9C,GAAG,CAAC,OAAO,KAAK,iBAAiB,EAAE,KAAK,GAAG,CAAC,CAAC;AAAA,MAC/C;AAAA,IACF;AAAA,EACF,GAAG,CAAC,aAAa,OAAO,YAAY,CAAC;AACvC;AAEA,SAAS,kBAAkB,OAAwD;AACjF,SAAO,MAAM,QAAQ,KAAK;AAC5B;AAEA,SAAS,UAAU,OAAgD;AACjE,SAAO,OAAO,UAAU,YAAY,cAAc,SAAS,OAAO,MAAM,aAAa;AACvF;AAEA,SAAS,WAAW,aAA0B,OAA8C;AAC1F,SAAO;AAAA,IACL,GAAG,MAAM,aAAS,mCAAkB,WAAW,CAAC;AAAA,IAChD,GAAG,YAAY;AAAA,MACb,CAAC,QAAQ,gBAAgB;AAAA,QACvB,GAAG;AAAA,QACH,KAAC,yCAAwB,UAAU,CAAC,GAAG,MAAM,SAAS,UAAU;AAAA,MAClE;AAAA,MACA,CAAC;AAAA,IACH;AAAA,EACF;AACF;AAEA,SAAS,mBAAmB,aAA0B,OAAsB;AAC1E,MAAI,kBAAkB,KAAK,GAAG;AAC5B,eAAO,iCAAc,aAAa,KAAK;AAAA,EACzC;AAEA,MAAI,UAAU,KAAK,GAAG;AACpB,WAAO,WAAW,aAAa,KAAmC;AAAA,EACpE;AAEA,QAAM,EAAE,YAAY,UAAU,IAAI;AAClC,aAAO,yBAAW,aAAa,WAAW,UAAU;AACtD;AAEA,SAAS,eACP,aACA,OACA,OACkB;AAClB,QAAM,MAAM,mBAAmB,aAAa,KAAK;AACjD,aAAO,kCAAgB,CAAC,GAAG,GAAG,MAAM,UAAU;AAChD;","names":[]}
1
+ {"version":3,"sources":["../../../../../src/runtimes/react/hooks/use-stylesheet-factory.ts"],"sourcesContent":["import { useMemo, useEffect, useRef } from 'react'\nimport { type CSSObject, serializeStyles } from '@emotion/serialize'\nimport { type EmotionCache } from '@emotion/cache'\nimport { type SerializedStyles } from '@emotion/utils'\n\nimport {\n type BoxDisplayModel,\n type Breakpoints,\n type Stylesheet,\n type ResolvedStyle,\n type ResolvedStyleV2,\n type ResolvedTypographyStyle,\n isNotNil,\n getBaseBreakpoint,\n getBreakpointMediaQuery,\n} from '@makeswift/controls'\n\nimport { useCache } from '../root-style-registry'\nimport { styleV1Css } from '../controls/style'\nimport { typographyCss } from '../controls/typography'\n\nimport { useBreakpoints } from './use-breakpoints'\nimport { useCssId } from './use-css-id'\nimport { useStyles, serializedStyleClassName } from '../use-style'\nimport { pollBoxModel } from '../poll-box-model'\n\nexport type StylesheetFactory = {\n get(propName: string): Stylesheet\n useDefinedStyles(): void\n}\n\nexport function useStylesheetFactory(): StylesheetFactory {\n const breakpoints = useBreakpoints()\n const cache = useCache()\n const componentUid = useCssId()\n\n const computedStyles = useRef<Record<string, SerializedStyles>>({}).current\n const boxModelCallbacks = useRef<Record<string, (boxModel: BoxDisplayModel | null) => void>>({}).current\n\n return useMemo(() => {\n const getStylesheet = (styleSheetId: string): Stylesheet => ({\n breakpoints(): Breakpoints {\n return breakpoints\n },\n\n defineStyle(\n style: ResolvedStyle,\n onBoxModelChange?: (boxModel: BoxDisplayModel | null) => void,\n ): string {\n const serialized = serializeStyle(breakpoints, style, cache)\n const uid = `u-${componentUid}-${styleSheetId}`\n computedStyles[uid] = serialized\n\n const className = serializedStyleClassName(cache, serialized)\n if (!onBoxModelChange) return className\n\n boxModelCallbacks[uid] = onBoxModelChange\n return `${className} ${uid}`\n },\n\n child(id: string): Stylesheet {\n return getStylesheet(`${styleSheetId}-${id}`)\n },\n })\n\n return {\n get(propName: string): Stylesheet {\n return getStylesheet(propName)\n },\n\n useDefinedStyles() {\n useStyles(cache, Object.values(computedStyles))\n\n useEffect(() => {\n const unsubscribes = Object.entries(boxModelCallbacks)\n .map(([uid, callback]) =>\n callback != null\n ? pollBoxModel({\n element: document.querySelector(`.${uid}`),\n onBoxModelChange: callback,\n })\n : undefined,\n )\n .filter(isNotNil)\n\n return () => unsubscribes.forEach(fn => fn())\n }, [Object.keys(boxModelCallbacks).join(' ')])\n },\n }\n }, [breakpoints, cache, componentUid])\n}\n\nfunction isTypographyStyle(style: ResolvedStyle): style is ResolvedTypographyStyle {\n return Array.isArray(style)\n}\n\nfunction isStyleV2(style: ResolvedStyle): style is ResolvedStyleV2 {\n return typeof style === 'object' && 'getStyle' in style && typeof style.getStyle === 'function'\n}\n\nfunction styleV2Css(breakpoints: Breakpoints, style: ResolvedStyleV2<CSSObject>): CSSObject {\n return {\n ...style.getStyle(getBaseBreakpoint(breakpoints)),\n ...breakpoints.reduce(\n (styles, breakpoint) => ({\n ...styles,\n [getBreakpointMediaQuery(breakpoint)]: style.getStyle(breakpoint),\n }),\n {},\n ),\n }\n}\n\nfunction resolvedStyleToCss(breakpoints: Breakpoints, style: ResolvedStyle) {\n if (isTypographyStyle(style)) {\n return typographyCss(breakpoints, style)\n }\n\n if (isStyleV2(style)) {\n return styleV2Css(breakpoints, style as ResolvedStyleV2<CSSObject>)\n }\n\n const { properties, styleData } = style\n return styleV1Css(breakpoints, styleData, properties)\n}\n\nfunction serializeStyle(\n breakpoints: Breakpoints,\n style: ResolvedStyle,\n cache: EmotionCache,\n): SerializedStyles {\n const css = resolvedStyleToCss(breakpoints, style)\n return serializeStyles([css], cache.registered)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA2C;AAC3C,uBAAgD;AAIhD,sBAUO;AAEP,iCAAyB;AACzB,mBAA2B;AAC3B,wBAA8B;AAE9B,6BAA+B;AAC/B,wBAAyB;AACzB,uBAAoD;AACpD,4BAA6B;AAOtB,SAAS,uBAA0C;AACxD,QAAM,kBAAc,uCAAe;AACnC,QAAM,YAAQ,qCAAS;AACvB,QAAM,mBAAe,4BAAS;AAE9B,QAAM,qBAAiB,qBAAyC,CAAC,CAAC,EAAE;AACpE,QAAM,wBAAoB,qBAAmE,CAAC,CAAC,EAAE;AAEjG,aAAO,sBAAQ,MAAM;AACnB,UAAM,gBAAgB,CAAC,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O;AAAA,IACL,GAAG,MAAM,aAAS,mCAAkB,WAAW,CAAC;AAAA,IAChD,GAAG,YAAY;AAAA,MACb,CAAC,QAAQ,gBAAgB;AAAA,QACvB,GAAG;AAAA,QACH,KAAC,yCAAwB,UAAU,CAAC,GAAG,MAAM,SAAS,UAAU;AAAA,MAClE;AAAA,MACA,CAAC;AAAA,IACH;AAAA,EACF;AACF;AAEA,SAAS,mBAAmB,aAA0B,OAAsB;AAC1E,MAAI,kBAAkB,KAAK,GAAG;AAC5B,eAAO,iCAAc,aAAa,KAAK;AAAA,EACzC;AAEA,MAAI,UAAU,KAAK,GAAG;AACpB,WAAO,WAAW,aAAa,KAAmC;AAAA,EACpE;AAEA,QAAM,EAAE,YAAY,UAAU,IAAI;AAClC,aAAO,yBAAW,aAAa,WAAW,UAAU;AACtD;AAEA,SAAS,eACP,aACA,OACA,OACkB;AAClB,QAAM,MAAM,mBAAmB,aAAa,KAAK;AACjD,aAAO,kCAAgB,CAAC,GAAG,GAAG,MAAM,UAAU;AAChD;","names":[]}
@@ -22,9 +22,9 @@ __export(host_api_client_exports, {
22
22
  useMakeswiftHostApiClient: () => useMakeswiftHostApiClient
23
23
  });
24
24
  module.exports = __toCommonJS(host_api_client_exports);
25
- var import_use_react_runtime = require("./hooks/use-react-runtime");
25
+ var import_use_store = require("./hooks/use-store");
26
26
  function useMakeswiftHostApiClient() {
27
- return (0, import_use_react_runtime.useReactRuntime)().hostApiClient;
27
+ return (0, import_use_store.useStore)().hostApiClient;
28
28
  }
29
29
  // Annotate the CommonJS export names for ESM import in node:
30
30
  0 && (module.exports = {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/runtimes/react/host-api-client.tsx"],"sourcesContent":["'use client'\n\nimport { MakeswiftHostApiClient } from '../../api/client'\n\nimport { useReactRuntime } from './hooks/use-react-runtime'\n\nexport function useMakeswiftHostApiClient(): MakeswiftHostApiClient {\n return useReactRuntime().hostApiClient\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,+BAAgC;AAEzB,SAAS,4BAAoD;AAClE,aAAO,0CAAgB,EAAE;AAC3B;","names":[]}
1
+ {"version":3,"sources":["../../../../src/runtimes/react/host-api-client.tsx"],"sourcesContent":["'use client'\n\nimport { MakeswiftHostApiClient } from '../../api/client'\n\nimport { useStore } from './hooks/use-store'\n\nexport function useMakeswiftHostApiClient(): MakeswiftHostApiClient {\n return useStore().hostApiClient\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,uBAAyB;AAElB,SAAS,4BAAoD;AAClE,aAAO,2BAAS,EAAE;AACpB;","names":[]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/runtimes/react/poll-box-model.ts"],"sourcesContent":["import { BoxModel, getBox } from '../../state/modules/read-write/box-models'\nimport deepEqual from '../../utils/deepEqual'\n\nexport function pollBoxModel({\n element,\n onBoxModelChange,\n}: {\n element: Element | null\n onBoxModelChange(boxModel: BoxModel | null): void\n}): () => void {\n let currentBoxModel: BoxModel | null = null\n\n const handleAnimationFrameRequest = () => {\n const measuredBoxModel = element == null ? null : getBox(element)\n\n if (!deepEqual(currentBoxModel, measuredBoxModel)) {\n currentBoxModel = measuredBoxModel\n\n onBoxModelChange(currentBoxModel)\n }\n\n animationFrameHandle = requestAnimationFrame(handleAnimationFrameRequest)\n }\n\n let animationFrameHandle = requestAnimationFrame(handleAnimationFrameRequest)\n\n return () => {\n cancelAnimationFrame(animationFrameHandle)\n\n onBoxModelChange(null)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAAiC;AACjC,uBAAsB;AAEf,SAAS,aAAa;AAAA,EAC3B;AAAA,EACA;AACF,GAGe;AACb,MAAI,kBAAmC;AAEvC,QAAM,8BAA8B,MAAM;AACxC,UAAM,mBAAmB,WAAW,OAAO,WAAO,0BAAO,OAAO;AAEhE,QAAI,KAAC,iBAAAA,SAAU,iBAAiB,gBAAgB,GAAG;AACjD,wBAAkB;AAElB,uBAAiB,eAAe;AAAA,IAClC;AAEA,2BAAuB,sBAAsB,2BAA2B;AAAA,EAC1E;AAEA,MAAI,uBAAuB,sBAAsB,2BAA2B;AAE5E,SAAO,MAAM;AACX,yBAAqB,oBAAoB;AAEzC,qBAAiB,IAAI;AAAA,EACvB;AACF;","names":["deepEqual"]}
1
+ {"version":3,"sources":["../../../../src/runtimes/react/poll-box-model.ts"],"sourcesContent":["import { BoxDisplayModel, getBox } from '../../state/modules/read-write/box-models'\nimport deepEqual from '../../utils/deepEqual'\n\nexport function pollBoxModel({\n element,\n onBoxModelChange,\n}: {\n element: Element | null\n onBoxModelChange(boxModel: BoxDisplayModel | null): void\n}): () => void {\n let currentBoxModel: BoxDisplayModel | null = null\n\n const handleAnimationFrameRequest = () => {\n const measuredBoxModel = element == null ? null : getBox(element)\n\n if (!deepEqual(currentBoxModel, measuredBoxModel)) {\n currentBoxModel = measuredBoxModel\n\n onBoxModelChange(currentBoxModel)\n }\n\n animationFrameHandle = requestAnimationFrame(handleAnimationFrameRequest)\n }\n\n let animationFrameHandle = requestAnimationFrame(handleAnimationFrameRequest)\n\n return () => {\n cancelAnimationFrame(animationFrameHandle)\n\n onBoxModelChange(null)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAAwC;AACxC,uBAAsB;AAEf,SAAS,aAAa;AAAA,EAC3B;AAAA,EACA;AACF,GAGe;AACb,MAAI,kBAA0C;AAE9C,QAAM,8BAA8B,MAAM;AACxC,UAAM,mBAAmB,WAAW,OAAO,WAAO,0BAAO,OAAO;AAEhE,QAAI,KAAC,iBAAAA,SAAU,iBAAiB,gBAAgB,GAAG;AACjD,wBAAkB;AAElB,uBAAiB,eAAe;AAAA,IAClC;AAEA,2BAAuB,sBAAsB,2BAA2B;AAAA,EAC1E;AAEA,MAAI,uBAAuB,sBAAsB,2BAA2B;AAE5E,SAAO,MAAM;AACX,yBAAqB,oBAAoB;AAEzC,qBAAiB,IAAI;AAAA,EACvB;AACF;","names":["deepEqual"]}
@@ -44,7 +44,7 @@ class ReactRuntimeCore extends import_runtime_core.RuntimeCore {
44
44
  props
45
45
  }) {
46
46
  validateComponentType(type, component);
47
- const unregisterComponent = this.store.dispatch(
47
+ const unregisterComponent = this.protoStore.dispatch(
48
48
  (0, import_read_only_actions.registerComponentEffect)(
49
49
  type,
50
50
  { label, icon, hidden, description, builtinSuspense },
@@ -56,7 +56,7 @@ class ReactRuntimeCore extends import_runtime_core.RuntimeCore {
56
56
  "builtinSuspense is ignored in React >= 19.2; components are always wrapped in <Activity>."
57
57
  );
58
58
  }
59
- const unregisterReactComponent = this.store.dispatch(
59
+ const unregisterReactComponent = this.protoStore.dispatch(
60
60
  (0, import_read_only_actions.registerReactComponentEffect)(type, component)
61
61
  );
62
62
  return () => {
@@ -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(type: string, component?: ComponentType): void {\n const componentName = component?.name ?? 'Component'\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 C extends ComponentType<{ [K in keyof P]: DescriptorValueType<P[K]> }>,\n >(\n component: C,\n {\n type,\n label,\n icon = ComponentIcon.Cube,\n hidden = false,\n description,\n builtinSuspense,\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 props?: P\n },\n ): () => void {\n validateComponentType(type, component as unknown as ComponentType)\n\n const unregisterComponent = this.store.dispatch(\n registerComponentEffect(\n type,\n { label, icon, hidden, description, builtinSuspense },\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 const unregisterReactComponent = this.store.dispatch(\n registerReactComponentEffect(type, component as unknown as ComponentType),\n )\n\n return () => {\n unregisterComponent()\n unregisterReactComponent()\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,oCAAiC;AAEjC,+BAGO;AAEP,6BAA8B;AAG9B,0BAA4B;AAE5B,SAAS,sBAAsB,MAAc,WAAiC;AAC5E,QAAM,gBAAgB,WAAW,QAAQ;AACzC,MAAI,OAAO,SAAS,YAAY,SAAS,IAAI;AAC3C,UAAM,IAAI;AAAA,MACR,GAAG,aAAa,6EAA6E,IAAI;AAAA,IACnG;AAAA,EACF;AACF;AAEO,MAAM,yBAAyB,gCAAY;AAAA,EAChD,kBAKE,WACA;AAAA,IACE;AAAA,IACA;AAAA,IACA,OAAO,qCAAc;AAAA,IACrB,SAAS;AAAA,IACT;AAAA,IACA;AAAA,IACA;AAAA,EACF,GAcY;AACZ,0BAAsB,MAAM,SAAqC;AAEjE,UAAM,sBAAsB,KAAK,MAAM;AAAA,UACrC;AAAA,QACE;AAAA,QACA,EAAE,OAAO,MAAM,QAAQ,aAAa,gBAAgB;AAAA,QACpD,SAAS,CAAC;AAAA,MACZ;AAAA,IACF;AAEA,YAAI,gDAAiB,KAAK,oBAAoB,QAAW;AACvD,cAAQ;AAAA,QACN;AAAA,MACF;AAAA,IACF;AAEA,UAAM,2BAA2B,KAAK,MAAM;AAAA,UAC1C,uDAA6B,MAAM,SAAqC;AAAA,IAC1E;AAEA,WAAO,MAAM;AACX,0BAAoB;AACpB,+BAAyB;AAAA,IAC3B;AAAA,EACF;AACF;","names":[]}
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(type: string, component?: ComponentType): void {\n const componentName = component?.name ?? 'Component'\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 C extends ComponentType<{ [K in keyof P]: DescriptorValueType<P[K]> }>,\n >(\n component: C,\n {\n type,\n label,\n icon = ComponentIcon.Cube,\n hidden = false,\n description,\n builtinSuspense,\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 props?: P\n },\n ): () => void {\n validateComponentType(type, component as unknown as ComponentType)\n\n const unregisterComponent = this.protoStore.dispatch(\n registerComponentEffect(\n type,\n { label, icon, hidden, description, builtinSuspense },\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 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"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,oCAAiC;AAEjC,+BAGO;AAEP,6BAA8B;AAG9B,0BAA4B;AAE5B,SAAS,sBAAsB,MAAc,WAAiC;AAC5E,QAAM,gBAAgB,WAAW,QAAQ;AACzC,MAAI,OAAO,SAAS,YAAY,SAAS,IAAI;AAC3C,UAAM,IAAI;AAAA,MACR,GAAG,aAAa,6EAA6E,IAAI;AAAA,IACnG;AAAA,EACF;AACF;AAEO,MAAM,yBAAyB,gCAAY;AAAA,EAChD,kBAKE,WACA;AAAA,IACE;AAAA,IACA;AAAA,IACA,OAAO,qCAAc;AAAA,IACrB,SAAS;AAAA,IACT;AAAA,IACA;AAAA,IACA;AAAA,EACF,GAcY;AACZ,0BAAsB,MAAM,SAAqC;AAEjE,UAAM,sBAAsB,KAAK,WAAW;AAAA,UAC1C;AAAA,QACE;AAAA,QACA,EAAE,OAAO,MAAM,QAAQ,aAAa,gBAAgB;AAAA,QACpD,SAAS,CAAC;AAAA,MACZ;AAAA,IACF;AAEA,YAAI,gDAAiB,KAAK,oBAAoB,QAAW;AACvD,cAAQ;AAAA,QACN;AAAA,MACF;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;AACF;","names":[]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/runtimes/react/react-runtime.ts"],"sourcesContent":["import { registerBuiltinComponents } from '../../components/builtin/register'\nimport { ReactRuntimeCore } from './react-runtime-core'\n\nexport class ReactRuntime extends ReactRuntimeCore {\n constructor(...args: ConstructorParameters<typeof ReactRuntimeCore>) {\n super(...args)\n registerBuiltinComponents(this)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAA0C;AAC1C,gCAAiC;AAE1B,MAAM,qBAAqB,2CAAiB;AAAA,EACjD,eAAe,MAAsD;AACnE,UAAM,GAAG,IAAI;AACb,mDAA0B,IAAI;AAAA,EAChC;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../../src/runtimes/react/react-runtime.ts"],"sourcesContent":["import { registerBuiltinComponents } from '../../components/builtin/register'\nimport { ReactRuntimeCore } from './react-runtime-core'\n\nexport { type StoreKey } from './runtime-core'\n\nexport class ReactRuntime extends ReactRuntimeCore {\n constructor(...args: ConstructorParameters<typeof ReactRuntimeCore>) {\n super(...args)\n registerBuiltinComponents(this)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAA0C;AAC1C,gCAAiC;AAI1B,MAAM,qBAAqB,2CAAiB;AAAA,EACjD,eAAe,MAAsD;AACnE,UAAM,GAAG,IAAI;AACb,mDAA0B,IAAI;AAAA,EAChC;AACF;","names":[]}
@@ -26,53 +26,89 @@ var import_breakpoints = require("../../state/modules/breakpoints");
26
26
  var import_copy_element_tree = require("../../state/ops/copy-element-tree");
27
27
  var import_read_only_state = require("../../state/read-only-state");
28
28
  var import_store = require("../../state/store");
29
- var import_builder = require("../../builder");
30
- var import_read_only_actions = require("../../state/actions/internal/read-only-actions");
29
+ var import_ref_counted_map = require("../../utils/ref-counted-map");
30
+ var import_is_server = require("../../utils/is-server");
31
+ const VERSION_TAG_LIVE = "ref:live";
31
32
  class RuntimeCore {
32
- store;
33
- hostApiClient;
33
+ // The unowned entry TTL affects performance, not correctness. The TTL controls how long an unretained store stays
34
+ // in the map. If an entry expires and is removed from the map before React commits, the store remains retained
35
+ // via `<StoreContext.Provider>`. The only impact is that future lookups will create a new store instance instead of
36
+ // reusing the existing one, reducing cache efficiency.
37
+ activeStores = new import_ref_counted_map.RefCountedMap({
38
+ unownedEntryTtlMs: 1e3,
39
+ // Checking on retain/release is sufficient on the client, and we don't need to check on get on the server
40
+ // as the only scenario in which we add the store to the map is when the runtime is already bound to the
41
+ // requested site version, which should be the only site version for which the store is requested
42
+ ttlCheck: import_ref_counted_map.RefCountedMap.TTLCheck.ON_RETAIN | import_ref_counted_map.RefCountedMap.TTLCheck.ON_RELEASE
43
+ });
44
+ protoStore;
34
45
  appOrigin;
35
46
  apiOrigin;
47
+ requestKey;
48
+ fetch;
36
49
  constructor({
37
50
  appOrigin = "https://app.makeswift.com",
38
51
  apiOrigin = "https://api.makeswift.com",
39
52
  breakpoints,
53
+ requestKey,
40
54
  fetch
41
55
  }) {
42
56
  this.appOrigin = validateOrigin(appOrigin, "appOrigin");
43
57
  this.apiOrigin = validateOrigin(apiOrigin, "apiOrigin");
44
- this.hostApiClient = new import_client.MakeswiftHostApiClient({
45
- uri: new URL("graphql", this.apiOrigin).href,
46
- fetch
47
- });
48
- this.store = (0, import_store.configureStore)({
49
- name: "Runtime store",
50
- hostApiClient: this.hostApiClient,
51
- appOrigin: this.appOrigin,
52
- preloadedState: null,
58
+ this.requestKey = requestKey;
59
+ this.fetch = fetch;
60
+ this.protoStore = (0, import_store.configureProtoStore)({
61
+ name: "Runtime proto-store",
53
62
  breakpoints: breakpoints ? (0, import_breakpoints.parseBreakpointsInput)(breakpoints) : void 0
54
63
  });
55
64
  }
56
- setIdempotent({
57
- siteVersion,
58
- isReadOnly,
59
- locale
60
- }) {
61
- this.store.dispatch((0, import_read_only_actions.setSiteVersion)(siteVersion));
62
- this.store.dispatch((0, import_read_only_actions.setIsReadOnly)(isReadOnly));
63
- this.store.dispatch(locale != null ? (0, import_builder.setLocale)(new Intl.Locale(locale)) : (0, import_read_only_actions.resetLocaleState)());
65
+ getOrCreateStore({ siteVersion, locale }) {
66
+ const key = storeCacheKey({ siteVersion, locale });
67
+ const createStore = () => {
68
+ const hostApiClient = new import_client.MakeswiftHostApiClient({
69
+ uri: new URL("graphql", this.apiOrigin).href,
70
+ fetch: this.fetch,
71
+ preloadedState: { siteVersion, locale }
72
+ });
73
+ const isReadOnly = siteVersion == null;
74
+ return (0, import_store.configureReadWriteStore)({
75
+ name: `Runtime read-write store (site version: ${key})`,
76
+ appOrigin: this.appOrigin,
77
+ hostApiClient,
78
+ preloadedState: { ...this.protoStore.getState(), siteVersion, isReadOnly, locale }
79
+ });
80
+ };
81
+ const usePersistentStore = this.shouldUsePersistentStore(key);
82
+ return usePersistentStore ? this.activeStores.getOrCreate(key, createStore) : createStore();
64
83
  }
65
- async setupStore({ isReadOnly }) {
66
- const unloadReadWriteState = await this.store.loadReadWriteState({ isReadOnly });
67
- return () => unloadReadWriteState();
84
+ retainStore({ siteVersion, locale }, store) {
85
+ const key = storeCacheKey({ siteVersion, locale });
86
+ if (!this.shouldUsePersistentStore(key)) {
87
+ console.error("RuntimeCore: attempt to retain an ephemeral store", { key });
88
+ return;
89
+ }
90
+ this.activeStores.retain(key, store);
91
+ }
92
+ releaseStore({ siteVersion, locale }, store) {
93
+ const key = storeCacheKey({ siteVersion, locale });
94
+ if (!this.shouldUsePersistentStore(key)) {
95
+ console.error("RuntimeCore: attempt to release an ephemeral store", { key });
96
+ return;
97
+ }
98
+ this.activeStores.release(key, store);
68
99
  }
69
100
  copyElementTree(elementTree, replacementContext) {
70
- return (0, import_copy_element_tree.copyElementTree)(this.store.getState(), elementTree, replacementContext);
101
+ return (0, import_copy_element_tree.copyElementTree)(this.protoStore.getState(), elementTree, replacementContext);
71
102
  }
72
103
  getBreakpoints() {
73
- return (0, import_read_only_state.getBreakpoints)(this.store.getState());
104
+ return (0, import_read_only_state.getBreakpoints)(this.protoStore.getState());
105
+ }
106
+ shouldUsePersistentStore(key) {
107
+ return !(0, import_is_server.isServer)() || this.requestKey !== void 0 && storeCacheKey(this.requestKey) === key;
74
108
  }
75
109
  }
110
+ const storeCacheKey = ({ siteVersion, locale }) => `${siteVersionTag(siteVersion)}/${locale ?? "default"}`;
111
+ const siteVersionTag = (siteVersion) => siteVersion?.version ?? VERSION_TAG_LIVE;
76
112
  function validateOrigin(url, name) {
77
113
  try {
78
114
  return new URL(url).origin;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/runtimes/react/runtime-core.ts"],"sourcesContent":["import { type SerializableReplacementContext } from '@makeswift/controls'\n\nimport { MakeswiftHostApiClient } from '../../api/client'\nimport * as MakeswiftApiClient from '../../state/makeswift-api-client'\nimport { type SiteVersion } from '../../api/site-version'\n\nimport {\n Breakpoints,\n BreakpointsInput,\n parseBreakpointsInput,\n} from '../../state/modules/breakpoints'\n\nimport { copyElementTree } from '../../state/ops/copy-element-tree'\n\nimport { getBreakpoints, type Element, type ElementData } from '../../state/read-only-state'\nimport { configureStore, type Store } from '../../state/store'\nimport { setLocale } from '../../builder'\nimport {\n resetLocaleState,\n setIsReadOnly,\n setSiteVersion,\n} from '../../state/actions/internal/read-only-actions'\n\nexport class RuntimeCore {\n readonly store: Store\n readonly hostApiClient: MakeswiftHostApiClient\n readonly appOrigin: string\n readonly apiOrigin: string\n\n constructor({\n appOrigin = 'https://app.makeswift.com',\n apiOrigin = 'https://api.makeswift.com',\n breakpoints,\n fetch,\n }: {\n appOrigin?: string\n apiOrigin?: string\n breakpoints?: BreakpointsInput\n fetch: MakeswiftApiClient.HttpFetch\n }) {\n this.appOrigin = validateOrigin(appOrigin, 'appOrigin')\n this.apiOrigin = validateOrigin(apiOrigin, 'apiOrigin')\n\n this.hostApiClient = new MakeswiftHostApiClient({\n uri: new URL('graphql', this.apiOrigin).href,\n fetch: fetch,\n })\n\n this.store = configureStore({\n name: 'Runtime store',\n hostApiClient: this.hostApiClient,\n appOrigin: this.appOrigin,\n preloadedState: null,\n breakpoints: breakpoints ? parseBreakpointsInput(breakpoints) : undefined,\n })\n }\n\n setIdempotent({\n siteVersion,\n isReadOnly,\n locale,\n }: {\n siteVersion: SiteVersion | null\n isReadOnly: boolean\n locale: string | undefined\n }): void {\n this.store.dispatch(setSiteVersion(siteVersion))\n this.store.dispatch(setIsReadOnly(isReadOnly))\n this.store.dispatch(locale != null ? setLocale(new Intl.Locale(locale)) : resetLocaleState())\n }\n\n async setupStore({ isReadOnly }: { isReadOnly: boolean }): Promise<() => void> {\n const unloadReadWriteState = await this.store.loadReadWriteState({ isReadOnly })\n return () => unloadReadWriteState()\n }\n\n copyElementTree(\n elementTree: ElementData,\n replacementContext: SerializableReplacementContext,\n ): Element {\n return copyElementTree(this.store.getState(), elementTree, replacementContext)\n }\n\n getBreakpoints(): Breakpoints {\n return getBreakpoints(this.store.getState())\n }\n}\n\nfunction validateOrigin(url: string, name: string): string {\n try {\n return new URL(url).origin\n } catch {\n throw new Error(`The Makeswift runtime received an invalid \\`${name}\\` parameter: \"${url}\".`)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,oBAAuC;AAIvC,yBAIO;AAEP,+BAAgC;AAEhC,6BAA+D;AAC/D,mBAA2C;AAC3C,qBAA0B;AAC1B,+BAIO;AAEA,MAAM,YAAY;AAAA,EACd;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAET,YAAY;AAAA,IACV,YAAY;AAAA,IACZ,YAAY;AAAA,IACZ;AAAA,IACA;AAAA,EACF,GAKG;AACD,SAAK,YAAY,eAAe,WAAW,WAAW;AACtD,SAAK,YAAY,eAAe,WAAW,WAAW;AAEtD,SAAK,gBAAgB,IAAI,qCAAuB;AAAA,MAC9C,KAAK,IAAI,IAAI,WAAW,KAAK,SAAS,EAAE;AAAA,MACxC;AAAA,IACF,CAAC;AAED,SAAK,YAAQ,6BAAe;AAAA,MAC1B,MAAM;AAAA,MACN,eAAe,KAAK;AAAA,MACpB,WAAW,KAAK;AAAA,MAChB,gBAAgB;AAAA,MAChB,aAAa,kBAAc,0CAAsB,WAAW,IAAI;AAAA,IAClE,CAAC;AAAA,EACH;AAAA,EAEA,cAAc;AAAA,IACZ;AAAA,IACA;AAAA,IACA;AAAA,EACF,GAIS;AACP,SAAK,MAAM,aAAS,yCAAe,WAAW,CAAC;AAC/C,SAAK,MAAM,aAAS,wCAAc,UAAU,CAAC;AAC7C,SAAK,MAAM,SAAS,UAAU,WAAO,0BAAU,IAAI,KAAK,OAAO,MAAM,CAAC,QAAI,2CAAiB,CAAC;AAAA,EAC9F;AAAA,EAEA,MAAM,WAAW,EAAE,WAAW,GAAiD;AAC7E,UAAM,uBAAuB,MAAM,KAAK,MAAM,mBAAmB,EAAE,WAAW,CAAC;AAC/E,WAAO,MAAM,qBAAqB;AAAA,EACpC;AAAA,EAEA,gBACE,aACA,oBACS;AACT,eAAO,0CAAgB,KAAK,MAAM,SAAS,GAAG,aAAa,kBAAkB;AAAA,EAC/E;AAAA,EAEA,iBAA8B;AAC5B,eAAO,uCAAe,KAAK,MAAM,SAAS,CAAC;AAAA,EAC7C;AACF;AAEA,SAAS,eAAe,KAAa,MAAsB;AACzD,MAAI;AACF,WAAO,IAAI,IAAI,GAAG,EAAE;AAAA,EACtB,QAAQ;AACN,UAAM,IAAI,MAAM,+CAA+C,IAAI,kBAAkB,GAAG,IAAI;AAAA,EAC9F;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../../src/runtimes/react/runtime-core.ts"],"sourcesContent":["import { type SerializableReplacementContext } from '@makeswift/controls'\n\nimport { MakeswiftHostApiClient } from '../../api/client'\nimport * as MakeswiftApiClient from '../../state/makeswift-api-client'\nimport { type SiteVersion } from '../../api/site-version'\n\nimport {\n Breakpoints,\n BreakpointsInput,\n parseBreakpointsInput,\n} from '../../state/modules/breakpoints'\n\nimport { copyElementTree } from '../../state/ops/copy-element-tree'\n\nimport { getBreakpoints, type Element, type ElementData } from '../../state/read-only-state'\nimport {\n configureProtoStore,\n configureReadWriteStore,\n type ProtoStore,\n type Store,\n} from '../../state/store'\n\nimport { RefCountedMap } from '../../utils/ref-counted-map'\nimport { isServer } from '../../utils/is-server'\n\nexport type StoreKey = {\n siteVersion: SiteVersion | null\n locale: string | undefined\n}\n\nconst VERSION_TAG_LIVE = 'ref:live'\n\nexport class RuntimeCore {\n // The unowned entry TTL affects performance, not correctness. The TTL controls how long an unretained store stays\n // in the map. If an entry expires and is removed from the map before React commits, the store remains retained\n // via `<StoreContext.Provider>`. The only impact is that future lookups will create a new store instance instead of\n // reusing the existing one, reducing cache efficiency.\n private readonly activeStores = new RefCountedMap<string | null, Store>({\n unownedEntryTtlMs: 1000,\n // Checking on retain/release is sufficient on the client, and we don't need to check on get on the server\n // as the only scenario in which we add the store to the map is when the runtime is already bound to the\n // requested site version, which should be the only site version for which the store is requested\n ttlCheck: RefCountedMap.TTLCheck.ON_RETAIN | RefCountedMap.TTLCheck.ON_RELEASE,\n })\n\n readonly protoStore: ProtoStore\n readonly appOrigin: string\n readonly apiOrigin: string\n readonly requestKey: StoreKey | undefined\n readonly fetch: MakeswiftApiClient.HttpFetch\n\n constructor({\n appOrigin = 'https://app.makeswift.com',\n apiOrigin = 'https://api.makeswift.com',\n breakpoints,\n requestKey,\n fetch,\n }: {\n appOrigin?: string\n apiOrigin?: string\n breakpoints?: BreakpointsInput\n requestKey?: StoreKey\n fetch: MakeswiftApiClient.HttpFetch\n }) {\n this.appOrigin = validateOrigin(appOrigin, 'appOrigin')\n this.apiOrigin = validateOrigin(apiOrigin, 'apiOrigin')\n this.requestKey = requestKey\n this.fetch = fetch\n\n this.protoStore = configureProtoStore({\n name: 'Runtime proto-store',\n breakpoints: breakpoints ? parseBreakpointsInput(breakpoints) : undefined,\n })\n }\n\n getOrCreateStore({ siteVersion, locale }: StoreKey): Store {\n const key = storeCacheKey({ siteVersion, locale })\n\n const createStore = () => {\n // host API client includes an in-memory cache of the site's resources and thus also has to be versioned\n const hostApiClient = new MakeswiftHostApiClient({\n uri: new URL('graphql', this.apiOrigin).href,\n fetch: this.fetch,\n preloadedState: { siteVersion, locale },\n })\n\n // TODO: we need to decouple editability from the site version; specifically, previewing\n // a draft version of the site should not lead to switching to the read-write state\n const isReadOnly = siteVersion == null\n\n return configureReadWriteStore({\n name: `Runtime read-write store (site version: ${key})`,\n appOrigin: this.appOrigin,\n hostApiClient,\n preloadedState: { ...this.protoStore.getState(), siteVersion, isReadOnly, locale },\n })\n }\n\n // On the server, stores are ephemeral by default so SSR does not retain them in a long-lived runtime.\n // The exception is a runtime that is already bound to the requested site version & locale, where we\n // can safely reuse the store across multiple root regions and benefit from the host API client's\n // in-memory cache.\n //\n // On the client, stores are reference-counted by site version so multiple root regions can share a store\n // instance, which preserves the pre-v0.17 per-site-version store behavior without requiring a separate\n // runtime per root.\n const usePersistentStore = this.shouldUsePersistentStore(key)\n return usePersistentStore ? this.activeStores.getOrCreate(key, createStore) : createStore()\n }\n\n retainStore({ siteVersion, locale }: StoreKey, store: Store): void {\n const key = storeCacheKey({ siteVersion, locale })\n\n if (!this.shouldUsePersistentStore(key)) {\n console.error('RuntimeCore: attempt to retain an ephemeral store', { key })\n return\n }\n\n this.activeStores.retain(key, store)\n }\n\n releaseStore({ siteVersion, locale }: StoreKey, store: Store): void {\n const key = storeCacheKey({ siteVersion, locale })\n\n if (!this.shouldUsePersistentStore(key)) {\n console.error('RuntimeCore: attempt to release an ephemeral store', { key })\n return\n }\n\n this.activeStores.release(key, store)\n }\n\n copyElementTree(\n elementTree: ElementData,\n replacementContext: SerializableReplacementContext,\n ): Element {\n return copyElementTree(this.protoStore.getState(), elementTree, replacementContext)\n }\n\n getBreakpoints(): Breakpoints {\n return getBreakpoints(this.protoStore.getState())\n }\n\n private shouldUsePersistentStore(key: string): boolean {\n // don't persist stores on the server unless the runtime instance is bound to a request\n // and the requested store matches the request's site version and locale\n return !isServer() || (this.requestKey !== undefined && storeCacheKey(this.requestKey) === key)\n }\n}\n\nconst storeCacheKey = ({ siteVersion, locale }: StoreKey): string =>\n `${siteVersionTag(siteVersion)}/${locale ?? 'default'}`\n\nconst siteVersionTag = (siteVersion: SiteVersion | null): string =>\n siteVersion?.version ?? VERSION_TAG_LIVE\n\nfunction validateOrigin(url: string, name: string): string {\n try {\n return new URL(url).origin\n } catch {\n throw new Error(`The Makeswift runtime received an invalid \\`${name}\\` parameter: \"${url}\".`)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,oBAAuC;AAIvC,yBAIO;AAEP,+BAAgC;AAEhC,6BAA+D;AAC/D,mBAKO;AAEP,6BAA8B;AAC9B,uBAAyB;AAOzB,MAAM,mBAAmB;AAElB,MAAM,YAAY;AAAA;AAAA;AAAA;AAAA;AAAA,EAKN,eAAe,IAAI,qCAAoC;AAAA,IACtE,mBAAmB;AAAA;AAAA;AAAA;AAAA,IAInB,UAAU,qCAAc,SAAS,YAAY,qCAAc,SAAS;AAAA,EACtE,CAAC;AAAA,EAEQ;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAET,YAAY;AAAA,IACV,YAAY;AAAA,IACZ,YAAY;AAAA,IACZ;AAAA,IACA;AAAA,IACA;AAAA,EACF,GAMG;AACD,SAAK,YAAY,eAAe,WAAW,WAAW;AACtD,SAAK,YAAY,eAAe,WAAW,WAAW;AACtD,SAAK,aAAa;AAClB,SAAK,QAAQ;AAEb,SAAK,iBAAa,kCAAoB;AAAA,MACpC,MAAM;AAAA,MACN,aAAa,kBAAc,0CAAsB,WAAW,IAAI;AAAA,IAClE,CAAC;AAAA,EACH;AAAA,EAEA,iBAAiB,EAAE,aAAa,OAAO,GAAoB;AACzD,UAAM,MAAM,cAAc,EAAE,aAAa,OAAO,CAAC;AAEjD,UAAM,cAAc,MAAM;AAExB,YAAM,gBAAgB,IAAI,qCAAuB;AAAA,QAC/C,KAAK,IAAI,IAAI,WAAW,KAAK,SAAS,E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A,MAAM,gBAAgB,CAAC,EAAE,aAAa,OAAO,MAC3C,GAAG,eAAe,WAAW,CAAC,IAAI,UAAU,SAAS;AAEvD,MAAM,iBAAiB,CAAC,gBACtB,aAAa,WAAW;AAE1B,SAAS,eAAe,KAAa,MAAsB;AACzD,MAAI;AACF,WAAO,IAAI,IAAI,GAAG,EAAE;AAAA,EACtB,QAAQ;AACN,UAAM,IAAI,MAAM,+CAA+C,IAAI,kBAAkB,GAAG,IAAI;AAAA,EAC9F;AACF;","names":[]}
@@ -29,10 +29,8 @@ __export(read_only_actions_exports, {
29
29
  registerPropControllers: () => registerPropControllers,
30
30
  registerPropControllersHandle: () => registerPropControllersHandle,
31
31
  registerReactComponentEffect: () => registerReactComponentEffect,
32
- resetLocaleState: () => resetLocaleState,
33
32
  setIsInBuilder: () => setIsInBuilder,
34
33
  setIsReadOnly: () => setIsReadOnly,
35
- setSiteVersion: () => setSiteVersion,
36
34
  unregisterComponent: () => unregisterComponent,
37
35
  unregisterPropControllers: () => unregisterPropControllers,
38
36
  unregisterPropControllersHandle: () => unregisterPropControllersHandle
@@ -55,11 +53,7 @@ const ReadOnlyActionTypes = {
55
53
  REGISTER_REACT_COMPONENT: "REGISTER_REACT_COMPONENT",
56
54
  UNREGISTER_REACT_COMPONENT: "UNREGISTER_REACT_COMPONENT",
57
55
  SET_IS_IN_BUILDER: "SET_IS_IN_BUILDER",
58
- SET_IS_READ_ONLY: "SET_IS_READ_ONLY",
59
- SET_SITE_VERSION: "SET_SITE_VERSION",
60
- // TODO: consolidate with `SET_LOCALE` action in `shared-api.ts`
61
- // (requires changes to the builder to handle null locales)
62
- RESET_LOCALE_STATE: "RESET_LOCALE_STATE"
56
+ SET_IS_READ_ONLY: "SET_IS_READ_ONLY"
63
57
  };
64
58
  function apiResourceFulfilled(resourceType, resourceId, resource, locale) {
65
59
  return {
@@ -157,12 +151,6 @@ function setIsInBuilder(isInBuilder) {
157
151
  function setIsReadOnly(isReadOnly) {
158
152
  return { type: ReadOnlyActionTypes.SET_IS_READ_ONLY, payload: isReadOnly };
159
153
  }
160
- function setSiteVersion(siteVersion) {
161
- return { type: ReadOnlyActionTypes.SET_SITE_VERSION, payload: siteVersion };
162
- }
163
- function resetLocaleState() {
164
- return { type: ReadOnlyActionTypes.RESET_LOCALE_STATE };
165
- }
166
154
  // Annotate the CommonJS export names for ESM import in node:
167
155
  0 && (module.exports = {
168
156
  ReadOnlyActionTypes,
@@ -176,10 +164,8 @@ function resetLocaleState() {
176
164
  registerPropControllers,
177
165
  registerPropControllersHandle,
178
166
  registerReactComponentEffect,
179
- resetLocaleState,
180
167
  setIsInBuilder,
181
168
  setIsReadOnly,
182
- setSiteVersion,
183
169
  unregisterComponent,
184
170
  unregisterPropControllers,
185
171
  unregisterPropControllersHandle
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../src/state/actions/internal/read-only-actions.ts"],"sourcesContent":["import { type ThunkAction } from '@reduxjs/toolkit'\n\nimport { ControlInstance } from '@makeswift/controls'\n\nimport { ElementImperativeHandle } from '../../../runtimes/react/element-imperative-handle'\n\nimport { type APIResource, APIResourceType, APIResourceLocale } from '../../../api/types'\nimport { type SiteVersion } from '../../../api/site-version'\nimport { type Descriptor as PropControllerDescriptor } from '../../../prop-controllers/descriptors'\n\nimport { type ComponentMeta } from '../../modules/components-meta'\nimport { type PropControllersHandle } from '../../modules/prop-controller-handles'\nimport { type ComponentType } from '../../modules/react-components'\nimport { type DescriptorsByComponentType } from '../../modules/prop-controllers'\n\nimport { type DocumentPayload } from '../../shared-api'\n\nexport const ReadOnlyActionTypes = {\n // TODO: this one should be a read-write action and we should refuse\n // to fetch resources on the client in read-only mode\n API_RESOURCE_FULFILLED: 'API_RESOURCE_FULFILLED',\n\n CREATE_ELEMENT_TREE: 'CREATE_ELEMENT_TREE',\n DELETE_ELEMENT_TREE: 'DELETE_ELEMENT_TREE',\n\n REGISTER_COMPONENT: 'REGISTER_COMPONENT',\n UNREGISTER_COMPONENT: 'UNREGISTER_COMPONENT',\n REGISTER_COMPONENT_HANDLE: 'REGISTER_COMPONENT_HANDLE',\n UNREGISTER_COMPONENT_HANDLE: 'UNREGISTER_COMPONENT_HANDLE',\n\n REGISTER_PROP_CONTROLLERS: 'REGISTER_PROP_CONTROLLERS',\n UNREGISTER_PROP_CONTROLLERS: 'UNREGISTER_PROP_CONTROLLERS',\n REGISTER_PROP_CONTROLLERS_HANDLE: 'REGISTER_PROP_CONTROLLERS_HANDLE',\n UNREGISTER_PROP_CONTROLLERS_HANDLE: 'UNREGISTER_PROP_CONTROLLERS_HANDLE',\n\n REGISTER_REACT_COMPONENT: 'REGISTER_REACT_COMPONENT',\n UNREGISTER_REACT_COMPONENT: 'UNREGISTER_REACT_COMPONENT',\n\n SET_IS_IN_BUILDER: 'SET_IS_IN_BUILDER',\n SET_IS_READ_ONLY: 'SET_IS_READ_ONLY',\n SET_SITE_VERSION: 'SET_SITE_VERSION',\n\n // TODO: consolidate with `SET_LOCALE` action in `shared-api.ts`\n // (requires changes to the builder to handle null locales)\n RESET_LOCALE_STATE: 'RESET_LOCALE_STATE',\n} as const\n\ntype APIResourceFulfilledAction = {\n type: typeof ReadOnlyActionTypes.API_RESOURCE_FULFILLED\n payload: {\n resourceType: APIResourceType\n resourceId: string\n resource: APIResource | null\n locale?: string | null\n }\n}\n\ntype CreateElementTreeAction = {\n type: typeof ReadOnlyActionTypes.CREATE_ELEMENT_TREE\n payload: { document: DocumentPayload; descriptors: DescriptorsByComponentType }\n}\n\ntype DeleteElementTreeAction = {\n type: typeof ReadOnlyActionTypes.DELETE_ELEMENT_TREE\n payload: { documentKey: string }\n}\n\nexport type RegisterComponentAction = {\n type: typeof ReadOnlyActionTypes.REGISTER_COMPONENT\n payload: {\n type: string\n meta: ComponentMeta\n propControllerDescriptors: Record<string, PropControllerDescriptor>\n }\n}\n\nexport type UnregisterComponentAction = {\n type: typeof ReadOnlyActionTypes.UNREGISTER_COMPONENT\n payload: { type: string }\n}\n\ntype RegisterComponentHandleAction = {\n type: typeof ReadOnlyActionTypes.REGISTER_COMPONENT_HANDLE\n payload: { documentKey: string; elementKey: string; componentHandle: ElementImperativeHandle }\n}\n\ntype UnregisterComponentHandleAction = {\n type: typeof ReadOnlyActionTypes.UNREGISTER_COMPONENT_HANDLE\n payload: { documentKey: string; elementKey: string }\n}\n\ntype RegisterPropControllersHandleAction = {\n type: typeof ReadOnlyActionTypes.REGISTER_PROP_CONTROLLERS_HANDLE\n payload: { documentKey: string; elementKey: string; handle: PropControllersHandle }\n}\n\ntype UnregisterPropControllersHandleAction = {\n type: typeof ReadOnlyActionTypes.UNREGISTER_PROP_CONTROLLERS_HANDLE\n payload: { documentKey: string; elementKey: string }\n}\n\ntype RegisterPropControllersAction = {\n type: typeof ReadOnlyActionTypes.REGISTER_PROP_CONTROLLERS\n payload: {\n documentKey: string\n elementKey: string\n propControllers: Record<string, ControlInstance>\n }\n}\n\ntype UnregisterPropControllersAction = {\n type: typeof ReadOnlyActionTypes.UNREGISTER_PROP_CONTROLLERS\n payload: { documentKey: string; elementKey: string }\n}\n\ntype RegisterReactComponentAction = {\n type: typeof ReadOnlyActionTypes.REGISTER_REACT_COMPONENT\n payload: { type: string; component: ComponentType }\n}\n\ntype UnregisterReactComponentAction = {\n type: typeof ReadOnlyActionTypes.UNREGISTER_REACT_COMPONENT\n payload: { type: string }\n}\n\ntype SetIsInBuilderAction = {\n type: typeof ReadOnlyActionTypes.SET_IS_IN_BUILDER\n payload: boolean\n}\n\ntype SetIsReadOnlyAction = {\n type: typeof ReadOnlyActionTypes.SET_IS_READ_ONLY\n payload: boolean\n}\n\ntype SetSiteVersionAction = {\n type: typeof ReadOnlyActionTypes.SET_SITE_VERSION\n payload: SiteVersion | null\n}\n\ntype ResetLocaleStateAction = {\n type: typeof ReadOnlyActionTypes.RESET_LOCALE_STATE\n}\n\nexport type ReadOnlyAction =\n | APIResourceFulfilledAction\n | CreateElementTreeAction\n | DeleteElementTreeAction\n | RegisterComponentAction\n | UnregisterComponentAction\n | RegisterComponentHandleAction\n | UnregisterComponentHandleAction\n | RegisterPropControllersHandleAction\n | UnregisterPropControllersHandleAction\n | RegisterPropControllersAction\n | UnregisterPropControllersAction\n | RegisterReactComponentAction\n | UnregisterReactComponentAction\n | SetIsInBuilderAction\n | SetIsReadOnlyAction\n | SetSiteVersionAction\n | ResetLocaleStateAction\n\nexport function apiResourceFulfilled<T extends APIResourceType>(\n resourceType: T,\n resourceId: string,\n resource: APIResource | null,\n locale?: APIResourceLocale<T>,\n): APIResourceFulfilledAction {\n return {\n type: ReadOnlyActionTypes.API_RESOURCE_FULFILLED,\n payload: { resourceType, resourceId, resource, locale },\n }\n}\n\nexport function createElementTree(\n payload: CreateElementTreeAction['payload'],\n): CreateElementTreeAction {\n return {\n type: ReadOnlyActionTypes.CREATE_ELEMENT_TREE,\n payload,\n }\n}\n\nexport function deleteElementTree(\n payload: DeleteElementTreeAction['payload'],\n): DeleteElementTreeAction {\n return { type: ReadOnlyActionTypes.DELETE_ELEMENT_TREE, payload }\n}\n\nexport function registerComponent(\n type: string,\n meta: ComponentMeta,\n propControllerDescriptors: Record<string, PropControllerDescriptor>,\n): RegisterComponentAction {\n return {\n type: ReadOnlyActionTypes.REGISTER_COMPONENT,\n payload: { type, meta, propControllerDescriptors },\n }\n}\n\nexport function unregisterComponent(type: string): UnregisterComponentAction {\n return { type: ReadOnlyActionTypes.UNREGISTER_COMPONENT, payload: { type } }\n}\n\nexport function registerComponentEffect(\n type: string,\n meta: ComponentMeta,\n propControllerDescriptors: Record<string, PropControllerDescriptor>,\n): ThunkAction<() => void, unknown, unknown, ReadOnlyAction> {\n return dispatch => {\n dispatch(registerComponent(type, meta, propControllerDescriptors))\n\n return () => {\n dispatch(unregisterComponent(type))\n }\n }\n}\n\nexport function registerComponentHandle(\n documentKey: string,\n elementKey: string,\n componentHandle: ElementImperativeHandle,\n): RegisterComponentHandleAction {\n return {\n type: ReadOnlyActionTypes.REGISTER_COMPONENT_HANDLE,\n payload: { documentKey, elementKey, componentHandle },\n }\n}\n\nfunction unregisterComponentHandle(\n documentKey: string,\n elementKey: string,\n): UnregisterComponentHandleAction {\n return {\n type: ReadOnlyActionTypes.UNREGISTER_COMPONENT_HANDLE,\n payload: { documentKey, elementKey },\n }\n}\n\nexport function registerComponentHandleEffect(\n documentKey: string,\n elementKey: string,\n componentHandle: ElementImperativeHandle,\n): ThunkAction<() => void, unknown, unknown, ReadOnlyAction> {\n return dispatch => {\n dispatch(registerComponentHandle(documentKey, elementKey, componentHandle))\n\n return () => {\n dispatch(unregisterComponentHandle(documentKey, elementKey))\n }\n }\n}\n\nexport function registerPropControllersHandle(\n documentKey: string,\n elementKey: string,\n handle: PropControllersHandle,\n): RegisterPropControllersHandleAction {\n return {\n type: ReadOnlyActionTypes.REGISTER_PROP_CONTROLLERS_HANDLE,\n payload: { documentKey, elementKey, handle },\n }\n}\n\nexport function unregisterPropControllersHandle(\n documentKey: string,\n elementKey: string,\n): UnregisterPropControllersHandleAction {\n return {\n type: ReadOnlyActionTypes.UNREGISTER_PROP_CONTROLLERS_HANDLE,\n payload: { documentKey, elementKey },\n }\n}\n\nexport function registerPropControllers(\n documentKey: string,\n elementKey: string,\n propControllers: Record<string, ControlInstance>,\n): RegisterPropControllersAction {\n return {\n type: ReadOnlyActionTypes.REGISTER_PROP_CONTROLLERS,\n payload: { documentKey, elementKey, propControllers },\n }\n}\n\nexport function unregisterPropControllers(\n documentKey: string,\n elementKey: string,\n): UnregisterPropControllersAction {\n return {\n type: ReadOnlyActionTypes.UNREGISTER_PROP_CONTROLLERS,\n payload: { documentKey, elementKey },\n }\n}\n\nfunction registerReactComponent(\n type: string,\n component: ComponentType,\n): RegisterReactComponentAction {\n return { type: ReadOnlyActionTypes.REGISTER_REACT_COMPONENT, payload: { type, component } }\n}\n\nfunction unregisterReactComponent(type: string): UnregisterReactComponentAction {\n return { type: ReadOnlyActionTypes.UNREGISTER_REACT_COMPONENT, payload: { type } }\n}\n\nexport function registerReactComponentEffect(\n type: string,\n component: ComponentType,\n): ThunkAction<() => void, unknown, unknown, ReadOnlyAction> {\n return dispatch => {\n dispatch(registerReactComponent(type, component))\n\n return () => {\n dispatch(unregisterReactComponent(type))\n }\n }\n}\n\nexport function setIsInBuilder(isInBuilder: boolean): SetIsInBuilderAction {\n return { type: ReadOnlyActionTypes.SET_IS_IN_BUILDER, payload: isInBuilder }\n}\n\nexport function setIsReadOnly(isReadOnly: boolean): SetIsReadOnlyAction {\n return { type: ReadOnlyActionTypes.SET_IS_READ_ONLY, payload: isReadOnly }\n}\n\nexport function setSiteVersion(siteVersion: SiteVersion | null): SetSiteVersionAction {\n return { type: ReadOnlyActionTypes.SET_SITE_VERSION, payload: siteVersion }\n}\n\nexport function resetLocaleState(): ResetLocaleStateAction {\n return { type: ReadOnlyActionTypes.RESET_LOCALE_STATE }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAiBO,MAAM,sBAAsB;AAAA;AAAA;AAAA,EAGjC,wBAAwB;AAAA,EAExB,qBAAqB;AAAA,EACrB,qBAAqB;AAAA,EAErB,oBAAoB;AAAA,EACpB,sBAAsB;AAAA,EACtB,2BAA2B;AAAA,EAC3B,6BAA6B;AAAA,EAE7B,2BAA2B;AAAA,EAC3B,6BAA6B;AAAA,EAC7B,kCAAkC;AAAA,EAClC,oCAAoC;AAAA,EAEpC,0BAA0B;AAAA,EAC1B,4BAA4B;AAAA,EAE5B,mBAAmB;AAAA,EACnB,kBAAkB;AAAA,EAClB,kBAAkB;AAAA;AAAA;AAAA,EAIlB,oBAAoB;AACtB;AAsHO,SAAS,qBACd,cACA,YACA,UACA,QAC4B;AAC5B,SAAO;AAAA,IACL,MAAM,oBAAoB;AAAA,IAC1B,SAAS,EAAE,cAAc,YAAY,UAAU,OAAO;AAAA,EACxD;AACF;AAE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1B,SAAS,EAAE,aAAa,WAAW;AAAA,EACrC;AACF;AAEO,SAAS,wBACd,aACA,YACA,iBAC+B;AAC/B,SAAO;AAAA,IACL,MAAM,oBAAoB;AAAA,IAC1B,SAAS,EAAE,aAAa,YAAY,gBAAgB;AAAA,EACtD;AACF;AAEO,SAAS,0BACd,aACA,YACiC;AACjC,SAAO;AAAA,IACL,MAAM,oBAAoB;AAAA,IAC1B,SAAS,EAAE,aAAa,WAAW;AAAA,EACrC;AACF;AAEA,SAAS,uBACP,MACA,WAC8B;AAC9B,SAAO,EAAE,MAAM,oBAAoB,0BAA0B,SAAS,EAAE,MAAM,UAAU,EAAE;AAC5F;AAEA,SAAS,yBAAyB,MAA8C;AAC9E,SAAO,EAAE,MAAM,oBAAoB,4BAA4B,SAAS,EAAE,KAAK,EAAE;AACnF;AAEO,SAAS,6BACd,MACA,WAC2D;AAC3D,SAAO,cAAY;AACjB,aAAS,uBAAuB,MAAM,SAAS,CAAC;AAEhD,WAAO,MAAM;AACX,eAAS,yBAAyB,IAAI,CAAC;AAAA,IACzC;AAAA,EACF;AACF;AAEO,SAAS,eAAe,aAA4C;AACzE,SAAO,EAAE,MAAM,oBAAoB,mBAAmB,SAAS,YAAY;AAC7E;AAEO,SAAS,cAAc,YAA0C;AACtE,SAAO,EAAE,MAAM,oBAAoB,kBAAkB,SAAS,WAAW;AAC3E;AAEO,SAAS,eAAe,aAAuD;AACpF,SAAO,EAAE,MAAM,oBAAoB,kBAAkB,SAAS,YAAY;AAC5E;AAEO,SAAS,mBAA2C;AACzD,SAAO,EAAE,MAAM,oBAAoB,mBAAmB;AACxD;","names":[]}
1
+ {"version":3,"sources":["../../../../../src/state/actions/internal/read-only-actions.ts"],"sourcesContent":["import { type ThunkAction } from '@reduxjs/toolkit'\n\nimport { ControlInstance } from '@makeswift/controls'\n\nimport { ElementImperativeHandle } from '../../../runtimes/react/element-imperative-handle'\n\nimport { type APIResource, APIResourceType, APIResourceLocale } from '../../../api/types'\nimport { type Descriptor as PropControllerDescriptor } from '../../../prop-controllers/descriptors'\n\nimport { type ComponentMeta } from '../../modules/components-meta'\nimport { type PropControllersHandle } from '../../modules/prop-controller-handles'\nimport { type ComponentType } from '../../modules/react-components'\nimport { type DescriptorsByComponentType } from '../../modules/prop-controllers'\n\nimport { type DocumentPayload } from '../../shared-api'\n\nexport const ReadOnlyActionTypes = {\n // TODO: this one should be a read-write action and we should refuse\n // to fetch resources on the client in read-only mode\n API_RESOURCE_FULFILLED: 'API_RESOURCE_FULFILLED',\n\n CREATE_ELEMENT_TREE: 'CREATE_ELEMENT_TREE',\n DELETE_ELEMENT_TREE: 'DELETE_ELEMENT_TREE',\n\n REGISTER_COMPONENT: 'REGISTER_COMPONENT',\n UNREGISTER_COMPONENT: 'UNREGISTER_COMPONENT',\n REGISTER_COMPONENT_HANDLE: 'REGISTER_COMPONENT_HANDLE',\n UNREGISTER_COMPONENT_HANDLE: 'UNREGISTER_COMPONENT_HANDLE',\n\n REGISTER_PROP_CONTROLLERS: 'REGISTER_PROP_CONTROLLERS',\n UNREGISTER_PROP_CONTROLLERS: 'UNREGISTER_PROP_CONTROLLERS',\n REGISTER_PROP_CONTROLLERS_HANDLE: 'REGISTER_PROP_CONTROLLERS_HANDLE',\n UNREGISTER_PROP_CONTROLLERS_HANDLE: 'UNREGISTER_PROP_CONTROLLERS_HANDLE',\n\n REGISTER_REACT_COMPONENT: 'REGISTER_REACT_COMPONENT',\n UNREGISTER_REACT_COMPONENT: 'UNREGISTER_REACT_COMPONENT',\n\n SET_IS_IN_BUILDER: 'SET_IS_IN_BUILDER',\n SET_IS_READ_ONLY: 'SET_IS_READ_ONLY',\n} as const\n\ntype APIResourceFulfilledAction = {\n type: typeof ReadOnlyActionTypes.API_RESOURCE_FULFILLED\n payload: {\n resourceType: APIResourceType\n resourceId: string\n resource: APIResource | null\n locale?: string | null\n }\n}\n\ntype CreateElementTreeAction = {\n type: typeof ReadOnlyActionTypes.CREATE_ELEMENT_TREE\n payload: { document: DocumentPayload; descriptors: DescriptorsByComponentType }\n}\n\ntype DeleteElementTreeAction = {\n type: typeof ReadOnlyActionTypes.DELETE_ELEMENT_TREE\n payload: { documentKey: string }\n}\n\nexport type RegisterComponentAction = {\n type: typeof ReadOnlyActionTypes.REGISTER_COMPONENT\n payload: {\n type: string\n meta: ComponentMeta\n propControllerDescriptors: Record<string, PropControllerDescriptor>\n }\n}\n\nexport type UnregisterComponentAction = {\n type: typeof ReadOnlyActionTypes.UNREGISTER_COMPONENT\n payload: { type: string }\n}\n\ntype RegisterComponentHandleAction = {\n type: typeof ReadOnlyActionTypes.REGISTER_COMPONENT_HANDLE\n payload: { documentKey: string; elementKey: string; componentHandle: ElementImperativeHandle }\n}\n\ntype UnregisterComponentHandleAction = {\n type: typeof ReadOnlyActionTypes.UNREGISTER_COMPONENT_HANDLE\n payload: { documentKey: string; elementKey: string }\n}\n\ntype RegisterPropControllersHandleAction = {\n type: typeof ReadOnlyActionTypes.REGISTER_PROP_CONTROLLERS_HANDLE\n payload: { documentKey: string; elementKey: string; handle: PropControllersHandle }\n}\n\ntype UnregisterPropControllersHandleAction = {\n type: typeof ReadOnlyActionTypes.UNREGISTER_PROP_CONTROLLERS_HANDLE\n payload: { documentKey: string; elementKey: string }\n}\n\ntype RegisterPropControllersAction = {\n type: typeof ReadOnlyActionTypes.REGISTER_PROP_CONTROLLERS\n payload: {\n documentKey: string\n elementKey: string\n propControllers: Record<string, ControlInstance>\n }\n}\n\ntype UnregisterPropControllersAction = {\n type: typeof ReadOnlyActionTypes.UNREGISTER_PROP_CONTROLLERS\n payload: { documentKey: string; elementKey: string }\n}\n\ntype RegisterReactComponentAction = {\n type: typeof ReadOnlyActionTypes.REGISTER_REACT_COMPONENT\n payload: { type: string; component: ComponentType }\n}\n\ntype UnregisterReactComponentAction = {\n type: typeof ReadOnlyActionTypes.UNREGISTER_REACT_COMPONENT\n payload: { type: string }\n}\n\ntype SetIsInBuilderAction = {\n type: typeof ReadOnlyActionTypes.SET_IS_IN_BUILDER\n payload: boolean\n}\n\ntype SetIsReadOnlyAction = {\n type: typeof ReadOnlyActionTypes.SET_IS_READ_ONLY\n payload: boolean\n}\n\nexport type ReadOnlyAction =\n | APIResourceFulfilledAction\n | CreateElementTreeAction\n | DeleteElementTreeAction\n | RegisterComponentAction\n | UnregisterComponentAction\n | RegisterComponentHandleAction\n | UnregisterComponentHandleAction\n | RegisterPropControllersHandleAction\n | UnregisterPropControllersHandleAction\n | RegisterPropControllersAction\n | UnregisterPropControllersAction\n | RegisterReactComponentAction\n | UnregisterReactComponentAction\n | SetIsInBuilderAction\n | SetIsReadOnlyAction\n\nexport function apiResourceFulfilled<T extends APIResourceType>(\n resourceType: T,\n resourceId: string,\n resource: APIResource | null,\n locale?: APIResourceLocale<T>,\n): APIResourceFulfilledAction {\n return {\n type: ReadOnlyActionTypes.API_RESOURCE_FULFILLED,\n payload: { resourceType, resourceId, resource, locale },\n }\n}\n\nexport function createElementTree(\n payload: CreateElementTreeAction['payload'],\n): CreateElementTreeAction {\n return {\n type: ReadOnlyActionTypes.CREATE_ELEMENT_TREE,\n payload,\n }\n}\n\nexport function deleteElementTree(\n payload: DeleteElementTreeAction['payload'],\n): DeleteElementTreeAction {\n return { type: ReadOnlyActionTypes.DELETE_ELEMENT_TREE, payload }\n}\n\nexport function registerComponent(\n type: string,\n meta: ComponentMeta,\n propControllerDescriptors: Record<string, PropControllerDescriptor>,\n): RegisterComponentAction {\n return {\n type: ReadOnlyActionTypes.REGISTER_COMPONENT,\n payload: { type, meta, propControllerDescriptors },\n }\n}\n\nexport function unregisterComponent(type: string): UnregisterComponentAction {\n return { type: ReadOnlyActionTypes.UNREGISTER_COMPONENT, payload: { type } }\n}\n\nexport function registerComponentEffect(\n type: string,\n meta: ComponentMeta,\n propControllerDescriptors: Record<string, PropControllerDescriptor>,\n): ThunkAction<() => void, unknown, unknown, ReadOnlyAction> {\n return dispatch => {\n dispatch(registerComponent(type, meta, propControllerDescriptors))\n\n return () => {\n dispatch(unregisterComponent(type))\n }\n }\n}\n\nexport function registerComponentHandle(\n documentKey: string,\n elementKey: string,\n componentHandle: ElementImperativeHandle,\n): RegisterComponentHandleAction {\n return {\n type: ReadOnlyActionTypes.REGISTER_COMPONENT_HANDLE,\n payload: { documentKey, elementKey, componentHandle },\n }\n}\n\nfunction unregisterComponentHandle(\n documentKey: string,\n elementKey: string,\n): UnregisterComponentHandleAction {\n return {\n type: ReadOnlyActionTypes.UNREGISTER_COMPONENT_HANDLE,\n payload: { documentKey, elementKey },\n }\n}\n\nexport function registerComponentHandleEffect(\n documentKey: string,\n elementKey: string,\n componentHandle: ElementImperativeHandle,\n): ThunkAction<() => void, unknown, unknown, ReadOnlyAction> {\n return dispatch => {\n dispatch(registerComponentHandle(documentKey, elementKey, componentHandle))\n\n return () => {\n dispatch(unregisterComponentHandle(documentKey, elementKey))\n }\n }\n}\n\nexport function registerPropControllersHandle(\n documentKey: string,\n elementKey: string,\n handle: PropControllersHandle,\n): RegisterPropControllersHandleAction {\n return {\n type: ReadOnlyActionTypes.REGISTER_PROP_CONTROLLERS_HANDLE,\n payload: { documentKey, elementKey, handle },\n }\n}\n\nexport function unregisterPropControllersHandle(\n documentKey: string,\n elementKey: string,\n): UnregisterPropControllersHandleAction {\n return {\n type: ReadOnlyActionTypes.UNREGISTER_PROP_CONTROLLERS_HANDLE,\n payload: { documentKey, elementKey },\n }\n}\n\nexport function registerPropControllers(\n documentKey: string,\n elementKey: string,\n propControllers: Record<string, ControlInstance>,\n): RegisterPropControllersAction {\n return {\n type: ReadOnlyActionTypes.REGISTER_PROP_CONTROLLERS,\n payload: { documentKey, elementKey, propControllers },\n }\n}\n\nexport function unregisterPropControllers(\n documentKey: string,\n elementKey: string,\n): UnregisterPropControllersAction {\n return {\n type: ReadOnlyActionTypes.UNREGISTER_PROP_CONTROLLERS,\n payload: { documentKey, elementKey },\n }\n}\n\nfunction registerReactComponent(\n type: string,\n component: ComponentType,\n): RegisterReactComponentAction {\n return { type: ReadOnlyActionTypes.REGISTER_REACT_COMPONENT, payload: { type, component } }\n}\n\nfunction unregisterReactComponent(type: string): UnregisterReactComponentAction {\n return { type: ReadOnlyActionTypes.UNREGISTER_REACT_COMPONENT, payload: { type } }\n}\n\nexport function registerReactComponentEffect(\n type: string,\n component: ComponentType,\n): ThunkAction<() => void, unknown, unknown, ReadOnlyAction> {\n return dispatch => {\n dispatch(registerReactComponent(type, component))\n\n return () => {\n dispatch(unregisterReactComponent(type))\n }\n }\n}\n\nexport function setIsInBuilder(isInBuilder: boolean): SetIsInBuilderAction {\n return { type: ReadOnlyActionTypes.SET_IS_IN_BUILDER, payload: isInBuilder }\n}\n\nexport function setIsReadOnly(isReadOnly: boolean): SetIsReadOnlyAction {\n return { type: ReadOnlyActionTypes.SET_IS_READ_ONLY, payload: isReadOnly }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAgBO,MAAM,sBAAsB;AAAA;AAAA;AAAA,EAGjC,wBAAwB;AAAA,EAExB,qBAAqB;AAAA,EACrB,qBAAqB;AAAA,EAErB,oBAAoB;AAAA,EACpB,sBAAsB;AAAA,EACtB,2BAA2B;AAAA,EAC3B,6BAA6B;AAAA,EAE7B,2BAA2B;AAAA,EAC3B,6BAA6B;AAAA,EAC7B,kCAAkC;AAAA,EAClC,oCAAoC;AAAA,EAEpC,0BAA0B;AAAA,EAC1B,4BAA4B;AAAA,EAE5B,mBAAmB;AAAA,EACnB,kBAAkB;AACpB;AA2GO,SAAS,qBACd,cACA,YACA,UACA,QAC4B;AAC5B,SAAO;AAAA,IACL,MAAM,oBAAoB;AAAA,IAC1B,SAAS,EAAE,cAAc,YAAY,UAAU,OAAO;AAAA,EACxD;AACF;AAEO,SAAS,kBACd,SACyB;AACzB,SAAO;AAAA,IACL,MAAM,oBAAoB;AAAA,IAC1B;AA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