@makeswift/runtime 0.28.7-canary.3 → 0.28.7-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.
- package/dist/cjs/api/graphql/documents/queries.js +6 -6
- package/dist/cjs/api/graphql/documents/queries.js.map +1 -1
- package/dist/cjs/api/graphql/generated/types.js.map +1 -1
- package/dist/cjs/api/graphql-api-client.js +61 -0
- package/dist/cjs/api/graphql-api-client.js.map +1 -0
- package/dist/cjs/api/{client.js → host-api-resources-client.js} +7 -15
- package/dist/cjs/api/host-api-resources-client.js.map +1 -0
- package/dist/cjs/api/rest-api-client.js +187 -0
- package/dist/cjs/api/rest-api-client.js.map +1 -0
- package/dist/cjs/api/schema/index.js +23 -0
- package/dist/cjs/api/schema/index.js.map +1 -0
- package/dist/cjs/api/schema/page-pathname-slice.js +38 -0
- package/dist/cjs/api/schema/page-pathname-slice.js.map +1 -0
- package/dist/cjs/api-handler/handlers/manifest.js +1 -1
- package/dist/cjs/client/component-snapshot.js +63 -0
- package/dist/cjs/client/component-snapshot.js.map +1 -0
- package/dist/cjs/client/index.js +102 -360
- package/dist/cjs/client/index.js.map +1 -1
- package/dist/cjs/client/page-snapshot.js +33 -0
- package/dist/cjs/client/page-snapshot.js.map +1 -0
- package/dist/cjs/client/schema/component-document.js +45 -0
- package/dist/cjs/client/schema/component-document.js.map +1 -0
- package/dist/cjs/client/schema/fonts.js +38 -0
- package/dist/cjs/client/schema/fonts.js.map +1 -0
- package/dist/cjs/client/schema/get-page.js +39 -0
- package/dist/cjs/client/schema/get-page.js.map +1 -0
- package/dist/cjs/client/schema/get-pages.js +68 -0
- package/dist/cjs/client/schema/get-pages.js.map +1 -0
- package/dist/cjs/client/schema/index.js +31 -0
- package/dist/cjs/client/schema/index.js.map +1 -0
- package/dist/cjs/client/schema/preview-token-payload.js +34 -0
- package/dist/cjs/client/schema/preview-token-payload.js.map +1 -0
- package/dist/cjs/components/builtin/Form/Form.js +2 -2
- package/dist/cjs/components/builtin/Form/Form.js.map +1 -1
- package/dist/cjs/next/components/tests/controls/color-control/fixtures.js.map +1 -1
- package/dist/cjs/next/components/tests/controls/page-control-prop-rendering.js.map +1 -1
- package/dist/cjs/next/components/tests/controls/rich-text-v2-control/fixtures.js.map +1 -1
- package/dist/cjs/next/testing/element-data.js +3 -3
- package/dist/cjs/next/testing/element-data.js.map +1 -1
- package/dist/cjs/runtimes/react/components/GoogleFontLink.js +2 -2
- package/dist/cjs/runtimes/react/components/GoogleFontLink.js.map +1 -1
- package/dist/cjs/runtimes/react/components/hooks/use-page-snippets.js +2 -2
- package/dist/cjs/runtimes/react/components/hooks/use-page-snippets.js.map +1 -1
- package/dist/cjs/runtimes/react/components/page/PageHead.js +2 -2
- package/dist/cjs/runtimes/react/components/page/PageHead.js.map +1 -1
- package/dist/cjs/runtimes/react/hooks/makeswift-api.js +10 -10
- package/dist/cjs/runtimes/react/hooks/makeswift-api.js.map +1 -1
- package/dist/cjs/runtimes/react/{host-api-client.js → hooks/use-api-resources-client.js} +9 -9
- package/dist/cjs/runtimes/react/hooks/use-api-resources-client.js.map +1 -0
- package/dist/cjs/runtimes/react/hooks/use-cache-data.js +2 -2
- package/dist/cjs/runtimes/react/hooks/use-cache-data.js.map +1 -1
- package/dist/cjs/runtimes/react/hooks/use-graphql-api-client.js +35 -0
- package/dist/cjs/runtimes/react/hooks/use-graphql-api-client.js.map +1 -0
- package/dist/cjs/runtimes/react/hooks/use-resource-resolver.js +3 -3
- package/dist/cjs/runtimes/react/hooks/use-resource-resolver.js.map +1 -1
- package/dist/cjs/runtimes/react/runtime-core.js +12 -7
- package/dist/cjs/runtimes/react/runtime-core.js.map +1 -1
- package/dist/cjs/state/middleware/makeswift-api-client-sync.js.map +1 -1
- package/dist/cjs/state/store.js +3 -3
- package/dist/cjs/state/store.js.map +1 -1
- package/dist/esm/api/graphql/documents/queries.js +4 -4
- package/dist/esm/api/graphql/documents/queries.js.map +1 -1
- package/dist/esm/api/graphql/generated/types.js.map +1 -1
- package/dist/esm/api/graphql-api-client.js +42 -0
- package/dist/esm/api/graphql-api-client.js.map +1 -0
- package/dist/esm/api/{client.js → host-api-resources-client.js} +3 -11
- package/dist/esm/api/host-api-resources-client.js.map +1 -0
- package/dist/esm/api/rest-api-client.js +152 -0
- package/dist/esm/api/rest-api-client.js.map +1 -0
- package/dist/esm/api/schema/index.js +2 -0
- package/dist/esm/api/schema/index.js.map +1 -0
- package/dist/esm/api/schema/page-pathname-slice.js +14 -0
- package/dist/esm/api/schema/page-pathname-slice.js.map +1 -0
- package/dist/esm/api-handler/handlers/manifest.js +1 -1
- package/dist/esm/client/component-snapshot.js +39 -0
- package/dist/esm/client/component-snapshot.js.map +1 -0
- package/dist/esm/client/index.js +67 -329
- package/dist/esm/client/index.js.map +1 -1
- package/dist/esm/client/page-snapshot.js +9 -0
- package/dist/esm/client/page-snapshot.js.map +1 -0
- package/dist/esm/client/schema/component-document.js +20 -0
- package/dist/esm/client/schema/component-document.js.map +1 -0
- package/dist/esm/client/schema/fonts.js +14 -0
- package/dist/esm/client/schema/fonts.js.map +1 -0
- package/dist/esm/client/schema/get-page.js +15 -0
- package/dist/esm/client/schema/get-page.js.map +1 -0
- package/dist/esm/client/schema/get-pages.js +42 -0
- package/dist/esm/client/schema/get-pages.js.map +1 -0
- package/dist/esm/client/schema/index.js +6 -0
- package/dist/esm/client/schema/index.js.map +1 -0
- package/dist/esm/client/schema/preview-token-payload.js +10 -0
- package/dist/esm/client/schema/preview-token-payload.js.map +1 -0
- package/dist/esm/components/builtin/Form/Form.js +2 -2
- package/dist/esm/components/builtin/Form/Form.js.map +1 -1
- package/dist/esm/next/components/tests/controls/color-control/fixtures.js.map +1 -1
- package/dist/esm/next/components/tests/controls/page-control-prop-rendering.js.map +1 -1
- package/dist/esm/next/components/tests/controls/rich-text-v2-control/fixtures.js.map +1 -1
- package/dist/esm/next/testing/element-data.js +1 -1
- package/dist/esm/next/testing/element-data.js.map +1 -1
- package/dist/esm/runtimes/react/components/GoogleFontLink.js +2 -2
- package/dist/esm/runtimes/react/components/GoogleFontLink.js.map +1 -1
- package/dist/esm/runtimes/react/components/hooks/use-page-snippets.js +2 -2
- package/dist/esm/runtimes/react/components/hooks/use-page-snippets.js.map +1 -1
- package/dist/esm/runtimes/react/components/page/PageHead.js +2 -2
- package/dist/esm/runtimes/react/components/page/PageHead.js.map +1 -1
- package/dist/esm/runtimes/react/hooks/makeswift-api.js +10 -10
- package/dist/esm/runtimes/react/hooks/makeswift-api.js.map +1 -1
- package/dist/esm/runtimes/react/hooks/use-api-resources-client.js +9 -0
- package/dist/esm/runtimes/react/hooks/use-api-resources-client.js.map +1 -0
- package/dist/esm/runtimes/react/hooks/use-cache-data.js +2 -2
- package/dist/esm/runtimes/react/hooks/use-cache-data.js.map +1 -1
- package/dist/esm/runtimes/react/hooks/use-graphql-api-client.js +11 -0
- package/dist/esm/runtimes/react/hooks/use-graphql-api-client.js.map +1 -0
- package/dist/esm/runtimes/react/hooks/use-resource-resolver.js +3 -3
- package/dist/esm/runtimes/react/hooks/use-resource-resolver.js.map +1 -1
- package/dist/esm/runtimes/react/runtime-core.js +12 -7
- package/dist/esm/runtimes/react/runtime-core.js.map +1 -1
- package/dist/esm/state/middleware/makeswift-api-client-sync.js.map +1 -1
- package/dist/esm/state/store.js +3 -3
- package/dist/esm/state/store.js.map +1 -1
- package/dist/types/api/__tests__/rest-api-client.error-handling.test.d.ts +2 -0
- package/dist/types/api/__tests__/rest-api-client.error-handling.test.d.ts.map +1 -0
- package/dist/types/api/__tests__/rest-api-client.get-resources.test.d.ts +2 -0
- package/dist/types/api/__tests__/rest-api-client.get-resources.test.d.ts.map +1 -0
- package/dist/types/api/graphql/documents/queries.d.ts +1 -1
- package/dist/types/api/graphql/documents/queries.d.ts.map +1 -1
- package/dist/types/api/graphql/generated/types.d.ts +2 -2
- package/dist/types/api/graphql/generated/types.d.ts.map +1 -1
- package/dist/types/api/graphql-api-client.d.ts +14 -0
- package/dist/types/api/graphql-api-client.d.ts.map +1 -0
- package/dist/types/api/{client.d.ts → host-api-resources-client.d.ts} +3 -7
- package/dist/types/api/host-api-resources-client.d.ts.map +1 -0
- package/dist/types/api/rest-api-client.d.ts +27 -0
- package/dist/types/api/rest-api-client.d.ts.map +1 -0
- package/dist/types/api/schema/index.d.ts +2 -0
- package/dist/types/api/schema/index.d.ts.map +1 -0
- package/dist/types/api/schema/page-pathname-slice.d.ts +21 -0
- package/dist/types/api/schema/page-pathname-slice.d.ts.map +1 -0
- package/dist/types/client/component-snapshot.d.ts +25 -0
- package/dist/types/client/component-snapshot.d.ts.map +1 -0
- package/dist/types/client/index.d.ts +19 -640
- package/dist/types/client/index.d.ts.map +1 -1
- package/dist/types/client/page-snapshot.d.ts +62 -0
- package/dist/types/client/page-snapshot.d.ts.map +1 -0
- package/dist/types/client/schema/component-document.d.ts +285 -0
- package/dist/types/client/schema/component-document.d.ts.map +1 -0
- package/dist/types/client/schema/fonts.d.ts +27 -0
- package/dist/types/client/schema/fonts.d.ts.map +1 -0
- package/dist/types/client/schema/get-page.d.ts +30 -0
- package/dist/types/client/schema/get-page.d.ts.map +1 -0
- package/dist/types/client/schema/get-pages.d.ts +202 -0
- package/dist/types/client/schema/get-pages.d.ts.map +1 -0
- package/dist/types/client/schema/index.d.ts +6 -0
- package/dist/types/client/schema/index.d.ts.map +1 -0
- package/dist/types/client/schema/preview-token-payload.d.ts +19 -0
- package/dist/types/client/schema/preview-token-payload.d.ts.map +1 -0
- package/dist/types/next/components/tests/controls/color-control/fixtures.d.ts +1 -1
- package/dist/types/next/components/tests/controls/color-control/fixtures.d.ts.map +1 -1
- package/dist/types/next/components/tests/controls/page-control-prop-rendering.d.ts +1 -1
- package/dist/types/next/components/tests/controls/page-control-prop-rendering.d.ts.map +1 -1
- package/dist/types/next/components/tests/controls/rich-text-v2-control/fixtures.d.ts +1 -1
- package/dist/types/next/components/tests/controls/rich-text-v2-control/fixtures.d.ts.map +1 -1
- package/dist/types/runtimes/react/components/GoogleFontLink.d.ts.map +1 -1
- package/dist/types/runtimes/react/components/page/PageHead.d.ts.map +1 -1
- package/dist/types/runtimes/react/hooks/use-api-resources-client.d.ts +3 -0
- package/dist/types/runtimes/react/hooks/use-api-resources-client.d.ts.map +1 -0
- package/dist/types/runtimes/react/hooks/use-cache-data.d.ts +1 -1
- package/dist/types/runtimes/react/hooks/use-cache-data.d.ts.map +1 -1
- package/dist/types/runtimes/react/hooks/use-graphql-api-client.d.ts +3 -0
- package/dist/types/runtimes/react/hooks/use-graphql-api-client.d.ts.map +1 -0
- package/dist/types/runtimes/react/runtime-core.d.ts +2 -0
- package/dist/types/runtimes/react/runtime-core.d.ts.map +1 -1
- package/dist/types/state/middleware/makeswift-api-client-sync.d.ts +2 -2
- package/dist/types/state/middleware/makeswift-api-client-sync.d.ts.map +1 -1
- package/dist/types/state/store.d.ts +4 -4
- package/dist/types/state/store.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/cjs/api/client.js.map +0 -1
- package/dist/cjs/runtimes/react/host-api-client.js.map +0 -1
- package/dist/esm/api/client.js.map +0 -1
- package/dist/esm/runtimes/react/host-api-client.js +0 -9
- package/dist/esm/runtimes/react/host-api-client.js.map +0 -1
- package/dist/types/api/client.d.ts.map +0 -1
- package/dist/types/client/tests/client.error-handling.test.d.ts +0 -2
- package/dist/types/client/tests/client.error-handling.test.d.ts.map +0 -1
- package/dist/types/client/tests/client.get-resources.test.d.ts +0 -2
- package/dist/types/client/tests/client.get-resources.test.d.ts.map +0 -1
- package/dist/types/runtimes/react/host-api-client.d.ts +0 -3
- package/dist/types/runtimes/react/host-api-client.d.ts.map +0 -1
|
@@ -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.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":"AAsDI,cA6EI,YA7EJ;AAtDJ,SAAyB,UAAU,YAAY,QAAQ,gBAAgB,WAAW;AAClF,SAAS,8BAA8B;AACvC,SAAS,aAAa;AACtB,SAAS,QAAQ,cAAc;AAC/B,OAAO;AACP,SAAS,iCAAiC;AAM1C,SAAS,sBAAsB;AAE/B,SAAS,0BAA0B;AACnC,SAAS,YAAY;AACrB,SAAS,gBAAgB;AACzB,YAAY,aAAa;AAEzB,MAAM,UAAU;AAChB,MAAM,aAAa;AAEnB,MAAM,aAAa,CAAC,SAClB,SAAS,SAAY,cAAc,eAAe,IAAI,IAAI,OAAO,KAAK,UAAU,IAAI;AAEtF,MAAM,eAAe,CAAC,SACpB,MAAM,oBAAoB,KAAK,aAAa,qBAAqB,MAAM,eAAe,EAAE;AAE1F,MAAM,uBAAuB,CAAC,SAAkB,SAAS,cAAc,SAAY,KAA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A,EACF,OAAO;AAEL,YAAQ,OAAO,UAAU,IAAI;AAC7B,YAAQ,OAAO,aAAa,WAAW,CAAC;AAExC,UAAM,WAAW,QAAQ,iCAAiC,aAAa,EAAE,QAAQ,UAAU,CAAC;AAC5F,UAAM,cAAc;AAAA,MAClB,oBAAC,sBAAmB,UAAqB,GAAG,mBAAmB;AAAA,IACjE;AAEA,UAAM,WAAW,MAAM,iBAAiB,WAAW;AACnD,UAAM,cAAc,CAAC,OACnB,SAAS,cAAc,iBAAiB,EAAE,IAAI;AAEhD,WAAO,aAAa,YAAY,MAAM,CAAC,CAAC,EAAE,gBAAgB,eAAe;AACzE,WAAO,CAAC,GAAG,SAAS,iBAAiB,OAAO,CAAC,EAAE,IAAI,OAAK,EAAE,WAAW,CAAC,EAAE;AAAA,MACtE;AAAA,IACF;AACA,WAAO,OAAO,YAAY,iBAAiB,GAAG,WAAW,CAAC,EAAE,KAAK,CAAC;AAAA,EACpE;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../../../../src/next/components/tests/controls/page-control-prop-rendering.tsx"],"sourcesContent":["import { type ReactNode, Fragment, forwardRef, useRef, isValidElement, act } from 'react'\nimport { renderToReadableStream } from 'react-dom/server'\nimport { JSDOM } from 'jsdom'\nimport { render, screen } from '@testing-library/react'\nimport '@testing-library/jest-dom'\nimport { ServerInsertedHTMLContext } from 'next/navigation'\n\nimport { type Data, type ValueType, type DataType, ControlDefinition } from '@makeswift/controls'\n\nimport { type CacheData } from '../../../../api/api-resources-client'\nimport { ElementData } from '../../../../state/read-only-state'\nimport { setIsInBuilder } from '../../../../state/actions/internal/read-only-actions'\nimport { ReactRuntime } from '../../../../runtimes/react/react-runtime'\nimport { MakeswiftComponent } from '../../../../runtimes/react/components/MakeswiftComponent'\nimport { Page } from '../../page'\nimport { isServer } from '../../../../utils/is-server'\nimport * as Testing from '../../../testing'\n\nconst ROOT_ID = '00000000-0000-0000-0000-000000000000'\nconst ELEMENT_ID = '11111111-1111-1111-1111-111111111111'\n\nconst renderProp = (prop: any) =>\n prop === undefined ? 'undefined' : isValidElement(prop) ? prop : JSON.stringify(prop)\n\nconst propSnapshot = (prop: HTMLElement | null) =>\n prop?.childElementCount ? prop.childNodes : parseStringifiedProp(prop?.textContent ?? '')\n\nconst parseStringifiedProp = (prop: string) => (prop === 'undefined' ? undefined : JSON.parse(prop))\n\nasync function streamToString(stream: ReadableStream) {\n const reader = stream.getReader()\n const decoder = new TextDecoder()\n\n let result = ''\n\n while (true) {\n const { done, value } = await reader.read()\n if (done) break\n result += decoder.decode(value, { stream: true })\n }\n\n return result\n}\n\nasync function renderToString(element: ReactNode) {\n return await streamToString(await renderToReadableStream(element))\n}\n\nasync function serverSideRender(children: ReactNode) {\n // wrap the children in a context provider to capture server-inserted HTML, see\n // https://github.com/vercel/next.js/blob/canary/packages/next/src/server/app-render/server-inserted-html.tsx\n const serverInsertedCallbacks: (() => React.ReactNode)[] = []\n\n const elementTree = (\n <ServerInsertedHTMLContext.Provider value={handler => serverInsertedCallbacks.push(handler)}>\n {children}\n </ServerInsertedHTMLContext.Provider>\n )\n\n const elementsHTML = await renderToString(elementTree)\n\n const serverInsertedNodes = serverInsertedCallbacks.map((callback, index) => (\n <Fragment key={'__next_server_inserted__' + index}>{callback()}</Fragment>\n ))\n\n const headHTML = await renderToString(serverInsertedNodes)\n\n const dom = new JSDOM(\n `<!DOCTYPE html><head>${headHTML}</head><body><div id=\"root\">${elementsHTML}</div></body></div>`,\n {\n runScripts: 'dangerously',\n },\n )\n\n return dom.window.document\n}\n\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":"AAsDI,cA6EI,YA7EJ;AAtDJ,SAAyB,UAAU,YAAY,QAAQ,gBAAgB,WAAW;AAClF,SAAS,8BAA8B;AACvC,SAAS,aAAa;AACtB,SAAS,QAAQ,cAAc;AAC/B,OAAO;AACP,SAAS,iCAAiC;AAM1C,SAAS,sBAAsB;AAE/B,SAAS,0BAA0B;AACnC,SAAS,YAAY;AACrB,SAAS,gBAAgB;AACzB,YAAY,aAAa;AAEzB,MAAM,UAAU;AAChB,MAAM,aAAa;AAEnB,MAAM,aAAa,CAAC,SAClB,SAAS,SAAY,cAAc,eAAe,IAAI,IAAI,OAAO,KAAK,UAAU,IAAI;AAEtF,MAAM,eAAe,CAAC,SACpB,MAAM,oBAAoB,KAAK,aAAa,qBAAqB,MAAM,eAAe,EAAE;AAE1F,MAAM,uBAAuB,CAAC,SAAkB,SAAS,cAAc,SAAY,KAAK,MAAM,IAAI;AAElG,eAAe,eAAe,QAAwB;AACpD,QAAM,SAAS,OAAO,UAAU;AAChC,QAAM,UAAU,IAAI,YAAY;AAEhC,MAAI,SAAS;AAEb,SAAO,MAAM;AACX,UAAM,EAAE,MAAM,MAAM,IAAI,MAAM,OAAO,KAAK;AAC1C,QAAI;AAAM;AACV,cAAU,QAAQ,OAAO,OAAO,EAAE,QAAQ,KAAK,CAAC;AAAA,EAClD;AAEA,SAAO;AACT;AAEA,eAAe,eAAe,SAAoB;AAChD,SAAO,MAAM,eAAe,MAAM,uBAAuB,OAAO,CAAC;AACnE;AAEA,eAAe,iBAAiB,UAAqB;AAGnD,QAAM,0BAAqD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iBAAiB,OAAO,CAAC,EAAE,IAAI,OAAK,EAAE,WAAW,CAAC,EAAE;AAAA,MACtE;AAAA,IACF;AACA,WAAO,OAAO,YAAY,iBAAiB,GAAG,WAAW,CAAC,EAAE,KAAK,CAAC;AAAA,EACpE;AACF;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../src/next/components/tests/controls/rich-text-v2-control/fixtures.tsx"],"sourcesContent":["import { APIResourceType, type Swatch, type Typography } from '../../../../../api'\n\nimport * as Fixture from '../fixtures/rich-text-v2'\nimport { type CacheData } from '../../../../../api/client'\n\nconst swatchId = 'U3dhdGNoOmJkODYxMWM5LTNiZjItNDM3MS1iMmU4LTBmMmNlMDZjNDE1OA=='\nconst swatch: Swatch = {\n __typename: APIResourceType.Swatch,\n id: swatchId,\n hue: 238,\n saturation: 87,\n lightness: 49,\n}\n\nconst typographyId = 'VHlwb2dyYXBoeTowNGI4OTZlMC0wZWEyLTRkMTMtYmU3ZS0xYmY1M2VmMjBiZjc='\nconst typography: Typography = {\n __typename: APIResourceType.Typography,\n id: typographyId,\n name: 'Body',\n style: [\n {\n deviceId: 'desktop',\n value: {\n fontFamily: 'Lato',\n fontSize: { value: 16, unit: 'px' },\n color: null,\n lineHeight: null,\n letterSpacing: null,\n fontWeight: null,\n textAlign: null,\n uppercase: null,\n underline: null,\n strikethrough: null,\n italic: null,\n },\n },\n ],\n}\n\nexport const value = Fixture.data\nexport const cacheData = (): Partial<CacheData> => ({\n apiResources: {\n Swatch: [\n {\n id: swatchId,\n value: swatch,\n },\n ],\n Typography: [\n {\n id: typographyId,\n value: typography,\n },\n ],\n },\n})\n"],"mappings":"AAAA,SAAS,uBAAqD;AAE9D,YAAY,aAAa;AAGzB,MAAM,WAAW;AACjB,MAAM,SAAiB;AAAA,EACrB,YAAY,gBAAgB;AAAA,EAC5B,IAAI;AAAA,EACJ,KAAK;AAAA,EACL,YAAY;AAAA,EACZ,WAAW;AACb;AAEA,MAAM,eAAe;AACrB,MAAM,aAAyB;AAAA,EAC7B,YAAY,gBAAgB;AAAA,EAC5B,IAAI;AAAA,EACJ,MAAM;AAAA,EACN,OAAO;AAAA,IACL;AAAA,MACE,UAAU;AAAA,MACV,OAAO;AAAA,QACL,YAAY;AAAA,QACZ,UAAU,EAAE,OAAO,IAAI,MAAM,KAAK;AAAA,QAClC,OAAO;AAAA,QACP,YAAY;AAAA,QACZ,eAAe;AAAA,QACf,YAAY;AAAA,QACZ,WAAW;AAAA,QACX,WAAW;AAAA,QACX,WAAW;AAAA,QACX,eAAe;AAAA,QACf,QAAQ;AAAA,MACV;AAAA,IACF;AAAA,EACF;AACF;AAEO,MAAM,QAAQ,QAAQ;AACtB,MAAM,YAAY,OAA2B;AAAA,EAClD,cAAc;AAAA,IACZ,QAAQ;AAAA,MACN;AAAA,QACE,IAAI;AAAA,QACJ,OAAO;AAAA,MACT;AAAA,IACF;AAAA,IACA,YAAY;AAAA,MACV;AAAA,QACE,IAAI;AAAA,QACJ,OAAO;AAAA,MACT;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../src/next/components/tests/controls/rich-text-v2-control/fixtures.tsx"],"sourcesContent":["import { APIResourceType, type Swatch, type Typography } from '../../../../../api'\n\nimport * as Fixture from '../fixtures/rich-text-v2'\nimport { type CacheData } from '../../../../../api/api-resources-client'\n\nconst swatchId = 'U3dhdGNoOmJkODYxMWM5LTNiZjItNDM3MS1iMmU4LTBmMmNlMDZjNDE1OA=='\nconst swatch: Swatch = {\n __typename: APIResourceType.Swatch,\n id: swatchId,\n hue: 238,\n saturation: 87,\n lightness: 49,\n}\n\nconst typographyId = 'VHlwb2dyYXBoeTowNGI4OTZlMC0wZWEyLTRkMTMtYmU3ZS0xYmY1M2VmMjBiZjc='\nconst typography: Typography = {\n __typename: APIResourceType.Typography,\n id: typographyId,\n name: 'Body',\n style: [\n {\n deviceId: 'desktop',\n value: {\n fontFamily: 'Lato',\n fontSize: { value: 16, unit: 'px' },\n color: null,\n lineHeight: null,\n letterSpacing: null,\n fontWeight: null,\n textAlign: null,\n uppercase: null,\n underline: null,\n strikethrough: null,\n italic: null,\n },\n },\n ],\n}\n\nexport const value = Fixture.data\nexport const cacheData = (): Partial<CacheData> => ({\n apiResources: {\n Swatch: [\n {\n id: swatchId,\n value: swatch,\n },\n ],\n Typography: [\n {\n id: typographyId,\n value: typography,\n },\n ],\n },\n})\n"],"mappings":"AAAA,SAAS,uBAAqD;AAE9D,YAAY,aAAa;AAGzB,MAAM,WAAW;AACjB,MAAM,SAAiB;AAAA,EACrB,YAAY,gBAAgB;AAAA,EAC5B,IAAI;AAAA,EACJ,KAAK;AAAA,EACL,YAAY;AAAA,EACZ,WAAW;AACb;AAEA,MAAM,eAAe;AACrB,MAAM,aAAyB;AAAA,EAC7B,YAAY,gBAAgB;AAAA,EAC5B,IAAI;AAAA,EACJ,MAAM;AAAA,EACN,OAAO;AAAA,IACL;AAAA,MACE,UAAU;AAAA,MACV,OAAO;AAAA,QACL,YAAY;AAAA,QACZ,UAAU,EAAE,OAAO,IAAI,MAAM,KAAK;AAAA,QAClC,OAAO;AAAA,QACP,YAAY;AAAA,QACZ,eAAe;AAAA,QACf,YAAY;AAAA,QACZ,WAAW;AAAA,QACX,WAAW;AAAA,QACX,WAAW;AAAA,QACX,eAAe;AAAA,QACf,QAAQ;AAAA,MACV;AAAA,IACF;AAAA,EACF;AACF;AAEO,MAAM,QAAQ,QAAQ;AACtB,MAAM,YAAY,OAA2B;AAAA,EAClD,cAAc;AAAA,IACZ,QAAQ;AAAA,MACN;AAAA,QACE,IAAI;AAAA,QACJ,OAAO;AAAA,MACT;AAAA,IACF;AAAA,IACA,YAAY;AAAA,MACV;AAAA,QACE,IAAI;AAAA,QACJ,OAAO;AAAA,MACT;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { randomUUID } from "crypto";
|
|
2
|
-
import { CacheData } from "../../api/client";
|
|
2
|
+
import { CacheData } from "../../api/api-resources-client";
|
|
3
3
|
import { MakeswiftComponentType } from "../../components/builtin/constants";
|
|
4
4
|
function createRootComponent(elements, rootId) {
|
|
5
5
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/next/testing/element-data.ts"],"sourcesContent":["import { randomUUID } from 'crypto'\n\nimport {\n type MakeswiftPageSnapshot,\n type MakeswiftPageDocument,\n type MakeswiftComponentSnapshot,\n} from '../../client'\nimport { CacheData } from '../../api/client'\nimport { type ElementData } from '../../state/read-only-state'\nimport { MakeswiftComponentType } from '../../components/builtin/constants'\n\nexport function createRootComponent(elements: ElementData[], rootId?: string) {\n return {\n key: rootId ?? randomUUID(),\n type: MakeswiftComponentType.Root,\n props: {\n children: {\n columns: [\n {\n deviceId: 'desktop',\n value: {\n count: 12,\n spans: elements?.map(() => [12]),\n },\n },\n ],\n elements,\n },\n },\n }\n}\n\nconst isDocument = (\n elementDataOrDocument: ElementData | MakeswiftPageDocument,\n): elementDataOrDocument is MakeswiftPageDocument =>\n 'snippets' in elementDataOrDocument ||\n 'fonts' in elementDataOrDocument ||\n 'meta' in elementDataOrDocument ||\n 'seo' in elementDataOrDocument\n\nexport function createMakeswiftPageSnapshot(\n elementDataOrDocument: ElementData | MakeswiftPageDocument,\n {\n cacheData = {},\n locale = null,\n }: { cacheData?: Partial<MakeswiftPageSnapshot['cacheData']>; locale?: string | null } = {},\n): MakeswiftPageSnapshot {\n return {\n document: isDocument(elementDataOrDocument)\n ? elementDataOrDocument\n : {\n id: 'test-page-id',\n site: { id: 'test-site-id' },\n data: elementDataOrDocument,\n snippets: [],\n fonts: [],\n meta: {},\n seo: {},\n localizedPages: [],\n locale,\n },\n cacheData: {\n ...CacheData.empty(),\n ...cacheData,\n },\n }\n}\n\nexport function createMakeswiftComponentSnapshot(\n elementData: ElementData | null,\n {\n cacheData = {},\n locale = null,\n }: { cacheData?: Partial<MakeswiftComponentSnapshot['cacheData']>; locale?: string | null } = {},\n): MakeswiftComponentSnapshot {\n return {\n key: randomUUID(),\n document: {\n id: 'test-component-id',\n name: 'Test Component Document',\n siteId: 'test-site-id',\n data: elementData,\n inheritsFromParent: false,\n locale,\n },\n meta: {\n allowLocaleFallback: false,\n requestedLocale: locale,\n },\n cacheData: {\n ...CacheData.empty(),\n ...cacheData,\n },\n }\n}\n"],"mappings":"AAAA,SAAS,kBAAkB;AAO3B,SAAS,iBAAiB;AAE1B,SAAS,8BAA8B;AAEhC,SAAS,oBAAoB,UAAyB,QAAiB;AAC5E,SAAO;AAAA,IACL,KAAK,UAAU,WAAW;AAAA,IAC1B,MAAM,uBAAuB;AAAA,IAC7B,OAAO;AAAA,MACL,UAAU;AAAA,QACR,SAAS;AAAA,UACP;AAAA,YACE,UAAU;AAAA,YACV,OAAO;AAAA,cACL,OAAO;AAAA,cACP,OAAO,UAAU,IAAI,MAAM,CAAC,EAAE,CAAC;AAAA,YACjC;AAAA,UACF;AAAA,QACF;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;AAEA,MAAM,aAAa,CACjB,0BAEA,cAAc,yBACd,WAAW,yBACX,UAAU,yBACV,SAAS;AAEJ,SAAS,4BACd,uBACA;AAAA,EACE,YAAY,CAAC;AAAA,EACb,SAAS;AACX,IAAyF,CAAC,GACnE;AACvB,SAAO;AAAA,IACL,UAAU,WAAW,qBAAqB,IACtC,wBACA;AAAA,MACE,IAAI;AAAA,MACJ,MAAM,EAAE,IAAI,eAAe;AAAA,MAC3B,MAAM;AAAA,MACN,UAAU,CAAC;AAAA,MACX,OAAO,CAAC;AAAA,MACR,MAAM,CAAC;AAAA,MACP,KAAK,CAAC;AAAA,MACN,gBAAgB,CAAC;AAAA,MACjB;AAAA,IACF;AAAA,IACJ,WAAW;AAAA,MACT,GAAG,UAAU,MAAM;AAAA,MACnB,GAAG;AAAA,IACL;AAAA,EACF;AACF;AAEO,SAAS,iCACd,aACA;AAAA,EACE,YAAY,CAAC;AAAA,EACb,SAAS;AACX,IAA8F,CAAC,GACnE;AAC5B,SAAO;AAAA,IACL,KAAK,WAAW;AAAA,IAChB,UAAU;AAAA,MACR,IAAI;AAAA,MACJ,MAAM;AAAA,MACN,QAAQ;AAAA,MACR,MAAM;AAAA,MACN,oBAAoB;AAAA,MACpB;AAAA,IACF;AAAA,IACA,MAAM;AAAA,MACJ,qBAAqB;AAAA,MACrB,iBAAiB;AAAA,IACnB;AAAA,IACA,WAAW;AAAA,MACT,GAAG,UAAU,MAAM;AAAA,MACnB,GAAG;AAAA,IACL;AAAA,EACF;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../../src/next/testing/element-data.ts"],"sourcesContent":["import { randomUUID } from 'crypto'\n\nimport {\n type MakeswiftPageSnapshot,\n type MakeswiftPageDocument,\n type MakeswiftComponentSnapshot,\n} from '../../client'\nimport { CacheData } from '../../api/api-resources-client'\nimport { type ElementData } from '../../state/read-only-state'\nimport { MakeswiftComponentType } from '../../components/builtin/constants'\n\nexport function createRootComponent(elements: ElementData[], rootId?: string) {\n return {\n key: rootId ?? randomUUID(),\n type: MakeswiftComponentType.Root,\n props: {\n children: {\n columns: [\n {\n deviceId: 'desktop',\n value: {\n count: 12,\n spans: elements?.map(() => [12]),\n },\n },\n ],\n elements,\n },\n },\n }\n}\n\nconst isDocument = (\n elementDataOrDocument: ElementData | MakeswiftPageDocument,\n): elementDataOrDocument is MakeswiftPageDocument =>\n 'snippets' in elementDataOrDocument ||\n 'fonts' in elementDataOrDocument ||\n 'meta' in elementDataOrDocument ||\n 'seo' in elementDataOrDocument\n\nexport function createMakeswiftPageSnapshot(\n elementDataOrDocument: ElementData | MakeswiftPageDocument,\n {\n cacheData = {},\n locale = null,\n }: { cacheData?: Partial<MakeswiftPageSnapshot['cacheData']>; locale?: string | null } = {},\n): MakeswiftPageSnapshot {\n return {\n document: isDocument(elementDataOrDocument)\n ? elementDataOrDocument\n : {\n id: 'test-page-id',\n site: { id: 'test-site-id' },\n data: elementDataOrDocument,\n snippets: [],\n fonts: [],\n meta: {},\n seo: {},\n localizedPages: [],\n locale,\n },\n cacheData: {\n ...CacheData.empty(),\n ...cacheData,\n },\n }\n}\n\nexport function createMakeswiftComponentSnapshot(\n elementData: ElementData | null,\n {\n cacheData = {},\n locale = null,\n }: { cacheData?: Partial<MakeswiftComponentSnapshot['cacheData']>; locale?: string | null } = {},\n): MakeswiftComponentSnapshot {\n return {\n key: randomUUID(),\n document: {\n id: 'test-component-id',\n name: 'Test Component Document',\n siteId: 'test-site-id',\n data: elementData,\n inheritsFromParent: false,\n locale,\n },\n meta: {\n allowLocaleFallback: false,\n requestedLocale: locale,\n },\n cacheData: {\n ...CacheData.empty(),\n ...cacheData,\n },\n }\n}\n"],"mappings":"AAAA,SAAS,kBAAkB;AAO3B,SAAS,iBAAiB;AAE1B,SAAS,8BAA8B;AAEhC,SAAS,oBAAoB,UAAyB,QAAiB;AAC5E,SAAO;AAAA,IACL,KAAK,UAAU,WAAW;AAAA,IAC1B,MAAM,uBAAuB;AAAA,IAC7B,OAAO;AAAA,MACL,UAAU;AAAA,QACR,SAAS;AAAA,UACP;AAAA,YACE,UAAU;AAAA,YACV,OAAO;AAAA,cACL,OAAO;AAAA,cACP,OAAO,UAAU,IAAI,MAAM,CAAC,EAAE,CAAC;AAAA,YACjC;AAAA,UACF;AAAA,QACF;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;AAEA,MAAM,aAAa,CACjB,0BAEA,cAAc,yBACd,WAAW,yBACX,UAAU,yBACV,SAAS;AAEJ,SAAS,4BACd,uBACA;AAAA,EACE,YAAY,CAAC;AAAA,EACb,SAAS;AACX,IAAyF,CAAC,GACnE;AACvB,SAAO;AAAA,IACL,UAAU,WAAW,qBAAqB,IACtC,wBACA;AAAA,MACE,IAAI;AAAA,MACJ,MAAM,EAAE,IAAI,eAAe;AAAA,MAC3B,MAAM;AAAA,MACN,UAAU,CAAC;AAAA,MACX,OAAO,CAAC;AAAA,MACR,MAAM,CAAC;AAAA,MACP,KAAK,CAAC;AAAA,MACN,gBAAgB,CAAC;AAAA,MACjB;AAAA,IACF;AAAA,IACJ,WAAW;AAAA,MACT,GAAG,UAAU,MAAM;AAAA,MACnB,GAAG;AAAA,IACL;AAAA,EACF;AACF;AAEO,SAAS,iCACd,aACA;AAAA,EACE,YAAY,CAAC;AAAA,EACb,SAAS;AACX,IAA8F,CAAC,GACnE;AAC5B,SAAO;AAAA,IACL,KAAK,WAAW;AAAA,IAChB,UAAU;AAAA,MACR,IAAI;AAAA,MACJ,MAAM;AAAA,MACN,QAAQ;AAAA,MACR,MAAM;AAAA,MACN,oBAAoB;AAAA,MACpB;AAAA,IACF;AAAA,IACA,MAAM;AAAA,MACJ,qBAAqB;AAAA,MACrB,iBAAiB;AAAA,IACnB;AAAA,IACA,WAAW;AAAA,MACT,GAAG,UAAU,MAAM;AAAA,MACnB,GAAG;AAAA,IACL;AAAA,EACF;AACF;","names":[]}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { jsx } from "react/jsx-runtime";
|
|
3
3
|
import { useMemo, useSyncExternalStore } from "react";
|
|
4
4
|
import { useIsInBuilder } from "../hooks/use-is-in-builder";
|
|
5
|
-
import {
|
|
5
|
+
import { useApiResourcesClient } from "../hooks/use-api-resources-client";
|
|
6
6
|
import {
|
|
7
7
|
getGoogleFontsParamFromFonts,
|
|
8
8
|
getGoogleFontsParamFromSite,
|
|
@@ -25,7 +25,7 @@ function GoogleFontLink({ fonts, siteId }) {
|
|
|
25
25
|
return /* @__PURE__ */ jsx(PageLink, { precedence: "medium", rel: "stylesheet", href: url });
|
|
26
26
|
}
|
|
27
27
|
function useCachedSite(siteId) {
|
|
28
|
-
const client =
|
|
28
|
+
const client = useApiResourcesClient();
|
|
29
29
|
const getSnapshot = () => siteId == null ? null : client.readSite(siteId);
|
|
30
30
|
return useSyncExternalStore(client.subscribe, getSnapshot, getSnapshot);
|
|
31
31
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/runtimes/react/components/GoogleFontLink.tsx"],"sourcesContent":["'use client'\n\nimport { useMemo, useSyncExternalStore } from 'react'\n\nimport { type Font } from '../../../client'\nimport { type Site } from '../../../api'\nimport { useIsInBuilder } from '../hooks/use-is-in-builder'\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../../../src/runtimes/react/components/GoogleFontLink.tsx"],"sourcesContent":["'use client'\n\nimport { useMemo, useSyncExternalStore } from 'react'\n\nimport { type Font } from '../../../client'\nimport { type Site } from '../../../api'\nimport { useIsInBuilder } from '../hooks/use-is-in-builder'\nimport { useApiResourcesClient } from '../hooks/use-api-resources-client'\n\nimport {\n getGoogleFontsParamFromFonts,\n getGoogleFontsParamFromSite,\n getGoogleFontsUrl,\n} from '../utils/google-fonts-url'\nimport { PageLink } from './page/head-tags'\n\ntype Props = {\n fonts: Font[]\n siteId: string | null\n}\n\n/**\n * This is experimental, and some of the logic here is duplicated in the `PageHead` component.\n *\n * For now we want to avoid putting this on the critical path for rendering Makeswift pages, so we haven't\n * deduplicated the two.\n */\nexport function GoogleFontLink({ fonts, siteId }: Props) {\n const isInBuilder = useIsInBuilder()\n\n const site = useCachedSite(isInBuilder ? siteId : null)\n\n const fontFamilyParamValue = useMemo(() => {\n if (isInBuilder && site != null) {\n return getGoogleFontsParamFromSite(site)\n }\n return getGoogleFontsParamFromFonts(fonts)\n }, [isInBuilder, site, fonts])\n\n const url = getGoogleFontsUrl(fontFamilyParamValue)\n if (url === '') {\n return null\n }\n\n return <PageLink precedence=\"medium\" rel=\"stylesheet\" href={url} />\n}\n\nfunction useCachedSite(siteId: string | null): Site | null {\n const client = useApiResourcesClient()\n const getSnapshot = () => (siteId == null ? null : client.readSite(siteId))\n\n return useSyncExternalStore(client.subscribe, getSnapshot, getSnapshot)\n}\n"],"mappings":";AA4CS;AA1CT,SAAS,SAAS,4BAA4B;AAI9C,SAAS,sBAAsB;AAC/B,SAAS,6BAA6B;AAEtC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,gBAAgB;AAalB,SAAS,eAAe,EAAE,OAAO,OAAO,GAAU;AACvD,QAAM,cAAc,eAAe;AAEnC,QAAM,OAAO,cAAc,cAAc,SAAS,IAAI;AAEtD,QAAM,uBAAuB,QAAQ,MAAM;AACzC,QAAI,eAAe,QAAQ,MAAM;AAC/B,aAAO,4BAA4B,IAAI;AAAA,IACzC;AACA,WAAO,6BAA6B,KAAK;AAAA,EAC3C,GAAG,CAAC,aAAa,MAAM,KAAK,CAAC;AAE7B,QAAM,MAAM,kBAAkB,oBAAoB;AAClD,MAAI,QAAQ,IAAI;AACd,WAAO;AAAA,EACT;AAEA,SAAO,oBAAC,YAAS,YAAW,UAAS,KAAI,cAAa,MAAM,KAAK;AACnE;AAEA,SAAS,cAAc,QAAoC;AACzD,QAAM,SAAS,sBAAsB;AACrC,QAAM,cAAc,MAAO,UAAU,OAAO,OAAO,OAAO,SAAS,MAAM;AAEzE,SAAO,qBAAqB,OAAO,WAAW,aAAa,WAAW;AACxE;","names":[]}
|
|
@@ -2,7 +2,7 @@ import { useEffect, useMemo, useState, useSyncExternalStore } from "react";
|
|
|
2
2
|
import { SnippetLocation } from "../../../../client";
|
|
3
3
|
import deepEqual from "../../../../utils/deepEqual";
|
|
4
4
|
import { useIsInBuilder } from "../../hooks/use-is-in-builder";
|
|
5
|
-
import {
|
|
5
|
+
import { useApiResourcesClient } from "../../hooks/use-api-resources-client";
|
|
6
6
|
const filterUsedSnippetProperties = ({
|
|
7
7
|
code,
|
|
8
8
|
builderEnabled,
|
|
@@ -44,7 +44,7 @@ function usePageSnippets({ page }) {
|
|
|
44
44
|
return { headSnippets, bodySnippets };
|
|
45
45
|
}
|
|
46
46
|
function useCachedPage(pageId) {
|
|
47
|
-
const client =
|
|
47
|
+
const client = useApiResourcesClient();
|
|
48
48
|
const getSnapshot = () => pageId == null ? null : client.readPage(pageId);
|
|
49
49
|
const page = useSyncExternalStore(client.subscribe, getSnapshot, getSnapshot);
|
|
50
50
|
return page;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../src/runtimes/react/components/hooks/use-page-snippets.ts"],"sourcesContent":["import { useEffect, useMemo, useState, useSyncExternalStore } from 'react'\n\nimport { type MakeswiftPageDocument, type Snippet, SnippetLocation } from '../../../../client'\nimport { type Page as PageType } from '../../../../api'\n\nimport deepEqual from '../../../../utils/deepEqual'\n\nimport { useIsInBuilder } from '../../hooks/use-is-in-builder'\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../../../../src/runtimes/react/components/hooks/use-page-snippets.ts"],"sourcesContent":["import { useEffect, useMemo, useState, useSyncExternalStore } from 'react'\n\nimport { type MakeswiftPageDocument, type Snippet, SnippetLocation } from '../../../../client'\nimport { type Page as PageType } from '../../../../api'\n\nimport deepEqual from '../../../../utils/deepEqual'\n\nimport { useIsInBuilder } from '../../hooks/use-is-in-builder'\nimport { useApiResourcesClient } from '../../hooks/use-api-resources-client'\n\nconst filterUsedSnippetProperties = ({\n code,\n builderEnabled,\n liveEnabled,\n location,\n cleanup,\n}: Snippet) => ({\n code,\n builderEnabled,\n liveEnabled,\n location,\n cleanup,\n})\n\nexport function usePageSnippets({ page }: { page: MakeswiftPageDocument }) {\n const isInBuilder = useIsInBuilder()\n const [snippets, setSnippets] = useState(page.snippets)\n\n // We're using cached results here for page snippets so that anytime the user\n // changes the snippets or fonts on the builder, the change would be reflected\n // here. See this PR for discussions and things we can do to improve it in the\n // future: https://github.com/makeswift/makeswift/pull/77\n const cachedPage = useCachedPage(isInBuilder ? page.id : null)\n useEffect(() => {\n if (cachedPage == null) return\n\n const oldSnippets = snippets.map(filterUsedSnippetProperties)\n const newSnippets = cachedPage.snippets.map(filterUsedSnippetProperties)\n\n if (deepEqual(newSnippets, oldSnippets)) return\n\n setSnippets(cachedPage.snippets)\n }, [cachedPage])\n\n const filteredSnippets = useMemo(\n () => snippets.filter(snippet => (isInBuilder ? snippet.builderEnabled : snippet.liveEnabled)),\n [snippets, isInBuilder],\n )\n\n const headSnippets = useMemo(\n () => filteredSnippets.filter(snippet => snippet.location === SnippetLocation.Head),\n [filteredSnippets],\n )\n\n const bodySnippets = useMemo(\n () => filteredSnippets.filter(snippet => snippet.location === SnippetLocation.Body),\n [filteredSnippets],\n )\n\n return { headSnippets, bodySnippets }\n}\n\nfunction useCachedPage(pageId: string | null): PageType | null {\n const client = useApiResourcesClient()\n const getSnapshot = () => (pageId == null ? null : client.readPage(pageId))\n\n const page = useSyncExternalStore(client.subscribe, getSnapshot, getSnapshot)\n\n return page\n}\n"],"mappings":"AAAA,SAAS,WAAW,SAAS,UAAU,4BAA4B;AAEnE,SAAmD,uBAAuB;AAG1E,OAAO,eAAe;AAEtB,SAAS,sBAAsB;AAC/B,SAAS,6BAA6B;AAEtC,MAAM,8BAA8B,CAAC;AAAA,EACnC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,OAAgB;AAAA,EACd;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEO,SAAS,gBAAgB,EAAE,KAAK,GAAoC;AACzE,QAAM,cAAc,eAAe;AACnC,QAAM,CAAC,UAAU,WAAW,IAAI,SAAS,KAAK,QAAQ;AAMtD,QAAM,aAAa,cAAc,cAAc,KAAK,KAAK,IAAI;AAC7D,YAAU,MAAM;AACd,QAAI,cAAc;AAAM;AAExB,UAAM,cAAc,SAAS,IAAI,2BAA2B;AAC5D,UAAM,cAAc,WAAW,SAAS,IAAI,2BAA2B;AAEvE,QAAI,UAAU,aAAa,WAAW;AAAG;AAEzC,gBAAY,WAAW,QAAQ;AAAA,EACjC,GAAG,CAAC,UAAU,CAAC;AAEf,QAAM,mBAAmB;AAAA,IACvB,MAAM,SAAS,OAAO,aAAY,cAAc,QAAQ,iBAAiB,QAAQ,WAAY;AAAA,IAC7F,CAAC,UAAU,WAAW;AAAA,EACxB;AAEA,QAAM,eAAe;AAAA,IACnB,MAAM,iBAAiB,OAAO,aAAW,QAAQ,aAAa,gBAAgB,IAAI;AAAA,IAClF,CAAC,gBAAgB;AAAA,EACnB;AAEA,QAAM,eAAe;AAAA,IACnB,MAAM,iBAAiB,OAAO,aAAW,QAAQ,aAAa,gBAAgB,IAAI;AAAA,IAClF,CAAC,gBAAgB;AAAA,EACnB;AAEA,SAAO,EAAE,cAAc,aAAa;AACtC;AAEA,SAAS,cAAc,QAAwC;AAC7D,QAAM,SAAS,sBAAsB;AACrC,QAAM,cAAc,MAAO,UAAU,OAAO,OAAO,OAAO,SAAS,MAAM;AAEzE,QAAM,OAAO,qBAAqB,OAAO,WAAW,aAAa,WAAW;AAE5E,SAAO;AACT;","names":[]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useMemo, useSyncExternalStore } from "react";
|
|
3
|
-
import {
|
|
3
|
+
import { useApiResourcesClient } from "../../hooks/use-api-resources-client";
|
|
4
4
|
import { useFrameworkContext } from "../hooks/use-framework-context";
|
|
5
5
|
import { useIsInBuilder } from "../../hooks/use-is-in-builder";
|
|
6
6
|
import { usePageSnippets } from "../hooks/use-page-snippets";
|
|
@@ -86,7 +86,7 @@ function PageHead({ document: page, metadata = {} }) {
|
|
|
86
86
|
] });
|
|
87
87
|
}
|
|
88
88
|
function useCachedSite(siteId) {
|
|
89
|
-
const client =
|
|
89
|
+
const client = useApiResourcesClient();
|
|
90
90
|
const getSnapshot = () => siteId == null ? null : client.readSite(siteId);
|
|
91
91
|
const site = useSyncExternalStore(client.subscribe, getSnapshot, getSnapshot);
|
|
92
92
|
return site;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../src/runtimes/react/components/page/PageHead.tsx"],"sourcesContent":["import { useMemo, useSyncExternalStore, ReactNode } from 'react'\n\nimport { type MakeswiftPageDocument } from '../../../../client'\nimport { type Site } from '../../../../api'\n\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../../../../src/runtimes/react/components/page/PageHead.tsx"],"sourcesContent":["import { useMemo, useSyncExternalStore, ReactNode } from 'react'\n\nimport { type MakeswiftPageDocument } from '../../../../client'\nimport { type Site } from '../../../../api'\n\nimport { useApiResourcesClient } from '../../hooks/use-api-resources-client'\nimport { useFrameworkContext } from '../hooks/use-framework-context'\nimport { useIsInBuilder } from '../../hooks/use-is-in-builder'\nimport { usePageSnippets } from '../hooks/use-page-snippets'\n\nimport { PageTitle, PageMeta, PageLink, PageStyle } from './head-tags'\nimport { type PageMetadataSettings } from './page-seo-settings'\n\nconst defaultFavicon = {\n id: 'default-favicon',\n mimetype: 'image/png',\n publicUrl:\n 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACIAAAAiCAYAAAA6RwvCAAAACXBIWXMAABcRAAAXEQHKJvM/AAABjElEQVRYhc2XzU3EMBCFB8TddAAXn6EE6GCpgNABZ1/IXnymBOgAOmA7YM8+ABVsXEHQQFaKQryeN3Yk3ilKJtEnv/nLUd/3pFG0riGi88yrnQn+UfJ5FUi0riWiB2H4nQn+KRd0DFP8agXEfkqCYJBoHdtxIQxfm+DfFgEhoith3NYE30o/qgGR2BJB+xY7kdYEL8oNFUi0jiFMJuxVWrJqEMFxsyUNCsE6AeNztvBp7aJ143vXksoRnwhYtmNdSoIQa6RlO9YXEWW7KgoCleOgxgTf1QZBT+RZ2lXFING6UxCCq+ceeUE8fYdknY599v9sJvzGBP+yCEgC7GPmETc0OJ+0awAlkhe2pAbIXAeFZ8xe2g2Nk3c3ub0xwWt6zY9qbmiqGVMbZK21ZC/YmhlbeBMTzZNDQqcvDb1kM1x32iqZSt1HaqukfKvq34BAOTLsrH+ETNmUkKHHA+428RgeclPVWozeSyAI2EdWB34jtqXNTAySOY3i/KgFIlqOa4GkFmBegorzg4joG07he/M7zl6jAAAAAElFTkSuQmCC',\n}\n\ntype Props = {\n document: MakeswiftPageDocument\n metadata?: PageMetadataSettings\n}\n\nexport function PageHead({ document: page, metadata = {} }: Props): ReactNode {\n const {\n title: useTitle = false,\n favicon: useFavicon = false,\n canonicalUrl: useCanonicalUrl = false,\n indexingBlocked: useIndexingBlocked = false,\n description: useDescription = false,\n keywords: useKeywords = false,\n socialImage: useSocialImage = false,\n } = metadata\n\n const { headSnippets } = usePageSnippets({ page })\n const { HeadSnippet } = useFrameworkContext()\n\n const isInBuilder = useIsInBuilder()\n\n const site = useCachedSite(isInBuilder ? page.site.id : null)\n const baseLocalizedPage = page.localizedPages.find(({ parentId }) => parentId == null)\n\n const favicon = page.meta.favicon ?? defaultFavicon\n const title = baseLocalizedPage?.meta.title ?? page.meta.title\n const description = baseLocalizedPage?.meta.description ?? page.meta.description\n const keywords = baseLocalizedPage?.meta.keywords ?? page.meta.keywords\n const socialImage = baseLocalizedPage?.meta.socialImage ?? page.meta.socialImage\n const canonicalUrl = baseLocalizedPage?.seo.canonicalUrl ?? page.seo.canonicalUrl\n const isIndexingBlocked = baseLocalizedPage?.seo.isIndexingBlocked ?? page.seo.isIndexingBlocked\n\n const fontFamilyParamValue = useMemo(() => {\n if (site == null) {\n return page.fonts\n .map(({ family, variants }) => {\n return `${family.replace(/ /g, '+')}:${variants.join()}`\n })\n .join('|')\n }\n\n return site.googleFonts.edges\n .filter((edge): edge is NonNullable<typeof edge> => edge != null)\n .map(({ activeVariants, node: { family, variants } }) => {\n const activeVariantSpecifiers = variants\n .filter(variant =>\n activeVariants.some(activeVariant => activeVariant.specifier === variant.specifier),\n )\n .map(variant => variant.specifier)\n .join()\n\n return `${family.replace(/ /g, '+')}:${activeVariantSpecifiers}`\n })\n .join('|')\n }, [site, page])\n\n return (\n <>\n <PageStyle precedence=\"high\" href=\"makeswift-base-styles\">\n {`\n html {\n font-family: sans-serif;\n }\n div#__next {\n overflow: hidden;\n }\n `}\n </PageStyle>\n {useTitle && title && (\n <>\n <PageTitle>{title}</PageTitle>\n <PageMeta property=\"og:title\" content={title} />\n <PageMeta name=\"twitter:title\" content={title} />\n </>\n )}\n {useFavicon && favicon && (\n <PageLink rel=\"icon\" type={favicon.mimetype} href={favicon.publicUrl} />\n )}\n {useCanonicalUrl && canonicalUrl && <PageLink rel=\"canonical\" href={canonicalUrl} />}\n {useIndexingBlocked && isIndexingBlocked && <PageMeta name=\"robots\" content=\"noindex\" />}\n {useDescription && description && (\n <>\n <PageMeta name=\"description\" content={description} />\n <PageMeta property=\"og:description\" content={description} />\n <PageMeta name=\"twitter:description\" content={description} />\n </>\n )}\n {useKeywords && keywords && <PageMeta name=\"keywords\" content={keywords} />}\n {useSocialImage && socialImage && (\n <>\n <PageMeta property=\"og:image\" content={socialImage.publicUrl} />\n <PageMeta property=\"og:image:type\" content={socialImage.mimetype} />\n <PageMeta name=\"twitter:image\" content={socialImage.publicUrl} />\n <PageMeta name=\"twitter:card\" content=\"summary_large_image\" />\n </>\n )}\n {fontFamilyParamValue !== '' && (\n <PageLink\n precedence=\"medium\"\n rel=\"stylesheet\"\n href={`https://fonts.googleapis.com/css?family=${fontFamilyParamValue}&display=swap`}\n />\n )}\n {headSnippets.map(snippet => (\n <HeadSnippet key={snippet.id} snippet={snippet} />\n ))}\n </>\n )\n}\n\nfunction useCachedSite(siteId: string | null): Site | null {\n const client = useApiResourcesClient()\n const getSnapshot = () => (siteId == null ? null : client.readSite(siteId))\n\n const site = useSyncExternalStore(client.subscribe, getSnapshot, getSnapshot)\n\n return site\n}\n"],"mappings":"AA8EM,SAWE,UAXF,KAWE,YAXF;AA9EN,SAAS,SAAS,4BAAuC;AAKzD,SAAS,6BAA6B;AACtC,SAAS,2BAA2B;AACpC,SAAS,sBAAsB;AAC/B,SAAS,uBAAuB;AAEhC,SAAS,WAAW,UAAU,UAAU,iBAAiB;AAGzD,MAAM,iBAAiB;AAAA,EACrB,IAAI;AAAA,EACJ,UAAU;AAAA,EACV,WACE;AACJ;AAOO,SAAS,SAAS,EAAE,UAAU,MAAM,WAAW,CAAC,EAAE,GAAqB;AAC5E,QAAM;AAAA,IACJ,OAAO,WAAW;AAAA,IAClB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ACxB;AAAA,MAAC;AAAA;AAAA,QACC,YAAW;AAAA,QACX,KAAI;AAAA,QACJ,MAAM,2CAA2C,oBAAoB;AAAA;AAAA,IACvE;AAAA,IAED,aAAa,IAAI,aAChB,oBAAC,eAA6B,WAAZ,QAAQ,EAAsB,CACjD;AAAA,KACH;AAEJ;AAEA,SAAS,cAAc,QAAoC;AACzD,QAAM,SAAS,sBAAsB;AACrC,QAAM,cAAc,MAAO,UAAU,OAAO,OAAO,OAAO,SAAS,MAAM;AAEzE,QAAM,OAAO,qBAAqB,OAAO,WAAW,aAAa,WAAW;AAE5E,SAAO;AACT;","names":[]}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { useEffect, useRef, useSyncExternalStore } from "react";
|
|
3
|
-
import {
|
|
3
|
+
import { useApiResourcesClient } from "./use-api-resources-client";
|
|
4
4
|
import { useDocumentLocale } from "./use-document-context";
|
|
5
5
|
function useSwatch(swatchId) {
|
|
6
|
-
const client =
|
|
6
|
+
const client = useApiResourcesClient();
|
|
7
7
|
const readSwatch = () => swatchId == null ? null : client.readSwatch(swatchId);
|
|
8
8
|
const swatch = useSyncExternalStore(client.subscribe, readSwatch, readSwatch);
|
|
9
9
|
useEffect(() => {
|
|
@@ -13,7 +13,7 @@ function useSwatch(swatchId) {
|
|
|
13
13
|
return swatch;
|
|
14
14
|
}
|
|
15
15
|
function useSwatches(swatchIds) {
|
|
16
|
-
const client =
|
|
16
|
+
const client = useApiResourcesClient();
|
|
17
17
|
const lastSnapshot = useRef(null);
|
|
18
18
|
function getSnapshot() {
|
|
19
19
|
const swatches2 = swatchIds.map((swatchId) => client.readSwatch(swatchId));
|
|
@@ -29,7 +29,7 @@ function useSwatches(swatchIds) {
|
|
|
29
29
|
return swatches;
|
|
30
30
|
}
|
|
31
31
|
function useFile(fileId) {
|
|
32
|
-
const client =
|
|
32
|
+
const client = useApiResourcesClient();
|
|
33
33
|
const readFile = () => fileId == null ? null : client.readFile(fileId);
|
|
34
34
|
const file = useSyncExternalStore(client.subscribe, readFile, readFile);
|
|
35
35
|
useEffect(() => {
|
|
@@ -39,7 +39,7 @@ function useFile(fileId) {
|
|
|
39
39
|
return file;
|
|
40
40
|
}
|
|
41
41
|
function useFiles(fileIds) {
|
|
42
|
-
const client =
|
|
42
|
+
const client = useApiResourcesClient();
|
|
43
43
|
const lastSnapshot = useRef(null);
|
|
44
44
|
function getSnapshot() {
|
|
45
45
|
const files2 = fileIds.map((fileId) => client.readFile(fileId));
|
|
@@ -55,7 +55,7 @@ function useFiles(fileIds) {
|
|
|
55
55
|
return files;
|
|
56
56
|
}
|
|
57
57
|
function useTypography(typographyId) {
|
|
58
|
-
const client =
|
|
58
|
+
const client = useApiResourcesClient();
|
|
59
59
|
const readTypography = () => typographyId == null ? null : client.readTypography(typographyId);
|
|
60
60
|
const typography = useSyncExternalStore(client.subscribe, readTypography, readTypography);
|
|
61
61
|
useEffect(() => {
|
|
@@ -65,7 +65,7 @@ function useTypography(typographyId) {
|
|
|
65
65
|
return typography;
|
|
66
66
|
}
|
|
67
67
|
function useGlobalElement(globalElementId) {
|
|
68
|
-
const client =
|
|
68
|
+
const client = useApiResourcesClient();
|
|
69
69
|
const readGlobalElement = () => globalElementId == null ? null : client.readGlobalElement(globalElementId);
|
|
70
70
|
const globalElement = useSyncExternalStore(client.subscribe, readGlobalElement, readGlobalElement);
|
|
71
71
|
useEffect(() => {
|
|
@@ -75,7 +75,7 @@ function useGlobalElement(globalElementId) {
|
|
|
75
75
|
return globalElement;
|
|
76
76
|
}
|
|
77
77
|
function useLocalizedGlobalElement(locale, globalElementId) {
|
|
78
|
-
const client =
|
|
78
|
+
const client = useApiResourcesClient();
|
|
79
79
|
const readLocalizedGlobalElement = () => locale == null || globalElementId == null ? null : client.readLocalizedGlobalElement({ globalElementId, locale });
|
|
80
80
|
const localizedGlobalElement = useSyncExternalStore(
|
|
81
81
|
client.subscribe,
|
|
@@ -90,7 +90,7 @@ function useLocalizedGlobalElement(locale, globalElementId) {
|
|
|
90
90
|
return localizedGlobalElement;
|
|
91
91
|
}
|
|
92
92
|
function usePagePathnameSlice(pageId) {
|
|
93
|
-
const client =
|
|
93
|
+
const client = useApiResourcesClient();
|
|
94
94
|
const locale = useDocumentLocale();
|
|
95
95
|
const readPagePathnameSlice = () => pageId == null ? null : client.readPagePathnameSlice({ pageId, locale });
|
|
96
96
|
const pagePathnameSlice = useSyncExternalStore(
|
|
@@ -105,7 +105,7 @@ function usePagePathnameSlice(pageId) {
|
|
|
105
105
|
return pagePathnameSlice;
|
|
106
106
|
}
|
|
107
107
|
function useTable(tableId) {
|
|
108
|
-
const client =
|
|
108
|
+
const client = useApiResourcesClient();
|
|
109
109
|
const readTable = () => tableId == null ? null : client.readTable(tableId);
|
|
110
110
|
const table = useSyncExternalStore(client.subscribe, readTable, readTable);
|
|
111
111
|
useEffect(() => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/runtimes/react/hooks/makeswift-api.ts"],"sourcesContent":["'use client'\n\nimport { useEffect, useRef, useSyncExternalStore } from 'react'\nimport {\n File,\n GlobalElement,\n LocalizedGlobalElement,\n PagePathnameSlice,\n Swatch,\n Table,\n Typography,\n} from '../../../api'\n\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../../../src/runtimes/react/hooks/makeswift-api.ts"],"sourcesContent":["'use client'\n\nimport { useEffect, useRef, useSyncExternalStore } from 'react'\nimport {\n File,\n GlobalElement,\n LocalizedGlobalElement,\n PagePathnameSlice,\n Swatch,\n Table,\n Typography,\n} from '../../../api'\n\nimport { useApiResourcesClient } from './use-api-resources-client'\nimport { useDocumentLocale } from './use-document-context'\n\nexport function useSwatch(swatchId: string | null): Swatch | null {\n const client = useApiResourcesClient()\n const readSwatch = () => (swatchId == null ? null : client.readSwatch(swatchId))\n const swatch = useSyncExternalStore(client.subscribe, readSwatch, readSwatch)\n\n useEffect(() => {\n if (swatchId != null) client.fetchSwatch(swatchId).catch(console.error)\n }, [client, swatchId])\n\n return swatch\n}\n\nexport function useSwatches(swatchIds: string[]): (Swatch | null)[] {\n const client = useApiResourcesClient()\n const lastSnapshot = useRef<(Swatch | null)[] | null>(null)\n\n function getSnapshot() {\n const swatches = swatchIds.map(swatchId => client.readSwatch(swatchId))\n\n if (\n lastSnapshot.current != null &&\n lastSnapshot.current.length === swatches.length &&\n lastSnapshot.current.every((swatch, idx) => swatches[idx] === swatch)\n ) {\n return lastSnapshot.current\n }\n\n return (lastSnapshot.current = swatches)\n }\n\n const swatches = useSyncExternalStore(client.subscribe, getSnapshot, getSnapshot)\n\n useEffect(() => {\n Promise.all(swatchIds.map(swatchId => client.fetchSwatch(swatchId))).catch(console.error)\n }, [client, swatchIds])\n\n return swatches\n}\n\nexport function useFile(fileId: string | null): File | null {\n const client = useApiResourcesClient()\n const readFile = () => (fileId == null ? null : client.readFile(fileId))\n const file = useSyncExternalStore(client.subscribe, readFile, readFile)\n\n useEffect(() => {\n if (fileId != null) client.fetchFile(fileId)\n }, [client, fileId])\n\n return file\n}\n\nexport function useFiles(fileIds: string[]): (File | null)[] {\n const client = useApiResourcesClient()\n const lastSnapshot = useRef<(File | null)[] | null>(null)\n\n function getSnapshot() {\n const files = fileIds.map(fileId => client.readFile(fileId))\n\n if (\n lastSnapshot.current != null &&\n lastSnapshot.current.length === files.length &&\n lastSnapshot.current.every((file, idx) => files[idx] === file)\n ) {\n return lastSnapshot.current\n }\n\n return (lastSnapshot.current = files)\n }\n\n const files = useSyncExternalStore(client.subscribe, getSnapshot, getSnapshot)\n\n useEffect(() => {\n Promise.all(fileIds.map(fileId => client.fetchFile(fileId))).catch(console.error)\n }, [client, fileIds])\n\n return files\n}\n\nexport function useTypography(typographyId: string | null): Typography | null {\n const client = useApiResourcesClient()\n const readTypography = () => (typographyId == null ? null : client.readTypography(typographyId))\n const typography = useSyncExternalStore(client.subscribe, readTypography, readTypography)\n\n useEffect(() => {\n if (typographyId != null) client.fetchTypography(typographyId).catch(console.error)\n }, [client, typographyId])\n\n return typography\n}\n\nexport function useGlobalElement(globalElementId: string | null): GlobalElement | null {\n const client = useApiResourcesClient()\n const readGlobalElement = () =>\n globalElementId == null ? null : client.readGlobalElement(globalElementId)\n const globalElement = useSyncExternalStore(client.subscribe, readGlobalElement, readGlobalElement)\n\n useEffect(() => {\n if (globalElementId != null) client.fetchGlobalElement(globalElementId).catch(console.error)\n }, [client, globalElementId])\n\n return globalElement\n}\n\nexport function useLocalizedGlobalElement(\n locale: string | null,\n globalElementId: string | null,\n): LocalizedGlobalElement | null {\n const client = useApiResourcesClient()\n const readLocalizedGlobalElement = () =>\n locale == null || globalElementId == null\n ? null\n : client.readLocalizedGlobalElement({ globalElementId, locale })\n\n const localizedGlobalElement = useSyncExternalStore(\n client.subscribe,\n readLocalizedGlobalElement,\n readLocalizedGlobalElement,\n )\n\n useEffect(() => {\n if (locale != null && globalElementId != null) {\n client.fetchLocalizedGlobalElement({ globalElementId, locale }).catch(console.error)\n }\n }, [client, locale, globalElementId])\n\n return localizedGlobalElement\n}\n\nexport function usePagePathnameSlice(pageId: string | null): PagePathnameSlice | null {\n const client = useApiResourcesClient()\n const locale = useDocumentLocale()\n\n const readPagePathnameSlice = () =>\n pageId == null ? null : client.readPagePathnameSlice({ pageId, locale })\n\n const pagePathnameSlice = useSyncExternalStore(\n client.subscribe,\n readPagePathnameSlice,\n readPagePathnameSlice,\n )\n\n useEffect(() => {\n if (pageId != null) client.fetchPagePathnameSlice({ pageId, locale }).catch(console.error)\n }, [client, pageId, locale])\n\n return pagePathnameSlice\n}\n\nexport function useTable(tableId: string | null): Table | null {\n const client = useApiResourcesClient()\n const readTable = () => (tableId == null ? null : client.readTable(tableId))\n const table = useSyncExternalStore(client.subscribe, readTable, readTable)\n\n useEffect(() => {\n if (tableId != null) client.fetchTable(tableId).catch(console.error)\n }, [client, tableId])\n\n return table\n}\n"],"mappings":";AAEA,SAAS,WAAW,QAAQ,4BAA4B;AAWxD,SAAS,6BAA6B;AACtC,SAAS,yBA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hooks/use-api-resources-client.tsx"],"sourcesContent":["'use client'\n\nimport { ApiResourcesClient } from '../../../api/api-resources-client'\n\nimport { useStore } from './use-store'\n\nexport function useApiResourcesClient(): ApiResourcesClient {\n return useStore().apiResourcesClient\n}\n"],"mappings":";AAIA,SAAS,gBAAgB;AAElB,SAAS,wBAA4C;AAC1D,SAAO,SAAS,EAAE;AACpB;","names":[]}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { useMemo } from "react";
|
|
2
2
|
import { updateAPIClientCache } from "../../../state/actions/internal/read-write-actions";
|
|
3
|
-
import {
|
|
3
|
+
import { useApiResourcesClient } from "./use-api-resources-client";
|
|
4
4
|
function useCacheData(cacheData) {
|
|
5
|
-
const { store: apiStore } =
|
|
5
|
+
const { store: apiStore } = useApiResourcesClient();
|
|
6
6
|
useMemo(() => apiStore.dispatch(updateAPIClientCache(cacheData)), [cacheData]);
|
|
7
7
|
}
|
|
8
8
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/runtimes/react/hooks/use-cache-data.ts"],"sourcesContent":["import { useMemo } from 'react'\nimport { type CacheData } from '../../../api/client'\nimport { updateAPIClientCache } from '../../../state/actions/internal/read-write-actions'\n\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../../../src/runtimes/react/hooks/use-cache-data.ts"],"sourcesContent":["import { useMemo } from 'react'\nimport { type CacheData } from '../../../api/api-resources-client'\nimport { updateAPIClientCache } from '../../../state/actions/internal/read-write-actions'\n\nimport { useApiResourcesClient } from './use-api-resources-client'\n\nexport function useCacheData(cacheData: CacheData) {\n const { store: apiStore } = useApiResourcesClient()\n\n // We perform cache hydration immediately on render - this is safe to do per\n // render because updating the API cache is idempotent. For precedence, see:\n //\n // https://github.com/TanStack/query/blob/8f9f183f11df3709a1a38c4efce1452788041f88/packages/react-query/src/HydrationBoundary.tsx#L41\n useMemo(() => apiStore.dispatch(updateAPIClientCache(cacheData)), [cacheData])\n}\n"],"mappings":"AAAA,SAAS,eAAe;AAExB,SAAS,4BAA4B;AAErC,SAAS,6BAA6B;AAE/B,SAAS,aAAa,WAAsB;AACjD,QAAM,EAAE,OAAO,SAAS,IAAI,sBAAsB;AAMlD,UAAQ,MAAM,SAAS,SAAS,qBAAqB,SAAS,CAAC,GAAG,CAAC,SAAS,CAAC;AAC/E;","names":[]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { MakeswiftGraphQLApiClient } from "../../../api/graphql-api-client";
|
|
3
|
+
import { useReactRuntime } from "./use-react-runtime";
|
|
4
|
+
function useMakeswiftGraphQLApiClient() {
|
|
5
|
+
const runtime = useReactRuntime();
|
|
6
|
+
return new MakeswiftGraphQLApiClient({ endpoint: runtime.graphqlApiEndpoint });
|
|
7
|
+
}
|
|
8
|
+
export {
|
|
9
|
+
useMakeswiftGraphQLApiClient
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=use-graphql-api-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/runtimes/react/hooks/use-graphql-api-client.tsx"],"sourcesContent":["'use client'\n\nimport { MakeswiftGraphQLApiClient } from '../../../api/graphql-api-client'\n\nimport { useReactRuntime } from './use-react-runtime'\n\nexport function useMakeswiftGraphQLApiClient(): MakeswiftGraphQLApiClient {\n const runtime = useReactRuntime()\n return new MakeswiftGraphQLApiClient({ endpoint: runtime.graphqlApiEndpoint })\n}\n"],"mappings":";AAEA,SAAS,iCAAiC;AAE1C,SAAS,uBAAuB;AAEzB,SAAS,+BAA0D;AACxE,QAAM,UAAU,gBAAgB;AAChC,SAAO,IAAI,0BAA0B,EAAE,UAAU,QAAQ,mBAAmB,CAAC;AAC/E;","names":[]}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { useMemo } from "react";
|
|
2
|
-
import { useMakeswiftHostApiClient } from "../host-api-client";
|
|
3
2
|
import { createResourceResolver } from "../resource-resolver";
|
|
4
|
-
import {
|
|
3
|
+
import { useApiResourcesClient } from "./use-api-resources-client";
|
|
5
4
|
import { useDocumentKey, useDocumentLocale } from "./use-document-context";
|
|
5
|
+
import { useStore } from "./use-store";
|
|
6
6
|
function useResourceResolver() {
|
|
7
7
|
const store = useStore();
|
|
8
|
-
const apiClient =
|
|
8
|
+
const apiClient = useApiResourcesClient();
|
|
9
9
|
const documentKey = useDocumentKey();
|
|
10
10
|
const locale = useDocumentLocale();
|
|
11
11
|
return useMemo(
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/runtimes/react/hooks/use-resource-resolver.ts"],"sourcesContent":["import { useMemo } from 'react'\nimport { type ResourceResolver } from '@makeswift/controls'\n\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../../../src/runtimes/react/hooks/use-resource-resolver.ts"],"sourcesContent":["import { useMemo } from 'react'\nimport { type ResourceResolver } from '@makeswift/controls'\n\nimport { createResourceResolver } from '../resource-resolver'\n\nimport { useApiResourcesClient } from './use-api-resources-client'\nimport { useDocumentKey, useDocumentLocale } from './use-document-context'\nimport { useStore } from './use-store'\n\nexport function useResourceResolver(): ResourceResolver {\n const store = useStore()\n const apiClient = useApiResourcesClient()\n\n const documentKey = useDocumentKey()\n const locale = useDocumentLocale()\n\n return useMemo<ResourceResolver>(\n () =>\n createResourceResolver({\n store,\n apiClient,\n documentKey,\n locale,\n }),\n [store, apiClient, documentKey, locale],\n )\n}\n"],"mappings":"AAAA,SAAS,eAAe;AAGxB,SAAS,8BAA8B;AAEvC,SAAS,6BAA6B;AACtC,SAAS,gBAAgB,yBAAyB;AAClD,SAAS,gBAAgB;AAElB,SAAS,sBAAwC;AACtD,QAAM,QAAQ,SAAS;AACvB,QAAM,YAAY,sBAAsB;AAExC,QAAM,cAAc,eAAe;AACnC,QAAM,SAAS,kBAAkB;AAEjC,SAAO;AAAA,IACL,MACE,uBAAuB;AAAA,MACrB;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF,CAAC;AAAA,IACH,CAAC,OAAO,WAAW,aAAa,MAAM;AAAA,EACxC;AACF;","names":[]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { HostApiResourcesClient } from "../../api/host-api-resources-client";
|
|
2
2
|
import {
|
|
3
3
|
parseBreakpointsInput
|
|
4
4
|
} from "../../state/modules/breakpoints";
|
|
@@ -47,16 +47,12 @@ class RuntimeCore {
|
|
|
47
47
|
getOrCreateStore({ siteVersion, locale }) {
|
|
48
48
|
const key = storeCacheKey({ siteVersion, locale });
|
|
49
49
|
const createStore = () => {
|
|
50
|
-
const
|
|
51
|
-
uri: new URL("graphql", this.apiOrigin).href,
|
|
52
|
-
fetch: this.fetch,
|
|
53
|
-
preloadedState: { siteVersion, locale }
|
|
54
|
-
});
|
|
50
|
+
const apiResourcesClient = this.createApiResourcesClient({ siteVersion, locale });
|
|
55
51
|
const isReadOnly = siteVersion == null;
|
|
56
52
|
return configureReadWriteStore({
|
|
57
53
|
name: `Runtime read-write store (site version: ${key})`,
|
|
58
54
|
appOrigin: this.appOrigin,
|
|
59
|
-
|
|
55
|
+
apiResourcesClient,
|
|
60
56
|
preloadedState: { ...this.protoStore.getState(), siteVersion, isReadOnly, locale }
|
|
61
57
|
});
|
|
62
58
|
};
|
|
@@ -89,6 +85,15 @@ class RuntimeCore {
|
|
|
89
85
|
getBreakpoints() {
|
|
90
86
|
return getBreakpoints(this.protoStore.getState());
|
|
91
87
|
}
|
|
88
|
+
get graphqlApiEndpoint() {
|
|
89
|
+
return new URL("graphql", this.apiOrigin).href;
|
|
90
|
+
}
|
|
91
|
+
createApiResourcesClient(preloadedState) {
|
|
92
|
+
return new HostApiResourcesClient({
|
|
93
|
+
fetch: this.fetch,
|
|
94
|
+
preloadedState
|
|
95
|
+
});
|
|
96
|
+
}
|
|
92
97
|
shouldUsePersistentStore(key) {
|
|
93
98
|
return !isServer() || this.requestKey !== void 0 && storeCacheKey(this.requestKey) === key;
|
|
94
99
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/runtimes/react/runtime-core.ts"],"sourcesContent":["import { type SerializableReplacementContext } from '@makeswift/controls'\n\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../../src/runtimes/react/runtime-core.ts"],"sourcesContent":["import { type SerializableReplacementContext } from '@makeswift/controls'\n\nimport { HostApiResourcesClient } from '../../api/host-api-resources-client'\nimport { type HttpFetch } from '../../state/api-client/fetch-api-resource'\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: 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: 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 // API resources client includes an in-memory cache of the site's resources and thus also has to be versioned\n const apiResourcesClient = this.createApiResourcesClient({ siteVersion, locale })\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 apiResourcesClient,\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 if (this.activeStores.retain(key, store)) {\n store.startBreakpointWatch()\n }\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 if (this.activeStores.release(key, store)) {\n store.stopBreakpointWatch()\n }\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 get graphqlApiEndpoint(): string {\n return new URL('graphql', this.apiOrigin).href\n }\n\n private createApiResourcesClient(preloadedState: {\n siteVersion: SiteVersion | null\n locale: string | undefined\n }) {\n return new HostApiResourcesClient({\n fetch: this.fetch,\n preloadedState,\n })\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":"AAEA,SAAS,8BAA8B;AAIvC;AAAA,EAGE;AAAA,OACK;AAEP,SAAS,uBAAuB;AAEhC,SAAS,sBAAsD;AAC/D;AAAA,EACE;AAAA,EACA;AAAA,OAGK;AAEP,SAAS,qBAAqB;AAC9B,SAAS,gBAAgB;AAOzB,MAAM,mBAAmB;AAElB,MAAM,YAAY;AAAA;AAAA;AAAA;AAAA;AAAA,EAKN,eAAe,IAAI,cAAoC;AAAA,IACtE,mBAAmB;AAAA;AAAA;AAAA;AAAA,IAInB,UAAU,cAAc,SAAS,YAAY,cAAc,SAA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Aa,EAAE,aAAa,OAAO,GAAa,OAAoB;AAClE,UAAM,MAAM,cAAc,EAAE,aAAa,OAAO,CAAC;AAEjD,QAAI,CAAC,KAAK,yBAAyB,GAAG,GAAG;AACvC,cAAQ,MAAM,sDAAsD,EAAE,IAAI,CAAC;AAC3E;AAAA,IACF;AAEA,QAAI,KAAK,aAAa,QAAQ,KAAK,KAAK,GAAG;AACzC,YAAM,oBAAoB;AAAA,IAC5B;AAAA,EACF;AAAA,EAEA,gBACE,aACA,oBACS;AACT,WAAO,gBAAgB,KAAK,WAAW,SAAS,GAAG,aAAa,kBAAkB;AAAA,EACpF;AAAA,EAEA,iBAA8B;AAC5B,WAAO,eAAe,KAAK,WAAW,SAAS,CAAC;AAAA,EAClD;AAAA,EAEA,IAAI,qBAA6B;AAC/B,WAAO,IAAI,IAAI,WAAW,KAAK,SAAS,EAAE;AAAA,EAC5C;AAAA,EAEQ,yBAAyB,gBAG9B;AACD,WAAO,IAAI,uBAAuB;AAAA,MAChC,OAAO,KAAK;AAAA,MACZ;AAAA,IACF,CAAC;AAAA,EACH;AAAA,EAEQ,yBAAyB,KAAsB;AAGrD,WAAO,CAAC,SAAS,KAAM,KAAK,eAAe,UAAa,cAAc,KAAK,UAAU,MAAM;AAAA,EAC7F;AACF;AAEA,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":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/state/middleware/makeswift-api-client-sync.ts"],"sourcesContent":["import { type Middleware } from '@reduxjs/toolkit'\n\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../../src/state/middleware/makeswift-api-client-sync.ts"],"sourcesContent":["import { type Middleware } from '@reduxjs/toolkit'\n\nimport { ApiResourcesClient } from '../../api/api-resources-client'\n\nimport { type Action } from '../actions'\nimport { actionMiddleware } from '../toolkit'\nimport { type State, type Dispatch } from '../unified-state'\n\nexport function makeswiftApiClientSyncMiddleware(\n client: ApiResourcesClient,\n): Middleware<Dispatch, State, Dispatch> {\n return actionMiddleware(() => next => {\n return (action: Action) => {\n client.store.dispatch(action)\n\n return next(action)\n }\n })\n}\n"],"mappings":"AAKA,SAAS,wBAAwB;AAG1B,SAAS,iCACd,QACuC;AACvC,SAAO,iBAAiB,MAAM,UAAQ;AACpC,WAAO,CAAC,WAAmB;AACzB,aAAO,MAAM,SAAS,MAAM;AAE5B,aAAO,KAAK,MAAM;AAAA,IACpB;AAAA,EACF,CAAC;AACH;","names":[]}
|
package/dist/esm/state/store.js
CHANGED
|
@@ -94,7 +94,7 @@ function withMixin(mixin) {
|
|
|
94
94
|
function configureReadWriteStore({
|
|
95
95
|
name,
|
|
96
96
|
appOrigin,
|
|
97
|
-
|
|
97
|
+
apiResourcesClient,
|
|
98
98
|
preloadedState
|
|
99
99
|
}) {
|
|
100
100
|
const readWriteMiddlewareRef = {
|
|
@@ -138,7 +138,7 @@ function configureReadWriteStore({
|
|
|
138
138
|
name,
|
|
139
139
|
preloadedState,
|
|
140
140
|
middleware: () => [
|
|
141
|
-
makeswiftApiClientSyncMiddleware(
|
|
141
|
+
makeswiftApiClientSyncMiddleware(apiResourcesClient),
|
|
142
142
|
conditionalReadWriteMiddleware(readWriteMiddlewareRef)
|
|
143
143
|
],
|
|
144
144
|
enhancers: () => new Tuple(
|
|
@@ -150,7 +150,7 @@ function configureReadWriteStore({
|
|
|
150
150
|
})
|
|
151
151
|
),
|
|
152
152
|
withMixin({
|
|
153
|
-
|
|
153
|
+
apiResourcesClient,
|
|
154
154
|
loadReadWriteStateIfNeeded: async () => {
|
|
155
155
|
const { isReadOnly } = store.getState();
|
|
156
156
|
if (isReadOnly) {
|