@makeswift/runtime 0.28.7-canary.4 → 0.28.7-canary.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/api/api-resources-client.js.map +1 -1
- 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 +23 -1
- package/dist/cjs/api/graphql-api-client.js.map +1 -1
- package/dist/cjs/api/{client.js → host-api-resources-client.js} +7 -7
- package/dist/cjs/api/host-api-resources-client.js.map +1 -0
- package/dist/cjs/api/rest-api-client.js +186 -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/types.js.map +1 -1
- 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 +103 -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/next/client.js +0 -8
- package/dist/cjs/next/client.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/fetch.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/hooks/use-cache-data.js.map +1 -1
- package/dist/cjs/runtimes/react/runtime-core.js +2 -2
- package/dist/cjs/runtimes/react/runtime-core.js.map +1 -1
- package/dist/cjs/runtimes/react/testing/react-runtime.js +7 -1
- package/dist/cjs/runtimes/react/testing/react-runtime.js.map +1 -1
- package/dist/cjs/state/api-client/fetch-api-resource.js +8 -8
- package/dist/cjs/state/api-client/fetch-api-resource.js.map +1 -1
- package/dist/esm/api/api-resources-client.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 +29 -2
- package/dist/esm/api/graphql-api-client.js.map +1 -1
- package/dist/esm/api/{client.js → host-api-resources-client.js} +3 -3
- package/dist/esm/api/host-api-resources-client.js.map +1 -0
- package/dist/esm/api/rest-api-client.js +151 -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/types.js.map +1 -1
- 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 +68 -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/next/client.js +0 -8
- package/dist/esm/next/client.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/fetch.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/hooks/use-cache-data.js.map +1 -1
- package/dist/esm/runtimes/react/runtime-core.js +2 -2
- package/dist/esm/runtimes/react/runtime-core.js.map +1 -1
- package/dist/esm/runtimes/react/testing/react-runtime.js +7 -1
- package/dist/esm/runtimes/react/testing/react-runtime.js.map +1 -1
- package/dist/esm/state/api-client/fetch-api-resource.js +1 -1
- package/dist/esm/state/api-client/fetch-api-resource.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/api-resources-client.d.ts.map +1 -1
- 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 +5 -0
- package/dist/types/api/graphql-api-client.d.ts.map +1 -1
- package/dist/types/api/{client.d.ts → host-api-resources-client.d.ts} +3 -4
- package/dist/types/api/host-api-resources-client.d.ts.map +1 -0
- package/dist/types/api/rest-api-client.d.ts +25 -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/api/types.d.ts +1 -0
- package/dist/types/api/types.d.ts.map +1 -1
- 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/client.d.ts +0 -1
- package/dist/types/next/client.d.ts.map +1 -1
- 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/next/fetch.d.ts +1 -1
- package/dist/types/next/fetch.d.ts.map +1 -1
- 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/runtime-core.d.ts +1 -1
- package/dist/types/runtimes/react/runtime-core.d.ts.map +1 -1
- package/dist/types/runtimes/react/testing/react-runtime.d.ts.map +1 -1
- package/dist/types/state/api-client/fetch-api-resource.d.ts +1 -2
- package/dist/types/state/api-client/fetch-api-resource.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/cjs/api/client.js.map +0 -1
- package/dist/esm/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/cjs/next/client.js
CHANGED
|
@@ -24,7 +24,6 @@ module.exports = __toCommonJS(client_exports);
|
|
|
24
24
|
var import_zod = require("zod");
|
|
25
25
|
var import_site_version = require("../api/site-version");
|
|
26
26
|
var import_client = require("../client");
|
|
27
|
-
var import_cache = require("./cache");
|
|
28
27
|
const previewDataSchema = import_zod.z.object({
|
|
29
28
|
siteVersion: import_zod.z.string()
|
|
30
29
|
});
|
|
@@ -38,13 +37,6 @@ class Makeswift extends import_client.MakeswiftClient {
|
|
|
38
37
|
static getPreviewMode(previewData) {
|
|
39
38
|
return this.getSiteVersion(previewData) != null;
|
|
40
39
|
}
|
|
41
|
-
fetchOptions(_siteVersion) {
|
|
42
|
-
return {
|
|
43
|
-
next: {
|
|
44
|
-
tags: [import_cache.MAKESWIFT_CACHE_TAG]
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
40
|
}
|
|
49
41
|
// Annotate the CommonJS export names for ESM import in node:
|
|
50
42
|
0 && (module.exports = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/next/client.ts"],"sourcesContent":["import { PreviewData } from 'next'\nimport { z } from 'zod'\n\nimport { deserializeSiteVersion, type SiteVersion } from '../api/site-version'\n\nimport { MakeswiftClient } from '../client'\
|
|
1
|
+
{"version":3,"sources":["../../../src/next/client.ts"],"sourcesContent":["import { PreviewData } from 'next'\nimport { z } from 'zod'\n\nimport { deserializeSiteVersion, type SiteVersion } from '../api/site-version'\n\nimport { MakeswiftClient } from '../client'\n\nconst previewDataSchema = z.object({\n siteVersion: z.string(),\n})\n\nexport class Makeswift extends MakeswiftClient {\n static getSiteVersion(previewData: PreviewData): SiteVersion | null {\n const parsedSiteVersion = previewDataSchema.safeParse(previewData)\n if (!parsedSiteVersion.success) return null\n\n return deserializeSiteVersion(parsedSiteVersion.data.siteVersion)\n }\n\n static getPreviewMode(previewData: PreviewData): boolean {\n return this.getSiteVersion(previewData) != null\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,iBAAkB;AAElB,0BAAyD;AAEzD,oBAAgC;AAEhC,MAAM,oBAAoB,aAAE,OAAO;AAAA,EACjC,aAAa,aAAE,OAAO;AACxB,CAAC;AAEM,MAAM,kBAAkB,8BAAgB;AAAA,EAC7C,OAAO,eAAe,aAA8C;AAClE,UAAM,oBAAoB,kBAAkB,UAAU,WAAW;AACjE,QAAI,CAAC,kBAAkB;AAAS,aAAO;AAEvC,eAAO,4CAAuB,kBAAkB,KAAK,WAAW;AAAA,EAClE;AAAA,EAEA,OAAO,eAAe,aAAmC;AACvD,WAAO,KAAK,eAAe,WAAW,KAAK;AAAA,EAC7C;AACF;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../src/next/components/tests/controls/color-control/fixtures.ts"],"sourcesContent":["import { type ValueType } from '@makeswift/controls'\nimport { ColorDefinition } from '@makeswift/controls'\n\nimport { APIResourceType, type Swatch } from '../../../../../api'\nimport { type CacheData } from '../../../../../api/client'\n\ntype SwatchData = Omit<Swatch, 'id'>\n\nexport const swatchId = '[swatch-test-id]'\nexport const swatch: SwatchData = {\n __typename: APIResourceType.Swatch,\n hue: 238,\n saturation: 87,\n lightness: 49,\n}\n\nexport const value: ValueType<ColorDefinition> = {\n swatchId,\n alpha: 0.5,\n}\n\nexport const cacheData = (swatch: SwatchData | null): Partial<CacheData> => ({\n apiResources: {\n Swatch: [{ id: swatchId, value: swatch == null ? null : { id: swatchId, ...swatch } }],\n },\n})\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,iBAA6C;AAKtC,MAAM,WAAW;AACjB,MAAM,SAAqB;AAAA,EAChC,YAAY,2BAAgB;AAAA,EAC5B,KAAK;AAAA,EACL,YAAY;AAAA,EACZ,WAAW;AACb;AAEO,MAAM,QAAoC;AAAA,EAC/C;AAAA,EACA,OAAO;AACT;AAEO,MAAM,YAAY,CAACA,aAAmD;AAAA,EAC3E,cAAc;AAAA,IACZ,QAAQ,CAAC,EAAE,IAAI,UAAU,OAAOA,WAAU,OAAO,OAAO,EAAE,IAAI,UAAU,GAAGA,QAAO,EAAE,CAAC;AAAA,EACvF;AACF;","names":["swatch"]}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../src/next/components/tests/controls/color-control/fixtures.ts"],"sourcesContent":["import { type ValueType } from '@makeswift/controls'\nimport { ColorDefinition } from '@makeswift/controls'\n\nimport { APIResourceType, type Swatch } from '../../../../../api'\nimport { type CacheData } from '../../../../../api/api-resources-client'\n\ntype SwatchData = Omit<Swatch, 'id'>\n\nexport const swatchId = '[swatch-test-id]'\nexport const swatch: SwatchData = {\n __typename: APIResourceType.Swatch,\n hue: 238,\n saturation: 87,\n lightness: 49,\n}\n\nexport const value: ValueType<ColorDefinition> = {\n swatchId,\n alpha: 0.5,\n}\n\nexport const cacheData = (swatch: SwatchData | null): Partial<CacheData> => ({\n apiResources: {\n Swatch: [{ id: swatchId, value: swatch == null ? null : { id: swatchId, ...swatch } }],\n },\n})\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,iBAA6C;AAKtC,MAAM,WAAW;AACjB,MAAM,SAAqB;AAAA,EAChC,YAAY,2BAAgB;AAAA,EAC5B,KAAK;AAAA,EACL,YAAY;AAAA,EACZ,WAAW;AACb;AAEO,MAAM,QAAoC;AAAA,EAC/C;AAAA,EACA,OAAO;AACT;AAEO,MAAM,YAAY,CAACA,aAAmD;AAAA,EAC3E,cAAc;AAAA,IACZ,QAAQ,CAAC,EAAE,IAAI,UAAU,OAAOA,WAAU,OAAO,OAAO,EAAE,IAAI,UAAU,GAAGA,QAAO,EAAE,CAAC;AAAA,EACvF;AACF;","names":["swatch"]}
|
|
@@ -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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;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,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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/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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
|
@@ -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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iBAA8D;AAE9D,cAAyB;AAGzB,MAAM,WAAW;AACjB,MAAM,SAAiB;AAAA,EACrB,YAAY,2BAAgB;AAAA,EAC5B,IAAI;AAAA,EACJ,KAAK;AAAA,EACL,YAAY;AAAA,EACZ,WAAW;AACb;AAEA,MAAM,eAAe;AACrB,MAAM,aAAyB;AAAA,EAC7B,YAAY,2BAAgB;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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iBAA8D;AAE9D,cAAyB;AAGzB,MAAM,WAAW;AACjB,MAAM,SAAiB;AAAA,EACrB,YAAY,2BAAgB;AAAA,EAC5B,IAAI;AAAA,EACJ,KAAK;AAAA,EACL,YAAY;AAAA,EACZ,WAAW;AACb;AAEA,MAAM,eAAe;AACrB,MAAM,aAAyB;AAAA,EAC7B,YAAY,2BAAgB;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 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/next/fetch.ts"],"sourcesContent":["import { type HttpFetch } from '../
|
|
1
|
+
{"version":3,"sources":["../../../src/next/fetch.ts"],"sourcesContent":["import { type HttpFetch } from '../api/types'\n\nimport { MAKESWIFT_CACHE_TAG } from './cache'\n\nexport const fetch: HttpFetch = (url, init) =>\n globalThis.fetch(url, { ...init, next: { tags: [MAKESWIFT_CACHE_TAG] } })\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAAoC;AAE7B,MAAM,QAAmB,CAAC,KAAK,SACpC,WAAW,MAAM,KAAK,EAAE,GAAG,MAAM,MAAM,EAAE,MAAM,CAAC,gCAAmB,EAAE,EAAE,CAAC;","names":[]}
|
|
@@ -24,7 +24,7 @@ __export(element_data_exports, {
|
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(element_data_exports);
|
|
26
26
|
var import_crypto = require("crypto");
|
|
27
|
-
var
|
|
27
|
+
var import_api_resources_client = require("../../api/api-resources-client");
|
|
28
28
|
var import_constants = require("../../components/builtin/constants");
|
|
29
29
|
function createRootComponent(elements, rootId) {
|
|
30
30
|
return {
|
|
@@ -64,7 +64,7 @@ function createMakeswiftPageSnapshot(elementDataOrDocument, {
|
|
|
64
64
|
locale
|
|
65
65
|
},
|
|
66
66
|
cacheData: {
|
|
67
|
-
...
|
|
67
|
+
...import_api_resources_client.CacheData.empty(),
|
|
68
68
|
...cacheData
|
|
69
69
|
}
|
|
70
70
|
};
|
|
@@ -88,7 +88,7 @@ function createMakeswiftComponentSnapshot(elementData, {
|
|
|
88
88
|
requestedLocale: locale
|
|
89
89
|
},
|
|
90
90
|
cacheData: {
|
|
91
|
-
...
|
|
91
|
+
...import_api_resources_client.CacheData.empty(),
|
|
92
92
|
...cacheData
|
|
93
93
|
}
|
|
94
94
|
};
|
|
@@ -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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA2B;AAO3B,
|
|
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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA2B;AAO3B,kCAA0B;AAE1B,uBAAuC;AAEhC,SAAS,oBAAoB,UAAyB,QAAiB;AAC5E,SAAO;AAAA,IACL,KAAK,cAAU,0BAAW;AAAA,IAC1B,MAAM,wCAAuB;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,sCAAU,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,SAAK,0BAAW;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,sCAAU,MAAM;AAAA,MACnB,GAAG;AAAA,IACL;AAAA,EACF;AACF;","names":[]}
|
|
@@ -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 { 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;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAwB;AAExB,gCAAqC;AAErC,sCAAsC;AAE/B,SAAS,aAAa,WAAsB;AACjD,QAAM,EAAE,OAAO,SAAS,QAAI,uDAAsB;AAMlD,4BAAQ,MAAM,SAAS,aAAS,gDAAqB,SAAS,CAAC,GAAG,CAAC,SAAS,CAAC;AAC/E;","names":[]}
|
|
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;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAwB;AAExB,gCAAqC;AAErC,sCAAsC;AAE/B,SAAS,aAAa,WAAsB;AACjD,QAAM,EAAE,OAAO,SAAS,QAAI,uDAAsB;AAMlD,4BAAQ,MAAM,SAAS,aAAS,gDAAqB,SAAS,CAAC,GAAG,CAAC,SAAS,CAAC;AAC/E;","names":[]}
|
|
@@ -21,7 +21,7 @@ __export(runtime_core_exports, {
|
|
|
21
21
|
RuntimeCore: () => RuntimeCore
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(runtime_core_exports);
|
|
24
|
-
var
|
|
24
|
+
var import_host_api_resources_client = require("../../api/host-api-resources-client");
|
|
25
25
|
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");
|
|
@@ -107,7 +107,7 @@ class RuntimeCore {
|
|
|
107
107
|
return new URL("graphql", this.apiOrigin).href;
|
|
108
108
|
}
|
|
109
109
|
createApiResourcesClient(preloadedState) {
|
|
110
|
-
return new
|
|
110
|
+
return new import_host_api_resources_client.HostApiResourcesClient({
|
|
111
111
|
fetch: this.fetch,
|
|
112
112
|
preloadedState
|
|
113
113
|
});
|
|
@@ -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 '../../api/types'\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":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,uCAAuC;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,WAA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I,KAAK,aAAa,QAAQ,KAAK,KAAK,GAAG;AACzC,YAAM,oBAAoB;AAAA,IAC5B;AAAA,EACF;AAAA,EAEA,gBACE,aACA,oBACS;AACT,eAAO,0CAAgB,KAAK,WAAW,SAAS,GAAG,aAAa,kBAAkB;AAAA,EACpF;AAAA,EAEA,iBAA8B;AAC5B,eAAO,uCAAe,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,wDAAuB;AAAA,MAChC,OAAO,KAAK;AAAA,MACZ;AAAA,IACF,CAAC;AAAA,EACH;AAAA,EAEQ,yBAAyB,KAAsB;AAGrD,WAAO,KAAC,2BAAS,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":[]}
|
|
@@ -24,7 +24,13 @@ module.exports = __toCommonJS(react_runtime_exports);
|
|
|
24
24
|
var import_fixtures = require("../../../testing/fixtures");
|
|
25
25
|
var import_react_runtime = require("../react-runtime");
|
|
26
26
|
function createReactRuntime({ breakpoints } = {}) {
|
|
27
|
-
return new import_react_runtime.ReactRuntime({
|
|
27
|
+
return new import_react_runtime.ReactRuntime({
|
|
28
|
+
// Mock Service Worker patches global `fetch` for interception; make sure our test calls go
|
|
29
|
+
// through the patched version instead of an eagerly captured reference to the original
|
|
30
|
+
fetch: (...args) => globalThis.fetch(...args),
|
|
31
|
+
breakpoints,
|
|
32
|
+
...import_fixtures.TestOrigins
|
|
33
|
+
});
|
|
28
34
|
}
|
|
29
35
|
// Annotate the CommonJS export names for ESM import in node:
|
|
30
36
|
0 && (module.exports = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/runtimes/react/testing/react-runtime.tsx"],"sourcesContent":["import { type BreakpointsInput } from '../../../state/modules/breakpoints'\nimport { TestOrigins } from '../../../testing/fixtures'\nimport { ReactRuntime } from '../react-runtime'\n\nexport function createReactRuntime({ breakpoints }: { breakpoints?: BreakpointsInput } = {}) {\n return new ReactRuntime({ fetch
|
|
1
|
+
{"version":3,"sources":["../../../../../src/runtimes/react/testing/react-runtime.tsx"],"sourcesContent":["import { type BreakpointsInput } from '../../../state/modules/breakpoints'\nimport { TestOrigins } from '../../../testing/fixtures'\nimport { ReactRuntime } from '../react-runtime'\n\nexport function createReactRuntime({ breakpoints }: { breakpoints?: BreakpointsInput } = {}) {\n return new ReactRuntime({\n // Mock Service Worker patches global `fetch` for interception; make sure our test calls go\n // through the patched version instead of an eagerly captured reference to the original\n fetch: (...args) => globalThis.fetch(...args),\n breakpoints,\n ...TestOrigins,\n })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,sBAA4B;AAC5B,2BAA6B;AAEtB,SAAS,mBAAmB,EAAE,YAAY,IAAwC,CAAC,GAAG;AAC3F,SAAO,IAAI,kCAAa;AAAA;AAAA;AAAA,IAGtB,OAAO,IAAI,SAAS,WAAW,MAAM,GAAG,IAAI;AAAA,IAC5C;AAAA,IACA,GAAG;AAAA,EACL,CAAC;AACH;","names":[]}
|
|
@@ -35,7 +35,7 @@ var import_site_version = require("../../api/site-version");
|
|
|
35
35
|
var SiteVersionState = __toESM(require("../modules/site-version"));
|
|
36
36
|
var import_read_only_actions = require("../actions/internal/read-only-actions");
|
|
37
37
|
var import_host_api = require("../host-api");
|
|
38
|
-
var
|
|
38
|
+
var import_types = require("../../api/types");
|
|
39
39
|
var import_state = require("./state");
|
|
40
40
|
function fetchAPIResource(resourceType, resourceId, fetch, locale) {
|
|
41
41
|
const fetchVersioned = async (url, version) => {
|
|
@@ -64,25 +64,25 @@ function fetchAPIResource(resourceType, resourceId, fetch, locale) {
|
|
|
64
64
|
}
|
|
65
65
|
let resource;
|
|
66
66
|
switch (resourceType) {
|
|
67
|
-
case
|
|
67
|
+
case import_types.APIResourceType.Swatch:
|
|
68
68
|
resource = await fetchVersioned(`/api/makeswift/swatches/${resourceId}`, version);
|
|
69
69
|
break;
|
|
70
|
-
case
|
|
70
|
+
case import_types.APIResourceType.File:
|
|
71
71
|
resource = await fetchVersioned(`/api/makeswift/files/${resourceId}`, version);
|
|
72
72
|
break;
|
|
73
|
-
case
|
|
73
|
+
case import_types.APIResourceType.Typography:
|
|
74
74
|
resource = await fetchVersioned(
|
|
75
75
|
`/api/makeswift/typographies/${resourceId}`,
|
|
76
76
|
version
|
|
77
77
|
);
|
|
78
78
|
break;
|
|
79
|
-
case
|
|
79
|
+
case import_types.APIResourceType.GlobalElement:
|
|
80
80
|
resource = await fetchVersioned(
|
|
81
81
|
`/api/makeswift/global-elements/${resourceId}`,
|
|
82
82
|
version
|
|
83
83
|
);
|
|
84
84
|
break;
|
|
85
|
-
case
|
|
85
|
+
case import_types.APIResourceType.LocalizedGlobalElement: {
|
|
86
86
|
if (locale == null)
|
|
87
87
|
throw new Error("Locale is required to fetch LocalizedGlobalElement");
|
|
88
88
|
if ((0, import_state.getLocalizedResourceId)(state, locale, resourceId) === null) {
|
|
@@ -101,14 +101,14 @@ function fetchAPIResource(resourceType, resourceId, fetch, locale) {
|
|
|
101
101
|
);
|
|
102
102
|
break;
|
|
103
103
|
}
|
|
104
|
-
case
|
|
104
|
+
case import_types.APIResourceType.PagePathnameSlice: {
|
|
105
105
|
const url = new URL(`/api/makeswift/page-pathname-slices/${resourceId}`, "http://n");
|
|
106
106
|
if (locale != null)
|
|
107
107
|
url.searchParams.set("locale", locale);
|
|
108
108
|
resource = await fetchVersioned(url.pathname + url.search, version);
|
|
109
109
|
break;
|
|
110
110
|
}
|
|
111
|
-
case
|
|
111
|
+
case import_types.APIResourceType.Table:
|
|
112
112
|
resource = await fetchVersioned(`/api/makeswift/tables/${resourceId}`, version);
|
|
113
113
|
break;
|
|
114
114
|
default:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/state/api-client/fetch-api-resource.ts"],"sourcesContent":["import { type ThunkAction } from '@reduxjs/toolkit'\n\nimport { type SiteVersion, ApiHandlerHeaders, serializeSiteVersion } from '../../api/site-version'\n\nimport * as SiteVersionState from '../modules/site-version'\n\nimport { type Action } from '../actions'\nimport { apiResourceFulfilled } from '../actions/internal/read-only-actions'\nimport { setLocalizedResourceId } from '../host-api'\n\nimport {\n APIResourceType,\n type APIResource,\n type Swatch,\n type File,\n type Typography,\n type GlobalElement,\n type PagePathnameSlice,\n type Table,\n type LocalizedGlobalElement,\n type APIResourceLocale,\n} from '../../api'\n\nimport { type State, getHasAPIResource, getAPIResource, getLocalizedResourceId } from './state'\n\
|
|
1
|
+
{"version":3,"sources":["../../../../src/state/api-client/fetch-api-resource.ts"],"sourcesContent":["import { type ThunkAction } from '@reduxjs/toolkit'\n\nimport { type SiteVersion, ApiHandlerHeaders, serializeSiteVersion } from '../../api/site-version'\n\nimport * as SiteVersionState from '../modules/site-version'\n\nimport { type Action } from '../actions'\nimport { apiResourceFulfilled } from '../actions/internal/read-only-actions'\nimport { setLocalizedResourceId } from '../host-api'\n\nimport {\n APIResourceType,\n type APIResource,\n type Swatch,\n type File,\n type Typography,\n type GlobalElement,\n type PagePathnameSlice,\n type Table,\n type LocalizedGlobalElement,\n type APIResourceLocale,\n type HttpFetch,\n} from '../../api/types'\n\nimport { type State, getHasAPIResource, getAPIResource, getLocalizedResourceId } from './state'\n\ntype Thunk<ReturnType> = ThunkAction<ReturnType, State, unknown, Action>\n\nexport function fetchAPIResource<T extends APIResourceType>(\n resourceType: T,\n resourceId: string,\n fetch: HttpFetch,\n locale?: APIResourceLocale<T>,\n): Thunk<Promise<Extract<APIResource, { __typename: T }> | null>> {\n const fetchVersioned = async <T>(url: string, version: SiteVersion | null): Promise<T | null> => {\n const response = await fetch(url, {\n headers: {\n 'Content-Type': 'application/json',\n ...(version != null\n ? { [ApiHandlerHeaders.SiteVersion]: serializeSiteVersion(version) }\n : {}),\n },\n })\n\n if (response.status === 404) return null\n if (!response.ok) throw new Error(response.statusText)\n\n if (response.headers.get('content-type')?.includes('application/json') !== true) {\n throw new Error(\n `Expected JSON response from \"${url}\" but got \"${response.headers.get('content-type')}\"`,\n )\n }\n\n return response.json()\n }\n\n return async (dispatch, getState) => {\n const state = getState()\n const version = SiteVersionState.getSiteVersion(state.siteVersion)\n\n if (getHasAPIResource(state, resourceType, resourceId, locale)) {\n return getAPIResource(state, resourceType, resourceId, locale)\n }\n\n let resource: APIResource | null\n\n switch (resourceType) {\n case APIResourceType.Swatch:\n resource = await fetchVersioned<Swatch>(`/api/makeswift/swatches/${resourceId}`, version)\n break\n\n case APIResourceType.File:\n resource = await fetchVersioned<File>(`/api/makeswift/files/${resourceId}`, version)\n break\n\n case APIResourceType.Typography:\n resource = await fetchVersioned<Typography>(\n `/api/makeswift/typographies/${resourceId}`,\n version,\n )\n break\n\n case APIResourceType.GlobalElement:\n resource = await fetchVersioned<GlobalElement>(\n `/api/makeswift/global-elements/${resourceId}`,\n version,\n )\n break\n\n case APIResourceType.LocalizedGlobalElement: {\n if (locale == null) throw new Error('Locale is required to fetch LocalizedGlobalElement')\n\n // If `getLocalizedResourceId` returns null, it means we have tried to fetch the resource,\n // but the resource is not available. If we haven't fetched it yet, it'll return undefined.\n if (getLocalizedResourceId(state, locale, resourceId) === null) {\n return null\n }\n\n resource = await fetchVersioned<LocalizedGlobalElement>(\n `/api/makeswift/localized-global-elements/${resourceId}/${locale}`,\n version,\n )\n\n dispatch(\n setLocalizedResourceId({\n locale,\n resourceId,\n localizedResourceId: resource?.id ?? null,\n }),\n )\n\n break\n }\n\n case APIResourceType.PagePathnameSlice: {\n const url = new URL(`/api/makeswift/page-pathname-slices/${resourceId}`, 'http://n')\n\n if (locale != null) url.searchParams.set('locale', locale)\n\n resource = await fetchVersioned<PagePathnameSlice>(url.pathname + url.search, version)\n break\n }\n\n case APIResourceType.Table:\n resource = await fetchVersioned<Table>(`/api/makeswift/tables/${resourceId}`, version)\n break\n\n default:\n resource = null\n }\n\n dispatch(apiResourceFulfilled(resourceType, resourceId, resource, locale))\n\n return resource as Extract<APIResource, { __typename: T }> | null\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,0BAA0E;AAE1E,uBAAkC;AAGlC,+BAAqC;AACrC,sBAAuC;AAEvC,mBAYO;AAEP,mBAAsF;AAI/E,SAAS,iBACd,cACA,YACA,OACA,QACgE;AAChE,QAAM,iBAAiB,OAAU,KAAa,YAAmD;AAC/F,UAAM,WAAW,MAAM,MAAM,KAAK;AAAA,MAChC,SAAS;AAAA,QACP,gBAAgB;AAAA,QAChB,GAAI,WAAW,OACX,EAAE,CAAC,sCAAkB,WAAW,OAAG,0CAAqB,OAAO,EAAE,IACjE,CAAC;AAAA,MACP;AAAA,IACF,CAAC;AAED,QAAI,SAAS,WAAW;AAAK,aAAO;AACpC,QAAI,CAAC,SAAS;AAAI,YAAM,IAAI,MAAM,SAAS,UAAU;AAErD,QAAI,SAAS,QAAQ,IAAI,cAAc,GAAG,SAAS,kBAAkB,MAAM,MAAM;AAC/E,YAAM,IAAI;AAAA,QACR,gCAAgC,GAAG,cAAc,SAAS,QAAQ,IAAI,cAAc,CAAC;AAAA,MACvF;AAAA,IACF;AAEA,WAAO,SAAS,KAAK;AAAA,EACvB;AAEA,SAAO,OAAO,UAAU,aAAa;AACnC,UAAM,QAAQ,SAAS;AACvB,UA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A,MAEF;AACE,mBAAW;AAAA,IACf;AAEA,iBAAS,+CAAqB,cAAc,YAAY,UAAU,MAAM,CAAC;AAEzE,WAAO;AAAA,EACT;AACF;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/api/api-resources-client.ts"],"sourcesContent":["import { type FetchableValue } from '@makeswift/controls'\n\nimport { type Store as ApiClientStore } from '../state/api-client/store'\nimport * as ApiClientState from '../state/api-client/state'\n\nimport {\n type File,\n type GlobalElement,\n type LocalizedGlobalElement,\n type Page,\n type PagePathnameSlice,\n type Site,\n type Snippet,\n type Swatch,\n type Table,\n type Typography,\n APIResourceType,\n} from './types'\n\nexport type CacheData = ApiClientState.SerializedState\n\nexport const CacheData = {\n empty(): CacheData {\n return {\n apiResources: {},\n localizedResourcesMap: {},\n }\n },\n}\nexport abstract class ApiResourcesClient {\n readonly store: ApiClientStore\n readonly subscribe: ApiClientStore['subscribe']\n\n constructor({ store }: { store: ApiClientStore }) {\n this.store = store\n this.subscribe = this.store.subscribe\n }\n\n abstract fetchSwatch(swatchId: string): Promise<Swatch | null>\n\n readSwatch(swatchId: string): Swatch | null {\n return ApiClientState.getAPIResource(this.store.getState(), APIResourceType.Swatch, swatchId)\n }\n\n resolveSwatch(swatchId: string | undefined): FetchableValue<Swatch | null> {\n return this.resolveResource(APIResourceType.Swatch, {\n id: swatchId,\n read: id => this.readSwatch(id),\n fetch: id => this.fetchSwatch(id),\n })\n }\n\n abstract fetchFile(fileId: string): Promise<File | null>\n\n readFile(fileId: string): File | null {\n return ApiClientState.getAPIResource(this.store.getState(), APIResourceType.File, fileId)\n }\n\n resolveFile(fileId: string | undefined): FetchableValue<File | null> {\n return this.resolveResource(APIResourceType.File, {\n id: fileId,\n read: id => this.readFile(id),\n fetch: id => this.fetchFile(id),\n })\n }\n\n abstract fetchTypography(typographyId: string): Promise<Typography | null>\n\n readTypography(typographyId: string): Typography | null {\n return ApiClientState.getAPIResource(\n this.store.getState(),\n APIResourceType.Typography,\n typographyId,\n )\n }\n\n resolveTypography(typographyId: string | undefined): FetchableValue<Typography | null> {\n return this.resolveResource(APIResourceType.Typography, {\n id: typographyId,\n read: id => this.readTypography(id),\n fetch: id => this.fetchTypography(id),\n })\n }\n\n abstract fetchGlobalElement(globalElementId: string): Promise<GlobalElement | null>\n\n readGlobalElement(globalElementId: string): GlobalElement | null {\n return ApiClientState.getAPIResource(\n this.store.getState(),\n APIResourceType.GlobalElement,\n globalElementId,\n )\n }\n\n abstract fetchLocalizedGlobalElement({\n globalElementId,\n locale,\n }: {\n globalElementId: string\n locale: string\n }): Promise<LocalizedGlobalElement | null>\n\n readLocalizedGlobalElement({\n globalElementId,\n locale,\n }: {\n globalElementId: string\n locale: string\n }): LocalizedGlobalElement | null {\n return ApiClientState.getAPIResource(\n this.store.getState(),\n APIResourceType.LocalizedGlobalElement,\n globalElementId,\n locale,\n )\n }\n\n readPagePathnameSlice({\n pageId,\n locale,\n }: {\n pageId: string\n locale: string | null\n }): PagePathnameSlice | null {\n return ApiClientState.getAPIResource(\n this.store.getState(),\n APIResourceType.PagePathnameSlice,\n pageId,\n locale,\n )\n }\n\n abstract fetchPagePathnameSlice({\n pageId,\n locale,\n }: {\n pageId: string\n locale: string | null\n }): Promise<PagePathnameSlice | null>\n\n resolvePagePathnameSlice({\n pageId,\n locale,\n }: {\n pageId: string | undefined\n locale: string | null\n }): FetchableValue<PagePathnameSlice | null> {\n return this.resolveResource(APIResourceType.PagePathnameSlice, {\n id: pageId,\n read: id => this.readPagePathnameSlice({ pageId: id, locale }),\n fetch: id => this.fetchPagePathnameSlice({ pageId: id, locale }),\n })\n }\n\n resolveResource<R>(\n type: APIResourceType,\n {\n id,\n read,\n fetch,\n }: {\n id: string | undefined\n read: (id: string) => R | null\n fetch: (id: string) => Promise<R | null>\n },\n ): FetchableValue<R | null> {\n const _read = () => (id != null ? read(id) : null)\n let lastValue: R | null = null\n return {\n name: `${type}:${id}`,\n readStable: () => (lastValue = _read()),\n subscribe: (onUpdate: () => void) =>\n this.subscribe(() => {\n if (_read() !== lastValue) onUpdate()\n }),\n fetch: async () => (id != null ? fetch(id) : null),\n }\n }\n\n abstract fetchTable(tableId: string): Promise<Table | null>\n\n readTable(tableId: string): Table | null {\n return ApiClientState.getAPIResource(this.store.getState(), APIResourceType.Table, tableId)\n }\n\n readSite(siteId: string): Site | null {\n return ApiClientState.getAPIResource(this.store.getState(), APIResourceType.Site, siteId)\n }\n\n readPage(pageId: string): Page | null {\n return ApiClientState.getAPIResource(this.store.getState(), APIResourceType.Page, pageId)\n }\n\n readSnippet(snippetId: string): Snippet | null {\n return ApiClientState.getAPIResource(this.store.getState(), APIResourceType.Snippet, snippetId)\n }\n}\n"],"mappings":"AAGA,YAAY,oBAAoB;AAEhC;AAAA,EAWE;AAAA,OACK;AAIA,MAAM,YAAY;AAAA,EACvB,QAAmB;AACjB,WAAO;AAAA,MACL,cAAc,CAAC;AAAA,MACf,uBAAuB,CAAC;AAAA,IAC1B;AAAA,EACF;AACF;
|
|
1
|
+
{"version":3,"sources":["../../../src/api/api-resources-client.ts"],"sourcesContent":["import { type FetchableValue } from '@makeswift/controls'\n\nimport { type Store as ApiClientStore } from '../state/api-client/store'\nimport * as ApiClientState from '../state/api-client/state'\n\nimport {\n type File,\n type GlobalElement,\n type LocalizedGlobalElement,\n type Page,\n type PagePathnameSlice,\n type Site,\n type Snippet,\n type Swatch,\n type Table,\n type Typography,\n APIResourceType,\n} from './types'\n\nexport type CacheData = ApiClientState.SerializedState\n\nexport const CacheData = {\n empty(): CacheData {\n return {\n apiResources: {},\n localizedResourcesMap: {},\n }\n },\n}\n\nexport abstract class ApiResourcesClient {\n readonly store: ApiClientStore\n readonly subscribe: ApiClientStore['subscribe']\n\n constructor({ store }: { store: ApiClientStore }) {\n this.store = store\n this.subscribe = this.store.subscribe\n }\n\n abstract fetchSwatch(swatchId: string): Promise<Swatch | null>\n\n readSwatch(swatchId: string): Swatch | null {\n return ApiClientState.getAPIResource(this.store.getState(), APIResourceType.Swatch, swatchId)\n }\n\n resolveSwatch(swatchId: string | undefined): FetchableValue<Swatch | null> {\n return this.resolveResource(APIResourceType.Swatch, {\n id: swatchId,\n read: id => this.readSwatch(id),\n fetch: id => this.fetchSwatch(id),\n })\n }\n\n abstract fetchFile(fileId: string): Promise<File | null>\n\n readFile(fileId: string): File | null {\n return ApiClientState.getAPIResource(this.store.getState(), APIResourceType.File, fileId)\n }\n\n resolveFile(fileId: string | undefined): FetchableValue<File | null> {\n return this.resolveResource(APIResourceType.File, {\n id: fileId,\n read: id => this.readFile(id),\n fetch: id => this.fetchFile(id),\n })\n }\n\n abstract fetchTypography(typographyId: string): Promise<Typography | null>\n\n readTypography(typographyId: string): Typography | null {\n return ApiClientState.getAPIResource(\n this.store.getState(),\n APIResourceType.Typography,\n typographyId,\n )\n }\n\n resolveTypography(typographyId: string | undefined): FetchableValue<Typography | null> {\n return this.resolveResource(APIResourceType.Typography, {\n id: typographyId,\n read: id => this.readTypography(id),\n fetch: id => this.fetchTypography(id),\n })\n }\n\n abstract fetchGlobalElement(globalElementId: string): Promise<GlobalElement | null>\n\n readGlobalElement(globalElementId: string): GlobalElement | null {\n return ApiClientState.getAPIResource(\n this.store.getState(),\n APIResourceType.GlobalElement,\n globalElementId,\n )\n }\n\n abstract fetchLocalizedGlobalElement({\n globalElementId,\n locale,\n }: {\n globalElementId: string\n locale: string\n }): Promise<LocalizedGlobalElement | null>\n\n readLocalizedGlobalElement({\n globalElementId,\n locale,\n }: {\n globalElementId: string\n locale: string\n }): LocalizedGlobalElement | null {\n return ApiClientState.getAPIResource(\n this.store.getState(),\n APIResourceType.LocalizedGlobalElement,\n globalElementId,\n locale,\n )\n }\n\n readPagePathnameSlice({\n pageId,\n locale,\n }: {\n pageId: string\n locale: string | null\n }): PagePathnameSlice | null {\n return ApiClientState.getAPIResource(\n this.store.getState(),\n APIResourceType.PagePathnameSlice,\n pageId,\n locale,\n )\n }\n\n abstract fetchPagePathnameSlice({\n pageId,\n locale,\n }: {\n pageId: string\n locale: string | null\n }): Promise<PagePathnameSlice | null>\n\n resolvePagePathnameSlice({\n pageId,\n locale,\n }: {\n pageId: string | undefined\n locale: string | null\n }): FetchableValue<PagePathnameSlice | null> {\n return this.resolveResource(APIResourceType.PagePathnameSlice, {\n id: pageId,\n read: id => this.readPagePathnameSlice({ pageId: id, locale }),\n fetch: id => this.fetchPagePathnameSlice({ pageId: id, locale }),\n })\n }\n\n resolveResource<R>(\n type: APIResourceType,\n {\n id,\n read,\n fetch,\n }: {\n id: string | undefined\n read: (id: string) => R | null\n fetch: (id: string) => Promise<R | null>\n },\n ): FetchableValue<R | null> {\n const _read = () => (id != null ? read(id) : null)\n let lastValue: R | null = null\n return {\n name: `${type}:${id}`,\n readStable: () => (lastValue = _read()),\n subscribe: (onUpdate: () => void) =>\n this.subscribe(() => {\n if (_read() !== lastValue) onUpdate()\n }),\n fetch: async () => (id != null ? fetch(id) : null),\n }\n }\n\n abstract fetchTable(tableId: string): Promise<Table | null>\n\n readTable(tableId: string): Table | null {\n return ApiClientState.getAPIResource(this.store.getState(), APIResourceType.Table, tableId)\n }\n\n readSite(siteId: string): Site | null {\n return ApiClientState.getAPIResource(this.store.getState(), APIResourceType.Site, siteId)\n }\n\n readPage(pageId: string): Page | null {\n return ApiClientState.getAPIResource(this.store.getState(), APIResourceType.Page, pageId)\n }\n\n readSnippet(snippetId: string): Snippet | null {\n return ApiClientState.getAPIResource(this.store.getState(), APIResourceType.Snippet, snippetId)\n }\n}\n"],"mappings":"AAGA,YAAY,oBAAoB;AAEhC;AAAA,EAWE;AAAA,OACK;AAIA,MAAM,YAAY;AAAA,EACvB,QAAmB;AACjB,WAAO;AAAA,MACL,cAAc,CAAC;AAAA,MACf,uBAAuB,CAAC;AAAA,IAC1B;AAAA,EACF;AACF;AAEO,MAAe,mBAAmB;AAAA,EAC9B;AAAA,EACA;AAAA,EAET,YAAY,EAAE,MAAM,GAA8B;AAChD,SAAK,QAAQ;AACb,SAAK,YAA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B,MAAM,MAAM;AAAA,EAC1F;AAAA,EAEA,YAAY,WAAmC;AAC7C,WAAO,eAAe,eAAe,KAAK,MAAM,SAAS,GAAG,gBAAgB,SAAS,SAAS;AAAA,EAChG;AACF;","names":[]}
|
|
@@ -5,10 +5,10 @@ import {
|
|
|
5
5
|
TableFragment,
|
|
6
6
|
TypographyFragment
|
|
7
7
|
} from "./fragments";
|
|
8
|
-
const
|
|
8
|
+
const UnversionedResourcesQuery = (
|
|
9
9
|
/* GraphQL */
|
|
10
10
|
`
|
|
11
|
-
query
|
|
11
|
+
query UnversionedResources($fileIds: [ID!]!, $tableIds: [ID!]!) {
|
|
12
12
|
files(ids: $fileIds) {
|
|
13
13
|
...File
|
|
14
14
|
}
|
|
@@ -110,10 +110,10 @@ export {
|
|
|
110
110
|
CreateTableRecordMutation,
|
|
111
111
|
FileQuery,
|
|
112
112
|
GlobalElementQuery,
|
|
113
|
-
IntrospectedResourcesQuery,
|
|
114
113
|
SwatchQuery,
|
|
115
114
|
TableQuery,
|
|
116
115
|
TypographiesQuery,
|
|
117
|
-
TypographyQuery
|
|
116
|
+
TypographyQuery,
|
|
117
|
+
UnversionedResourcesQuery
|
|
118
118
|
};
|
|
119
119
|
//# sourceMappingURL=queries.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/api/graphql/documents/queries.ts"],"sourcesContent":["import {\n FileFragment,\n GlobalElementFragment,\n SwatchFragment,\n TableFragment,\n TypographyFragment,\n} from './fragments'\n\nexport const
|
|
1
|
+
{"version":3,"sources":["../../../../../src/api/graphql/documents/queries.ts"],"sourcesContent":["import {\n FileFragment,\n GlobalElementFragment,\n SwatchFragment,\n TableFragment,\n TypographyFragment,\n} from './fragments'\n\nexport const UnversionedResourcesQuery = /* GraphQL */ `\n query UnversionedResources($fileIds: [ID!]!, $tableIds: [ID!]!) {\n files(ids: $fileIds) {\n ...File\n }\n\n tables(ids: $tableIds) {\n ...Table\n }\n }\n\n ${FileFragment}\n ${TableFragment}\n`\n\nexport const SwatchQuery = /* GraphQL */ `\n query Swatch($swatchId: ID!) {\n swatch(id: $swatchId) {\n ...Swatch\n }\n }\n\n ${SwatchFragment}\n`\n\nexport const FileQuery = /* GraphQL */ `\n query File($fileId: ID!) {\n file(id: $fileId) {\n ...File\n }\n }\n\n ${FileFragment}\n`\n\nexport const TypographyQuery = /* GraphQL */ `\n query Typography($typographyId: ID!) {\n typography(id: $typographyId) {\n ...Typography\n }\n }\n\n ${TypographyFragment}\n`\n\nexport const TableQuery = /* GraphQL */ `\n query Table($tableId: ID!) {\n table(id: $tableId) {\n ...Table\n }\n }\n\n ${TableFragment}\n`\n\nexport const TypographiesQuery = /* GraphQL */ `\n query Typographies($typographyIds: [ID!]!) {\n typographies(ids: $typographyIds) {\n ...Typography\n }\n }\n\n ${TypographyFragment}\n`\n\nexport const GlobalElementQuery = /* GraphQL */ `\n query GlobalElement($globalElementId: ID!) {\n globalElement(id: $globalElementId) {\n ...GlobalElement\n }\n }\n\n ${GlobalElementFragment}\n`\n\nexport const CreateTableRecordMutation = /* GraphQL */ `\n mutation CreateTableRecord($input: CreateTableRecordInput!) {\n createTableRecord(input: $input) {\n tableRecord {\n id\n }\n }\n }\n`\n"],"mappings":"AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEA,MAAM;AAAA;AAAA,EAA0C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAWnD,YAAY;AAAA,IACZ,aAAa;AAAA;AAAA;AAGV,MAAM;AAAA;AAAA,EAA4B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAOrC,cAAc;AAAA;AAAA;AAGX,MAAM;AAAA;AAAA,EAA0B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAOnC,YAAY;AAAA;AAAA;AAGT,MAAM;AAAA;AAAA,EAAgC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAOzC,kBAAkB;AAAA;AAAA;AAGf,MAAM;AAAA;AAAA,EAA2B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAOpC,aAAa;AAAA;AAAA;AAGV,MAAM;AAAA;AAAA,EAAkC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAO3C,kBAAkB;AAAA;AAAA;AAGf,MAAM;AAAA;AAAA,EAAmC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAO5C,qBAAqB;AAAA;AAAA;AAGlB,MAAM;AAAA;AAAA,EAA0C;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/api/graphql/generated/types.ts"],"sourcesContent":["export type Maybe<T> = T | null\nexport type InputMaybe<T> = Maybe<T>\nexport type Exact<T extends { [key: string]: unknown }> = { [K in keyof T]: T[K] }\n\ntype Json = null | boolean | number | string | Json[] | { [key: string]: Json }\n\ntype Scalars = {\n ID: string\n JSON: Json\n Locale: string\n}\n\nexport type CreateTableRecordInput = {\n data: CreateTableRecordInputData\n}\n\nexport type CreateTableRecordInputData = {\n columns: Array<CreateTableRecordInputDataColumn>\n tableId?: InputMaybe<Scalars['ID']>\n}\n\nexport type CreateTableRecordInputDataColumn = {\n columnId: Scalars['ID']\n data: Scalars['JSON']\n}\n\nexport const SnippetLocation = {\n Body: 'BODY',\n Head: 'HEAD',\n} as const\n\nexport type SnippetLocation = (typeof SnippetLocation)[keyof typeof SnippetLocation]\n\nexport type SwatchFragment = {\n __typename: 'Swatch'\n id: string\n hue: number\n saturation: number\n lightness: number\n}\n\nexport type FileFragment = {\n __typename: 'File'\n id: string\n name: string\n extension: string | null\n publicUrl: string\n dimensions: { width: number; height: number } | null\n}\n\nexport type TypographyFragment = {\n __typename: 'Typography'\n id: string\n name: string\n style: Array<{\n deviceId: string\n value: {\n fontFamily: string | null\n lineHeight: number | null\n letterSpacing: number | null\n fontWeight: number | null\n textAlign: string | null\n uppercase: boolean | null\n underline: boolean | null\n strikethrough: boolean | null\n italic: boolean | null\n fontSize: { value: number | null; unit: string | null } | null\n color: { swatchId: string | null; alpha: number | null } | null\n }\n }>\n}\n\nexport type PagePathnameSliceFragment = {\n __typename: 'PagePathnameSlice'\n id: string\n pathname: string\n}\n\nexport type GlobalElementFragment = { __typename: 'GlobalElement'; id: string; data: Json }\n\nexport type LocalizedGlobalElementFragment = {\n __typename: 'LocalizedGlobalElement'\n id: string\n data: Json\n}\n\nexport type TableFragment = {\n __typename: 'Table'\n id: string\n name: string\n columns: Array<\n | { __typename: 'CheckboxTableColumn'; id: string; name: string }\n | { __typename: 'EmailTableColumn'; id: string; name: string }\n | { __typename: 'LongTextTableColumn'; id: string; name: string }\n | {\n __typename: 'MultipleSelectTableColumn'\n id: string\n name: string\n options: Array<{ id: string; name: string }>\n }\n | { __typename: 'NumberTableColumn'; id: string; name: string }\n | { __typename: 'PhoneNumberTableColumn'; id: string; name: string }\n | { __typename: 'SingleLineTextTableColumn'; id: string; name: string }\n | {\n __typename: 'SingleSelectTableColumn'\n id: string\n name: string\n options: Array<{ id: string; name: string }>\n }\n | { __typename: 'URLTableColumn'; id: string; name: string }\n >\n}\n\nexport type SnippetFragment = {\n __typename: 'Snippet'\n id: string\n name: string\n code: string\n cleanup: string | null\n location: SnippetLocation\n shouldAddToNewPages: boolean\n liveEnabled: boolean\n builderEnabled: boolean\n}\n\nexport type PageFragment = {\n __typename: 'Page'\n id: string\n snippets: Array<{\n __typename: 'Snippet'\n id: string\n name: string\n code: string\n cleanup: string | null\n location: SnippetLocation\n shouldAddToNewPages: boolean\n liveEnabled: boolean\n builderEnabled: boolean\n }>\n}\n\nexport type SiteFragment = {\n __typename: 'Site'\n id: string\n googleFonts: {\n edges: Array<{\n activeVariants: Array<{ specifier: string }>\n node: { family: string; variants: Array<{ specifier: string }> }\n } | null>\n }\n}\n\nexport type
|
|
1
|
+
{"version":3,"sources":["../../../../../src/api/graphql/generated/types.ts"],"sourcesContent":["export type Maybe<T> = T | null\nexport type InputMaybe<T> = Maybe<T>\nexport type Exact<T extends { [key: string]: unknown }> = { [K in keyof T]: T[K] }\n\ntype Json = null | boolean | number | string | Json[] | { [key: string]: Json }\n\ntype Scalars = {\n ID: string\n JSON: Json\n Locale: string\n}\n\nexport type CreateTableRecordInput = {\n data: CreateTableRecordInputData\n}\n\nexport type CreateTableRecordInputData = {\n columns: Array<CreateTableRecordInputDataColumn>\n tableId?: InputMaybe<Scalars['ID']>\n}\n\nexport type CreateTableRecordInputDataColumn = {\n columnId: Scalars['ID']\n data: Scalars['JSON']\n}\n\nexport const SnippetLocation = {\n Body: 'BODY',\n Head: 'HEAD',\n} as const\n\nexport type SnippetLocation = (typeof SnippetLocation)[keyof typeof SnippetLocation]\n\nexport type SwatchFragment = {\n __typename: 'Swatch'\n id: string\n hue: number\n saturation: number\n lightness: number\n}\n\nexport type FileFragment = {\n __typename: 'File'\n id: string\n name: string\n extension: string | null\n publicUrl: string\n dimensions: { width: number; height: number } | null\n}\n\nexport type TypographyFragment = {\n __typename: 'Typography'\n id: string\n name: string\n style: Array<{\n deviceId: string\n value: {\n fontFamily: string | null\n lineHeight: number | null\n letterSpacing: number | null\n fontWeight: number | null\n textAlign: string | null\n uppercase: boolean | null\n underline: boolean | null\n strikethrough: boolean | null\n italic: boolean | null\n fontSize: { value: number | null; unit: string | null } | null\n color: { swatchId: string | null; alpha: number | null } | null\n }\n }>\n}\n\nexport type PagePathnameSliceFragment = {\n __typename: 'PagePathnameSlice'\n id: string\n pathname: string\n}\n\nexport type GlobalElementFragment = { __typename: 'GlobalElement'; id: string; data: Json }\n\nexport type LocalizedGlobalElementFragment = {\n __typename: 'LocalizedGlobalElement'\n id: string\n data: Json\n}\n\nexport type TableFragment = {\n __typename: 'Table'\n id: string\n name: string\n columns: Array<\n | { __typename: 'CheckboxTableColumn'; id: string; name: string }\n | { __typename: 'EmailTableColumn'; id: string; name: string }\n | { __typename: 'LongTextTableColumn'; id: string; name: string }\n | {\n __typename: 'MultipleSelectTableColumn'\n id: string\n name: string\n options: Array<{ id: string; name: string }>\n }\n | { __typename: 'NumberTableColumn'; id: string; name: string }\n | { __typename: 'PhoneNumberTableColumn'; id: string; name: string }\n | { __typename: 'SingleLineTextTableColumn'; id: string; name: string }\n | {\n __typename: 'SingleSelectTableColumn'\n id: string\n name: string\n options: Array<{ id: string; name: string }>\n }\n | { __typename: 'URLTableColumn'; id: string; name: string }\n >\n}\n\nexport type SnippetFragment = {\n __typename: 'Snippet'\n id: string\n name: string\n code: string\n cleanup: string | null\n location: SnippetLocation\n shouldAddToNewPages: boolean\n liveEnabled: boolean\n builderEnabled: boolean\n}\n\nexport type PageFragment = {\n __typename: 'Page'\n id: string\n snippets: Array<{\n __typename: 'Snippet'\n id: string\n name: string\n code: string\n cleanup: string | null\n location: SnippetLocation\n shouldAddToNewPages: boolean\n liveEnabled: boolean\n builderEnabled: boolean\n }>\n}\n\nexport type SiteFragment = {\n __typename: 'Site'\n id: string\n googleFonts: {\n edges: Array<{\n activeVariants: Array<{ specifier: string }>\n node: { family: string; variants: Array<{ specifier: string }> }\n } | null>\n }\n}\n\nexport type UnversionedResourcesQueryVariables = Exact<{\n fileIds: Array<Scalars['ID']> | Scalars['ID']\n tableIds: Array<Scalars['ID']> | Scalars['ID']\n}>\n\nexport type UnversionedResourcesQueryResult = {\n files: Array<{\n __typename: 'File'\n id: string\n name: string\n extension: string | null\n publicUrl: string\n dimensions: { width: number; height: number } | null\n } | null>\n tables: Array<{\n __typename: 'Table'\n id: string\n name: string\n columns: Array<\n | { __typename: 'CheckboxTableColumn'; id: string; name: string }\n | { __typename: 'EmailTableColumn'; id: string; name: string }\n | { __typename: 'LongTextTableColumn'; id: string; name: string }\n | {\n __typename: 'MultipleSelectTableColumn'\n id: string\n name: string\n options: Array<{ id: string; name: string }>\n }\n | { __typename: 'NumberTableColumn'; id: string; name: string }\n | { __typename: 'PhoneNumberTableColumn'; id: string; name: string }\n | { __typename: 'SingleLineTextTableColumn'; id: string; name: string }\n | {\n __typename: 'SingleSelectTableColumn'\n id: string\n name: string\n options: Array<{ id: string; name: string }>\n }\n | { __typename: 'URLTableColumn'; id: string; name: string }\n >\n } | null>\n}\n\nexport type SwatchQueryVariables = Exact<{\n swatchId: Scalars['ID']\n}>\n\nexport type SwatchQueryResult = {\n swatch: {\n __typename: 'Swatch'\n id: string\n hue: number\n saturation: number\n lightness: number\n } | null\n}\n\nexport type FileQueryVariables = Exact<{\n fileId: Scalars['ID']\n}>\n\nexport type FileQueryResult = {\n file: {\n __typename: 'File'\n id: string\n name: string\n extension: string | null\n publicUrl: string\n dimensions: { width: number; height: number } | null\n } | null\n}\n\nexport type TypographyQueryVariables = Exact<{\n typographyId: Scalars['ID']\n}>\n\nexport type TypographyQueryResult = {\n typography: {\n __typename: 'Typography'\n id: string\n name: string\n style: Array<{\n deviceId: string\n value: {\n fontFamily: string | null\n lineHeight: number | null\n letterSpacing: number | null\n fontWeight: number | null\n textAlign: string | null\n uppercase: boolean | null\n underline: boolean | null\n strikethrough: boolean | null\n italic: boolean | null\n fontSize: { value: number | null; unit: string | null } | null\n color: { swatchId: string | null; alpha: number | null } | null\n }\n }>\n } | null\n}\n\nexport type TableQueryVariables = Exact<{\n tableId: Scalars['ID']\n}>\n\nexport type TableQueryResult = {\n table: {\n __typename: 'Table'\n id: string\n name: string\n columns: Array<\n | { __typename: 'CheckboxTableColumn'; id: string; name: string }\n | { __typename: 'EmailTableColumn'; id: string; name: string }\n | { __typename: 'LongTextTableColumn'; id: string; name: string }\n | {\n __typename: 'MultipleSelectTableColumn'\n id: string\n name: string\n options: Array<{ id: string; name: string }>\n }\n | { __typename: 'NumberTableColumn'; id: string; name: string }\n | { __typename: 'PhoneNumberTableColumn'; id: string; name: string }\n | { __typename: 'SingleLineTextTableColumn'; id: string; name: string }\n | {\n __typename: 'SingleSelectTableColumn'\n id: string\n name: string\n options: Array<{ id: string; name: string }>\n }\n | { __typename: 'URLTableColumn'; id: string; name: string }\n >\n } | null\n}\n\nexport type TypographiesQueryVariables = Exact<{\n typographyIds: Array<Scalars['ID']> | Scalars['ID']\n}>\n\nexport type TypographiesQueryResult = {\n typographies: Array<{\n __typename: 'Typography'\n id: string\n name: string\n style: Array<{\n deviceId: string\n value: {\n fontFamily: string | null\n lineHeight: number | null\n letterSpacing: number | null\n fontWeight: number | null\n textAlign: string | null\n uppercase: boolean | null\n underline: boolean | null\n strikethrough: boolean | null\n italic: boolean | null\n fontSize: { value: number | null; unit: string | null } | null\n color: { swatchId: string | null; alpha: number | null } | null\n }\n }>\n } | null>\n}\n\nexport type GlobalElementQueryVariables = Exact<{\n globalElementId: Scalars['ID']\n}>\n\nexport type GlobalElementQueryResult = {\n globalElement: { __typename: 'GlobalElement'; id: string; data: Json } | null\n}\n\nexport type CreateTableRecordMutationVariables = Exact<{\n input: CreateTableRecordInput\n}>\n\nexport type CreateTableRecordMutationResult = { createTableRecord: { tableRecord: { id: string } } }\n"],"mappings":"AA0BO,MAAM,kBAAkB;AAAA,EAC7B,MAAM;AAAA,EACN,MAAM;AACR;","names":[]}
|
|
@@ -1,13 +1,40 @@
|
|
|
1
1
|
import { GraphQLClient } from "./graphql/client";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
CreateTableRecordMutation,
|
|
4
|
+
FileQuery,
|
|
5
|
+
TableQuery,
|
|
6
|
+
UnversionedResourcesQuery
|
|
7
|
+
} from "./graphql/documents";
|
|
3
8
|
class MakeswiftGraphQLApiClient {
|
|
4
9
|
graphqlClient;
|
|
5
10
|
constructor({ endpoint }) {
|
|
6
|
-
this.graphqlClient = new GraphQLClient(endpoint
|
|
11
|
+
this.graphqlClient = new GraphQLClient(endpoint, {
|
|
12
|
+
"makeswift-runtime-version": "0.28.7-canary.6"
|
|
13
|
+
});
|
|
7
14
|
}
|
|
8
15
|
async createTableRecord(tableId, columns) {
|
|
9
16
|
await this.graphqlClient.request(CreateTableRecordMutation, { input: { data: { tableId, columns } } });
|
|
10
17
|
}
|
|
18
|
+
async getUnversionedResources({
|
|
19
|
+
fileIds,
|
|
20
|
+
tableIds
|
|
21
|
+
}) {
|
|
22
|
+
return await this.graphqlClient.request(UnversionedResourcesQuery, { fileIds, tableIds });
|
|
23
|
+
}
|
|
24
|
+
async getFile(fileId) {
|
|
25
|
+
const result = await this.graphqlClient.request(
|
|
26
|
+
FileQuery,
|
|
27
|
+
{ fileId }
|
|
28
|
+
);
|
|
29
|
+
return result.file;
|
|
30
|
+
}
|
|
31
|
+
async getTable(tableId) {
|
|
32
|
+
const result = await this.graphqlClient.request(
|
|
33
|
+
TableQuery,
|
|
34
|
+
{ tableId }
|
|
35
|
+
);
|
|
36
|
+
return result.table;
|
|
37
|
+
}
|
|
11
38
|
}
|
|
12
39
|
export {
|
|
13
40
|
MakeswiftGraphQLApiClient
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/api/graphql-api-client.ts"],"sourcesContent":["import { GraphQLClient } from './graphql/client'\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../src/api/graphql-api-client.ts"],"sourcesContent":["import { GraphQLClient } from './graphql/client'\n\nimport {\n CreateTableRecordMutation,\n FileQuery,\n TableQuery,\n UnversionedResourcesQuery,\n} from './graphql/documents'\n\nimport {\n type CreateTableRecordMutationResult,\n type CreateTableRecordMutationVariables,\n type FileQueryResult,\n type FileQueryVariables,\n type TableQueryResult,\n type TableQueryVariables,\n type UnversionedResourcesQueryResult,\n type UnversionedResourcesQueryVariables,\n} from './graphql/generated/types'\n\nimport { type File, type Table } from './types'\n\nexport class MakeswiftGraphQLApiClient {\n readonly graphqlClient: GraphQLClient\n\n constructor({ endpoint }: { endpoint: string }) {\n this.graphqlClient = new GraphQLClient(endpoint, {\n 'makeswift-runtime-version': PACKAGE_VERSION,\n })\n }\n\n async createTableRecord(tableId: string, columns: any): Promise<void> {\n await this.graphqlClient.request<\n CreateTableRecordMutationResult,\n CreateTableRecordMutationVariables\n >(CreateTableRecordMutation, { input: { data: { tableId, columns } } })\n }\n\n async getUnversionedResources({\n fileIds,\n tableIds,\n }: UnversionedResourcesQueryVariables): Promise<UnversionedResourcesQueryResult> {\n return await this.graphqlClient.request<\n UnversionedResourcesQueryResult,\n UnversionedResourcesQueryVariables\n >(UnversionedResourcesQuery, { fileIds, tableIds })\n }\n\n async getFile(fileId: string): Promise<File | null> {\n const result = await this.graphqlClient.request<FileQueryResult, FileQueryVariables>(\n FileQuery,\n { fileId },\n )\n\n return result.file\n }\n\n async getTable(tableId: string): Promise<Table | null> {\n const result = await this.graphqlClient.request<TableQueryResult, TableQueryVariables>(\n TableQuery,\n { tableId },\n )\n\n return result.table\n }\n}\n"],"mappings":"AAAA,SAAS,qBAAqB;AAE9B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAeA,MAAM,0BAA0B;AAAA,EAC5B;AAAA,EAET,YAAY,EAAE,SAAS,GAAyB;AAC9C,SAAK,gBAAgB,IAAI,cAAc,UAAU;AAAA,MAC/C,6BAA6B;AAAA,IAC/B,CAAC;AAAA,EACH;AAAA,EAEA,MAAM,kBAAkB,SAAiB,SAA6B;AACpE,UAAM,KAAK,cAAc,QAGvB,2BAA2B,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,QAAQ,EAAE,EAAE,CAAC;AAAA,EACxE;AAAA,EAEA,MAAM,wBAAwB;AAAA,IAC5B;AAAA,IACA;AAAA,EACF,GAAiF;AAC/E,WAAO,MAAM,KAAK,cAAc,QAG9B,2BAA2B,EAAE,SAAS,SAAS,CAAC;AAAA,EACpD;AAAA,EAEA,MAAM,QAAQ,QAAsC;AAClD,UAAM,SAAS,MAAM,KAAK,cAAc;AAAA,MACtC;AAAA,MACA,EAAE,OAAO;AAAA,IACX;AAEA,WAAO,OAAO;AAAA,EAChB;AAAA,EAEA,MAAM,SAAS,SAAwC;AACrD,UAAM,SAAS,MAAM,KAAK,cAAc;AAAA,MACtC;AAAA,MACA,EAAE,QAAQ;AAAA,IACZ;AAEA,WAAO,OAAO;AAAA,EAChB;AACF;","names":[]}
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
} from "./types";
|
|
6
6
|
import { ApiResourcesClient } from "./api-resources-client";
|
|
7
7
|
import { CacheData } from "./api-resources-client";
|
|
8
|
-
class
|
|
8
|
+
class HostApiResourcesClient extends ApiResourcesClient {
|
|
9
9
|
fetch;
|
|
10
10
|
constructor({
|
|
11
11
|
fetch,
|
|
@@ -54,6 +54,6 @@ class MakeswiftHostApiClient extends ApiResourcesClient {
|
|
|
54
54
|
}
|
|
55
55
|
export {
|
|
56
56
|
CacheData,
|
|
57
|
-
|
|
57
|
+
HostApiResourcesClient
|
|
58
58
|
};
|
|
59
|
-
//# sourceMappingURL=client.js.map
|
|
59
|
+
//# sourceMappingURL=host-api-resources-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/api/host-api-resources-client.ts"],"sourcesContent":["import { type State as ApiClientState } from '../state/api-client/state'\nimport { fetchAPIResource } from '../state/api-client/fetch-api-resource'\nimport { configureClientStore } from '../state/api-client/client-store'\n\nimport {\n type File,\n type GlobalElement,\n type LocalizedGlobalElement,\n type PagePathnameSlice,\n type Swatch,\n type Table,\n type Typography,\n type HttpFetch,\n APIResourceType,\n} from './types'\n\nimport { ApiResourcesClient } from './api-resources-client'\n\nexport { CacheData } from './api-resources-client'\n\n/**\n * NOTE(miguel): This \"client\" is used to fetch Makeswift API resources needed for the host. For\n * example, swatches, files, typographies, etc. Ideally it's internal to the runtime and is only\n * used by controls to transform API references to API resources.\n *\n * Moreover, its use should be reserved for the builder only, since for live pages all Makeswift\n * API resources should be embedded in the \"page snapshot\". In the builder, this client serves the\n * purpose of sending requests for API resources and keeping a cache so that changes that happen in\n * the builder, like modifying a swatch, can be sent via `postMessage` to the host and the cache can\n * immediately update the value and re-render.\n *\n * Furthermore, the API resources requested shouldn't be requested directly from the Makeswift API\n * as that would require those resources to not be authenticated since the requests come from the\n * browser when running the host. Instead, the requests should go to the host directly, at the\n * Makeswift API endpoint (i.g., `/api/makeswift/[...makeswift]` dynamic route) where the host's\n * API key can be used, securely, in the server. For this reason, this client should really be a\n * client of the host's API, not Makeswift's, intended to build and continuously maintain a realtime\n * snapshot for use in the builder, not the lives pages.\n */\nexport class HostApiResourcesClient extends ApiResourcesClient {\n readonly fetch: HttpFetch\n\n constructor({\n fetch,\n preloadedState,\n }: {\n fetch: HttpFetch\n preloadedState: Partial<ApiClientState>\n }) {\n super({\n store: configureClientStore({ preloadedState }),\n })\n\n this.fetch = fetch\n }\n\n async fetchSwatch(swatchId: string): Promise<Swatch | null> {\n return await this.store.dispatch(fetchAPIResource(APIResourceType.Swatch, swatchId, this.fetch))\n }\n\n async fetchFile(fileId: string): Promise<File | null> {\n return await this.store.dispatch(fetchAPIResource(APIResourceType.File, fileId, this.fetch))\n }\n\n async fetchTypography(typographyId: string): Promise<Typography | null> {\n return await this.store.dispatch(\n fetchAPIResource(APIResourceType.Typography, typographyId, this.fetch),\n )\n }\n\n async fetchGlobalElement(globalElementId: string): Promise<GlobalElement | null> {\n return await this.store.dispatch(\n fetchAPIResource(APIResourceType.GlobalElement, globalElementId, this.fetch),\n )\n }\n\n async fetchLocalizedGlobalElement({\n globalElementId,\n locale,\n }: {\n globalElementId: string\n locale: string\n }): Promise<LocalizedGlobalElement | null> {\n return await this.store.dispatch(\n fetchAPIResource(APIResourceType.LocalizedGlobalElement, globalElementId, this.fetch, locale),\n )\n }\n\n async fetchPagePathnameSlice({\n pageId,\n locale,\n }: {\n pageId: string\n locale: string | null\n }): Promise<PagePathnameSlice | null> {\n return await this.store.dispatch(\n fetchAPIResource(APIResourceType.PagePathnameSlice, pageId, this.fetch, locale),\n )\n }\n\n async fetchTable(tableId: string): Promise<Table | null> {\n return await this.store.dispatch(fetchAPIResource(APIResourceType.Table, tableId, this.fetch))\n }\n}\n"],"m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