@makeswift/runtime 0.28.7-canary.3 → 0.28.7-canary.4
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/client.js +0 -8
- package/dist/cjs/api/client.js.map +1 -1
- package/dist/cjs/api/graphql-api-client.js +39 -0
- package/dist/cjs/api/graphql-api-client.js.map +1 -0
- package/dist/cjs/api-handler/handlers/manifest.js +1 -1
- package/dist/cjs/client/index.js +3 -3
- package/dist/cjs/components/builtin/Form/Form.js +2 -2
- package/dist/cjs/components/builtin/Form/Form.js.map +1 -1
- package/dist/cjs/runtimes/react/components/GoogleFontLink.js +2 -2
- package/dist/cjs/runtimes/react/components/GoogleFontLink.js.map +1 -1
- package/dist/cjs/runtimes/react/components/hooks/use-page-snippets.js +2 -2
- package/dist/cjs/runtimes/react/components/hooks/use-page-snippets.js.map +1 -1
- package/dist/cjs/runtimes/react/components/page/PageHead.js +2 -2
- package/dist/cjs/runtimes/react/components/page/PageHead.js.map +1 -1
- package/dist/cjs/runtimes/react/hooks/makeswift-api.js +10 -10
- package/dist/cjs/runtimes/react/hooks/makeswift-api.js.map +1 -1
- package/dist/cjs/runtimes/react/{host-api-client.js → hooks/use-api-resources-client.js} +9 -9
- package/dist/cjs/runtimes/react/hooks/use-api-resources-client.js.map +1 -0
- package/dist/cjs/runtimes/react/hooks/use-cache-data.js +2 -2
- package/dist/cjs/runtimes/react/hooks/use-cache-data.js.map +1 -1
- package/dist/cjs/runtimes/react/hooks/use-graphql-api-client.js +35 -0
- package/dist/cjs/runtimes/react/hooks/use-graphql-api-client.js.map +1 -0
- package/dist/cjs/runtimes/react/hooks/use-resource-resolver.js +3 -3
- package/dist/cjs/runtimes/react/hooks/use-resource-resolver.js.map +1 -1
- package/dist/cjs/runtimes/react/runtime-core.js +11 -6
- package/dist/cjs/runtimes/react/runtime-core.js.map +1 -1
- package/dist/cjs/state/middleware/makeswift-api-client-sync.js.map +1 -1
- package/dist/cjs/state/store.js +3 -3
- package/dist/cjs/state/store.js.map +1 -1
- package/dist/esm/api/client.js +0 -8
- package/dist/esm/api/client.js.map +1 -1
- package/dist/esm/api/graphql-api-client.js +15 -0
- package/dist/esm/api/graphql-api-client.js.map +1 -0
- package/dist/esm/api-handler/handlers/manifest.js +1 -1
- package/dist/esm/client/index.js +3 -3
- package/dist/esm/components/builtin/Form/Form.js +2 -2
- package/dist/esm/components/builtin/Form/Form.js.map +1 -1
- package/dist/esm/runtimes/react/components/GoogleFontLink.js +2 -2
- package/dist/esm/runtimes/react/components/GoogleFontLink.js.map +1 -1
- package/dist/esm/runtimes/react/components/hooks/use-page-snippets.js +2 -2
- package/dist/esm/runtimes/react/components/hooks/use-page-snippets.js.map +1 -1
- package/dist/esm/runtimes/react/components/page/PageHead.js +2 -2
- package/dist/esm/runtimes/react/components/page/PageHead.js.map +1 -1
- package/dist/esm/runtimes/react/hooks/makeswift-api.js +10 -10
- package/dist/esm/runtimes/react/hooks/makeswift-api.js.map +1 -1
- package/dist/esm/runtimes/react/hooks/use-api-resources-client.js +9 -0
- package/dist/esm/runtimes/react/hooks/use-api-resources-client.js.map +1 -0
- package/dist/esm/runtimes/react/hooks/use-cache-data.js +2 -2
- package/dist/esm/runtimes/react/hooks/use-cache-data.js.map +1 -1
- package/dist/esm/runtimes/react/hooks/use-graphql-api-client.js +11 -0
- package/dist/esm/runtimes/react/hooks/use-graphql-api-client.js.map +1 -0
- package/dist/esm/runtimes/react/hooks/use-resource-resolver.js +3 -3
- package/dist/esm/runtimes/react/hooks/use-resource-resolver.js.map +1 -1
- package/dist/esm/runtimes/react/runtime-core.js +11 -6
- package/dist/esm/runtimes/react/runtime-core.js.map +1 -1
- package/dist/esm/state/middleware/makeswift-api-client-sync.js.map +1 -1
- package/dist/esm/state/store.js +3 -3
- package/dist/esm/state/store.js.map +1 -1
- package/dist/types/api/client.d.ts +1 -5
- package/dist/types/api/client.d.ts.map +1 -1
- package/dist/types/api/graphql-api-client.d.ts +9 -0
- package/dist/types/api/graphql-api-client.d.ts.map +1 -0
- package/dist/types/runtimes/react/components/GoogleFontLink.d.ts.map +1 -1
- package/dist/types/runtimes/react/components/page/PageHead.d.ts.map +1 -1
- package/dist/types/runtimes/react/hooks/use-api-resources-client.d.ts +3 -0
- package/dist/types/runtimes/react/hooks/use-api-resources-client.d.ts.map +1 -0
- package/dist/types/runtimes/react/hooks/use-graphql-api-client.d.ts +3 -0
- package/dist/types/runtimes/react/hooks/use-graphql-api-client.d.ts.map +1 -0
- package/dist/types/runtimes/react/runtime-core.d.ts +2 -0
- package/dist/types/runtimes/react/runtime-core.d.ts.map +1 -1
- package/dist/types/state/middleware/makeswift-api-client-sync.d.ts +2 -2
- package/dist/types/state/middleware/makeswift-api-client-sync.d.ts.map +1 -1
- package/dist/types/state/store.d.ts +4 -4
- package/dist/types/state/store.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/cjs/runtimes/react/host-api-client.js.map +0 -1
- package/dist/esm/runtimes/react/host-api-client.js +0 -9
- package/dist/esm/runtimes/react/host-api-client.js.map +0 -1
- package/dist/types/runtimes/react/host-api-client.d.ts +0 -3
- package/dist/types/runtimes/react/host-api-client.d.ts.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useMemo, useSyncExternalStore } from "react";
|
|
3
|
-
import {
|
|
3
|
+
import { useApiResourcesClient } from "../../hooks/use-api-resources-client";
|
|
4
4
|
import { useFrameworkContext } from "../hooks/use-framework-context";
|
|
5
5
|
import { useIsInBuilder } from "../../hooks/use-is-in-builder";
|
|
6
6
|
import { usePageSnippets } from "../hooks/use-page-snippets";
|
|
@@ -86,7 +86,7 @@ function PageHead({ document: page, metadata = {} }) {
|
|
|
86
86
|
] });
|
|
87
87
|
}
|
|
88
88
|
function useCachedSite(siteId) {
|
|
89
|
-
const client =
|
|
89
|
+
const client = useApiResourcesClient();
|
|
90
90
|
const getSnapshot = () => siteId == null ? null : client.readSite(siteId);
|
|
91
91
|
const site = useSyncExternalStore(client.subscribe, getSnapshot, getSnapshot);
|
|
92
92
|
return site;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../src/runtimes/react/components/page/PageHead.tsx"],"sourcesContent":["import { useMemo, useSyncExternalStore, ReactNode } from 'react'\n\nimport { type MakeswiftPageDocument } from '../../../../client'\nimport { type Site } from '../../../../api'\n\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../../../../src/runtimes/react/components/page/PageHead.tsx"],"sourcesContent":["import { useMemo, useSyncExternalStore, ReactNode } from 'react'\n\nimport { type MakeswiftPageDocument } from '../../../../client'\nimport { type Site } from '../../../../api'\n\nimport { useApiResourcesClient } from '../../hooks/use-api-resources-client'\nimport { useFrameworkContext } from '../hooks/use-framework-context'\nimport { useIsInBuilder } from '../../hooks/use-is-in-builder'\nimport { usePageSnippets } from '../hooks/use-page-snippets'\n\nimport { PageTitle, PageMeta, PageLink, PageStyle } from './head-tags'\nimport { type PageMetadataSettings } from './page-seo-settings'\n\nconst defaultFavicon = {\n id: 'default-favicon',\n mimetype: 'image/png',\n publicUrl:\n 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACIAAAAiCAYAAAA6RwvCAAAACXBIWXMAABcRAAAXEQHKJvM/AAABjElEQVRYhc2XzU3EMBCFB8TddAAXn6EE6GCpgNABZ1/IXnymBOgAOmA7YM8+ABVsXEHQQFaKQryeN3Yk3ilKJtEnv/nLUd/3pFG0riGi88yrnQn+UfJ5FUi0riWiB2H4nQn+KRd0DFP8agXEfkqCYJBoHdtxIQxfm+DfFgEhoith3NYE30o/qgGR2BJB+xY7kdYEL8oNFUi0jiFMJuxVWrJqEMFxsyUNCsE6AeNztvBp7aJ143vXksoRnwhYtmNdSoIQa6RlO9YXEWW7KgoCleOgxgTf1QZBT+RZ2lXFING6UxCCq+ceeUE8fYdknY599v9sJvzGBP+yCEgC7GPmETc0OJ+0awAlkhe2pAbIXAeFZ8xe2g2Nk3c3ub0xwWt6zY9qbmiqGVMbZK21ZC/YmhlbeBMTzZNDQqcvDb1kM1x32iqZSt1HaqukfKvq34BAOTLsrH+ETNmUkKHHA+428RgeclPVWozeSyAI2EdWB34jtqXNTAySOY3i/KgFIlqOa4GkFmBegorzg4joG07he/M7zl6jAAAAAElFTkSuQmCC',\n}\n\ntype Props = {\n document: MakeswiftPageDocument\n metadata?: PageMetadataSettings\n}\n\nexport function PageHead({ document: page, metadata = {} }: Props): ReactNode {\n const {\n title: useTitle = false,\n favicon: useFavicon = false,\n canonicalUrl: useCanonicalUrl = false,\n indexingBlocked: useIndexingBlocked = false,\n description: useDescription = false,\n keywords: useKeywords = false,\n socialImage: useSocialImage = false,\n } = metadata\n\n const { headSnippets } = usePageSnippets({ page })\n const { HeadSnippet } = useFrameworkContext()\n\n const isInBuilder = useIsInBuilder()\n\n const site = useCachedSite(isInBuilder ? page.site.id : null)\n const baseLocalizedPage = page.localizedPages.find(({ parentId }) => parentId == null)\n\n const favicon = page.meta.favicon ?? defaultFavicon\n const title = baseLocalizedPage?.meta.title ?? page.meta.title\n const description = baseLocalizedPage?.meta.description ?? page.meta.description\n const keywords = baseLocalizedPage?.meta.keywords ?? page.meta.keywords\n const socialImage = baseLocalizedPage?.meta.socialImage ?? page.meta.socialImage\n const canonicalUrl = baseLocalizedPage?.seo.canonicalUrl ?? page.seo.canonicalUrl\n const isIndexingBlocked = baseLocalizedPage?.seo.isIndexingBlocked ?? page.seo.isIndexingBlocked\n\n const fontFamilyParamValue = useMemo(() => {\n if (site == null) {\n return page.fonts\n .map(({ family, variants }) => {\n return `${family.replace(/ /g, '+')}:${variants.join()}`\n })\n .join('|')\n }\n\n return site.googleFonts.edges\n .filter((edge): edge is NonNullable<typeof edge> => edge != null)\n .map(({ activeVariants, node: { family, variants } }) => {\n const activeVariantSpecifiers = variants\n .filter(variant =>\n activeVariants.some(activeVariant => activeVariant.specifier === variant.specifier),\n )\n .map(variant => variant.specifier)\n .join()\n\n return `${family.replace(/ /g, '+')}:${activeVariantSpecifiers}`\n })\n .join('|')\n }, [site, page])\n\n return (\n <>\n <PageStyle precedence=\"high\" href=\"makeswift-base-styles\">\n {`\n html {\n font-family: sans-serif;\n }\n div#__next {\n overflow: hidden;\n }\n `}\n </PageStyle>\n {useTitle && title && (\n <>\n <PageTitle>{title}</PageTitle>\n <PageMeta property=\"og:title\" content={title} />\n <PageMeta name=\"twitter:title\" content={title} />\n </>\n )}\n {useFavicon && favicon && (\n <PageLink rel=\"icon\" type={favicon.mimetype} href={favicon.publicUrl} />\n )}\n {useCanonicalUrl && canonicalUrl && <PageLink rel=\"canonical\" href={canonicalUrl} />}\n {useIndexingBlocked && isIndexingBlocked && <PageMeta name=\"robots\" content=\"noindex\" />}\n {useDescription && description && (\n <>\n <PageMeta name=\"description\" content={description} />\n <PageMeta property=\"og:description\" content={description} />\n <PageMeta name=\"twitter:description\" content={description} />\n </>\n )}\n {useKeywords && keywords && <PageMeta name=\"keywords\" content={keywords} />}\n {useSocialImage && socialImage && (\n <>\n <PageMeta property=\"og:image\" content={socialImage.publicUrl} />\n <PageMeta property=\"og:image:type\" content={socialImage.mimetype} />\n <PageMeta name=\"twitter:image\" content={socialImage.publicUrl} />\n <PageMeta name=\"twitter:card\" content=\"summary_large_image\" />\n </>\n )}\n {fontFamilyParamValue !== '' && (\n <PageLink\n precedence=\"medium\"\n rel=\"stylesheet\"\n href={`https://fonts.googleapis.com/css?family=${fontFamilyParamValue}&display=swap`}\n />\n )}\n {headSnippets.map(snippet => (\n <HeadSnippet key={snippet.id} snippet={snippet} />\n ))}\n </>\n )\n}\n\nfunction useCachedSite(siteId: string | null): Site | null {\n const client = useApiResourcesClient()\n const getSnapshot = () => (siteId == null ? null : client.readSite(siteId))\n\n const site = useSyncExternalStore(client.subscribe, getSnapshot, getSnapshot)\n\n return site\n}\n"],"mappings":"AA8EM,SAWE,UAXF,KAWE,YAXF;AA9EN,SAAS,SAAS,4BAAuC;AAKzD,S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AAW,SAAS,UAAU;AAAA,IACxE,kBAAkB,eACjB,iCACE;AAAA,0BAAC,YAAS,UAAS,YAAW,SAAS,YAAY,WAAW;AAAA,MAC9D,oBAAC,YAAS,UAAS,iBAAgB,SAAS,YAAY,UAAU;AAAA,MAClE,oBAAC,YAAS,MAAK,iBAAgB,SAAS,YAAY,WAAW;AAAA,MAC/D,oBAAC,YAAS,MAAK,gBAAe,SAAQ,uBAAsB;AAAA,OAC9D;AAAA,IAED,yBAAyB,MACxB;AAAA,MAAC;AAAA;AAAA,QACC,YAAW;AAAA,QACX,KAAI;AAAA,QACJ,MAAM,2CAA2C,oBAAoB;AAAA;AAAA,IACvE;AAAA,IAED,aAAa,IAAI,aAChB,oBAAC,eAA6B,WAAZ,QAAQ,EAAsB,CACjD;AAAA,KACH;AAEJ;AAEA,SAAS,cAAc,QAAoC;AACzD,QAAM,SAAS,sBAAsB;AACrC,QAAM,cAAc,MAAO,UAAU,OAAO,OAAO,OAAO,SAAS,MAAM;AAEzE,QAAM,OAAO,qBAAqB,OAAO,WAAW,aAAa,WAAW;AAE5E,SAAO;AACT;","names":[]}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { useEffect, useRef, useSyncExternalStore } from "react";
|
|
3
|
-
import {
|
|
3
|
+
import { useApiResourcesClient } from "./use-api-resources-client";
|
|
4
4
|
import { useDocumentLocale } from "./use-document-context";
|
|
5
5
|
function useSwatch(swatchId) {
|
|
6
|
-
const client =
|
|
6
|
+
const client = useApiResourcesClient();
|
|
7
7
|
const readSwatch = () => swatchId == null ? null : client.readSwatch(swatchId);
|
|
8
8
|
const swatch = useSyncExternalStore(client.subscribe, readSwatch, readSwatch);
|
|
9
9
|
useEffect(() => {
|
|
@@ -13,7 +13,7 @@ function useSwatch(swatchId) {
|
|
|
13
13
|
return swatch;
|
|
14
14
|
}
|
|
15
15
|
function useSwatches(swatchIds) {
|
|
16
|
-
const client =
|
|
16
|
+
const client = useApiResourcesClient();
|
|
17
17
|
const lastSnapshot = useRef(null);
|
|
18
18
|
function getSnapshot() {
|
|
19
19
|
const swatches2 = swatchIds.map((swatchId) => client.readSwatch(swatchId));
|
|
@@ -29,7 +29,7 @@ function useSwatches(swatchIds) {
|
|
|
29
29
|
return swatches;
|
|
30
30
|
}
|
|
31
31
|
function useFile(fileId) {
|
|
32
|
-
const client =
|
|
32
|
+
const client = useApiResourcesClient();
|
|
33
33
|
const readFile = () => fileId == null ? null : client.readFile(fileId);
|
|
34
34
|
const file = useSyncExternalStore(client.subscribe, readFile, readFile);
|
|
35
35
|
useEffect(() => {
|
|
@@ -39,7 +39,7 @@ function useFile(fileId) {
|
|
|
39
39
|
return file;
|
|
40
40
|
}
|
|
41
41
|
function useFiles(fileIds) {
|
|
42
|
-
const client =
|
|
42
|
+
const client = useApiResourcesClient();
|
|
43
43
|
const lastSnapshot = useRef(null);
|
|
44
44
|
function getSnapshot() {
|
|
45
45
|
const files2 = fileIds.map((fileId) => client.readFile(fileId));
|
|
@@ -55,7 +55,7 @@ function useFiles(fileIds) {
|
|
|
55
55
|
return files;
|
|
56
56
|
}
|
|
57
57
|
function useTypography(typographyId) {
|
|
58
|
-
const client =
|
|
58
|
+
const client = useApiResourcesClient();
|
|
59
59
|
const readTypography = () => typographyId == null ? null : client.readTypography(typographyId);
|
|
60
60
|
const typography = useSyncExternalStore(client.subscribe, readTypography, readTypography);
|
|
61
61
|
useEffect(() => {
|
|
@@ -65,7 +65,7 @@ function useTypography(typographyId) {
|
|
|
65
65
|
return typography;
|
|
66
66
|
}
|
|
67
67
|
function useGlobalElement(globalElementId) {
|
|
68
|
-
const client =
|
|
68
|
+
const client = useApiResourcesClient();
|
|
69
69
|
const readGlobalElement = () => globalElementId == null ? null : client.readGlobalElement(globalElementId);
|
|
70
70
|
const globalElement = useSyncExternalStore(client.subscribe, readGlobalElement, readGlobalElement);
|
|
71
71
|
useEffect(() => {
|
|
@@ -75,7 +75,7 @@ function useGlobalElement(globalElementId) {
|
|
|
75
75
|
return globalElement;
|
|
76
76
|
}
|
|
77
77
|
function useLocalizedGlobalElement(locale, globalElementId) {
|
|
78
|
-
const client =
|
|
78
|
+
const client = useApiResourcesClient();
|
|
79
79
|
const readLocalizedGlobalElement = () => locale == null || globalElementId == null ? null : client.readLocalizedGlobalElement({ globalElementId, locale });
|
|
80
80
|
const localizedGlobalElement = useSyncExternalStore(
|
|
81
81
|
client.subscribe,
|
|
@@ -90,7 +90,7 @@ function useLocalizedGlobalElement(locale, globalElementId) {
|
|
|
90
90
|
return localizedGlobalElement;
|
|
91
91
|
}
|
|
92
92
|
function usePagePathnameSlice(pageId) {
|
|
93
|
-
const client =
|
|
93
|
+
const client = useApiResourcesClient();
|
|
94
94
|
const locale = useDocumentLocale();
|
|
95
95
|
const readPagePathnameSlice = () => pageId == null ? null : client.readPagePathnameSlice({ pageId, locale });
|
|
96
96
|
const pagePathnameSlice = useSyncExternalStore(
|
|
@@ -105,7 +105,7 @@ function usePagePathnameSlice(pageId) {
|
|
|
105
105
|
return pagePathnameSlice;
|
|
106
106
|
}
|
|
107
107
|
function useTable(tableId) {
|
|
108
|
-
const client =
|
|
108
|
+
const client = useApiResourcesClient();
|
|
109
109
|
const readTable = () => tableId == null ? null : client.readTable(tableId);
|
|
110
110
|
const table = useSyncExternalStore(client.subscribe, readTable, readTable);
|
|
111
111
|
useEffect(() => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/runtimes/react/hooks/makeswift-api.ts"],"sourcesContent":["'use client'\n\nimport { useEffect, useRef, useSyncExternalStore } from 'react'\nimport {\n File,\n GlobalElement,\n LocalizedGlobalElement,\n PagePathnameSlice,\n Swatch,\n Table,\n Typography,\n} from '../../../api'\n\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../../../src/runtimes/react/hooks/makeswift-api.ts"],"sourcesContent":["'use client'\n\nimport { useEffect, useRef, useSyncExternalStore } from 'react'\nimport {\n File,\n GlobalElement,\n LocalizedGlobalElement,\n PagePathnameSlice,\n Swatch,\n Table,\n Typography,\n} from '../../../api'\n\nimport { useApiResourcesClient } from './use-api-resources-client'\nimport { useDocumentLocale } from './use-document-context'\n\nexport function useSwatch(swatchId: string | null): Swatch | null {\n const client = useApiResourcesClient()\n const readSwatch = () => (swatchId == null ? null : client.readSwatch(swatchId))\n const swatch = useSyncExternalStore(client.subscribe, readSwatch, readSwatch)\n\n useEffect(() => {\n if (swatchId != null) client.fetchSwatch(swatchId).catch(console.error)\n }, [client, swatchId])\n\n return swatch\n}\n\nexport function useSwatches(swatchIds: string[]): (Swatch | null)[] {\n const client = useApiResourcesClient()\n const lastSnapshot = useRef<(Swatch | null)[] | null>(null)\n\n function getSnapshot() {\n const swatches = swatchIds.map(swatchId => client.readSwatch(swatchId))\n\n if (\n lastSnapshot.current != null &&\n lastSnapshot.current.length === swatches.length &&\n lastSnapshot.current.every((swatch, idx) => swatches[idx] === swatch)\n ) {\n return lastSnapshot.current\n }\n\n return (lastSnapshot.current = swatches)\n }\n\n const swatches = useSyncExternalStore(client.subscribe, getSnapshot, getSnapshot)\n\n useEffect(() => {\n Promise.all(swatchIds.map(swatchId => client.fetchSwatch(swatchId))).catch(console.error)\n }, [client, swatchIds])\n\n return swatches\n}\n\nexport function useFile(fileId: string | null): File | null {\n const client = useApiResourcesClient()\n const readFile = () => (fileId == null ? null : client.readFile(fileId))\n const file = useSyncExternalStore(client.subscribe, readFile, readFile)\n\n useEffect(() => {\n if (fileId != null) client.fetchFile(fileId)\n }, [client, fileId])\n\n return file\n}\n\nexport function useFiles(fileIds: string[]): (File | null)[] {\n const client = useApiResourcesClient()\n const lastSnapshot = useRef<(File | null)[] | null>(null)\n\n function getSnapshot() {\n const files = fileIds.map(fileId => client.readFile(fileId))\n\n if (\n lastSnapshot.current != null &&\n lastSnapshot.current.length === files.length &&\n lastSnapshot.current.every((file, idx) => files[idx] === file)\n ) {\n return lastSnapshot.current\n }\n\n return (lastSnapshot.current = files)\n }\n\n const files = useSyncExternalStore(client.subscribe, getSnapshot, getSnapshot)\n\n useEffect(() => {\n Promise.all(fileIds.map(fileId => client.fetchFile(fileId))).catch(console.error)\n }, [client, fileIds])\n\n return files\n}\n\nexport function useTypography(typographyId: string | null): Typography | null {\n const client = useApiResourcesClient()\n const readTypography = () => (typographyId == null ? null : client.readTypography(typographyId))\n const typography = useSyncExternalStore(client.subscribe, readTypography, readTypography)\n\n useEffect(() => {\n if (typographyId != null) client.fetchTypography(typographyId).catch(console.error)\n }, [client, typographyId])\n\n return typography\n}\n\nexport function useGlobalElement(globalElementId: string | null): GlobalElement | null {\n const client = useApiResourcesClient()\n const readGlobalElement = () =>\n globalElementId == null ? null : client.readGlobalElement(globalElementId)\n const globalElement = useSyncExternalStore(client.subscribe, readGlobalElement, readGlobalElement)\n\n useEffect(() => {\n if (globalElementId != null) client.fetchGlobalElement(globalElementId).catch(console.error)\n }, [client, globalElementId])\n\n return globalElement\n}\n\nexport function useLocalizedGlobalElement(\n locale: string | null,\n globalElementId: string | null,\n): LocalizedGlobalElement | null {\n const client = useApiResourcesClient()\n const readLocalizedGlobalElement = () =>\n locale == null || globalElementId == null\n ? null\n : client.readLocalizedGlobalElement({ globalElementId, locale })\n\n const localizedGlobalElement = useSyncExternalStore(\n client.subscribe,\n readLocalizedGlobalElement,\n readLocalizedGlobalElement,\n )\n\n useEffect(() => {\n if (locale != null && globalElementId != null) {\n client.fetchLocalizedGlobalElement({ globalElementId, locale }).catch(console.error)\n }\n }, [client, locale, globalElementId])\n\n return localizedGlobalElement\n}\n\nexport function usePagePathnameSlice(pageId: string | null): PagePathnameSlice | null {\n const client = useApiResourcesClient()\n const locale = useDocumentLocale()\n\n const readPagePathnameSlice = () =>\n pageId == null ? null : client.readPagePathnameSlice({ pageId, locale })\n\n const pagePathnameSlice = useSyncExternalStore(\n client.subscribe,\n readPagePathnameSlice,\n readPagePathnameSlice,\n )\n\n useEffect(() => {\n if (pageId != null) client.fetchPagePathnameSlice({ pageId, locale }).catch(console.error)\n }, [client, pageId, locale])\n\n return pagePathnameSlice\n}\n\nexport function useTable(tableId: string | null): Table | null {\n const client = useApiResourcesClient()\n const readTable = () => (tableId == null ? null : client.readTable(tableId))\n const table = useSyncExternalStore(client.subscribe, readTable, readTable)\n\n useEffect(() => {\n if (tableId != null) client.fetchTable(tableId).catch(console.error)\n }, [client, tableId])\n\n return table\n}\n"],"mappings":";AAEA,SAAS,WAAW,QAAQ,4BAA4B;AAWxD,SAAS,6BAA6B;AACtC,SAAS,yBAAyB;AAE3B,SAAS,UAAU,UAAwC;AAChE,QAAM,SAAS,sBAAsB;AACrC,QAAM,aAAa,MAAO,YAAY,OAAO,OAAO,OAAO,WAAW,QAAQ;AAC9E,QAAM,SAAS,qBAAqB,OAAO,WAAW,YAAY,UAAU;AAE5E,YAAU,MAAM;AACd,QAAI,YAAY;AAAM,aAAO,YAAY,QAAQ,EAAE,MAAM,QAAQ,KAAK;AAAA,EACxE,GAAG,CAAC,QAAQ,QAAQ,CAAC;AAErB,SAAO;AACT;AAEO,SAAS,YAAY,WAAwC;AAClE,QAAM,SAAS,sBAAsB;AACrC,QAAM,eAAe,OAAiC,IAAI;AAE1D,WAAS,cAAc;AACrB,UAAMA,YAAW,UAAU,IAAI,cAAY,OAAO,WAAW,QAAQ,CAAC;AAEtE,QACE,aAAa,WAAW,QACxB,aAAa,QAAQ,WAAWA,UAAS,UACzC,aAAa,QAAQ,MAAM,CAAC,QAAQ,QAAQA,UAAS,GAAG,MAAM,MAAM,GACpE;AACA,aAAO,aAAa;AAAA,IACtB;AAEA,WAAQ,aAAa,UAAUA;AAAA,EACjC;AAEA,QAAM,WAAW,qBAAqB,OAAO,WAAW,aAAa,WAAW;AAEhF,YAAU,MAAM;AACd,YAAQ,IAAI,UAAU,IAAI,cAAY,OAAO,YAAY,QAAQ,CAAC,CAAC,EAAE,MAAM,QAAQ,KAAK;AAAA,EAC1F,GAAG,CAAC,QAAQ,SAAS,CAAC;AAEtB,SAAO;AACT;AAEO,SAAS,QAAQ,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AAO,OAAO,UAAU,OAAO;AAC1E,QAAM,QAAQ,qBAAqB,OAAO,WAAW,WAAW,SAAS;AAEzE,YAAU,MAAM;AACd,QAAI,WAAW;AAAM,aAAO,WAAW,OAAO,EAAE,MAAM,QAAQ,KAAK;AAAA,EACrE,GAAG,CAAC,QAAQ,OAAO,CAAC;AAEpB,SAAO;AACT;","names":["swatches","files"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/runtimes/react/hooks/use-api-resources-client.tsx"],"sourcesContent":["'use client'\n\nimport { ApiResourcesClient } from '../../../api/api-resources-client'\n\nimport { useStore } from './use-store'\n\nexport function useApiResourcesClient(): ApiResourcesClient {\n return useStore().apiResourcesClient\n}\n"],"mappings":";AAIA,SAAS,gBAAgB;AAElB,SAAS,wBAA4C;AAC1D,SAAO,SAAS,EAAE;AACpB;","names":[]}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { useMemo } from "react";
|
|
2
2
|
import { updateAPIClientCache } from "../../../state/actions/internal/read-write-actions";
|
|
3
|
-
import {
|
|
3
|
+
import { useApiResourcesClient } from "./use-api-resources-client";
|
|
4
4
|
function useCacheData(cacheData) {
|
|
5
|
-
const { store: apiStore } =
|
|
5
|
+
const { store: apiStore } = useApiResourcesClient();
|
|
6
6
|
useMemo(() => apiStore.dispatch(updateAPIClientCache(cacheData)), [cacheData]);
|
|
7
7
|
}
|
|
8
8
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/runtimes/react/hooks/use-cache-data.ts"],"sourcesContent":["import { useMemo } from 'react'\nimport { type CacheData } from '../../../api/client'\nimport { updateAPIClientCache } from '../../../state/actions/internal/read-write-actions'\n\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../../../src/runtimes/react/hooks/use-cache-data.ts"],"sourcesContent":["import { useMemo } from 'react'\nimport { type CacheData } from '../../../api/client'\nimport { updateAPIClientCache } from '../../../state/actions/internal/read-write-actions'\n\nimport { useApiResourcesClient } from './use-api-resources-client'\n\nexport function useCacheData(cacheData: CacheData) {\n const { store: apiStore } = useApiResourcesClient()\n\n // We perform cache hydration immediately on render - this is safe to do per\n // render because updating the API cache is idempotent. For precedence, see:\n //\n // https://github.com/TanStack/query/blob/8f9f183f11df3709a1a38c4efce1452788041f88/packages/react-query/src/HydrationBoundary.tsx#L41\n useMemo(() => apiStore.dispatch(updateAPIClientCache(cacheData)), [cacheData])\n}\n"],"mappings":"AAAA,SAAS,eAAe;AAExB,SAAS,4BAA4B;AAErC,SAAS,6BAA6B;AAE/B,SAAS,aAAa,WAAsB;AACjD,QAAM,EAAE,OAAO,SAAS,IAAI,sBAAsB;AAMlD,UAAQ,MAAM,SAAS,SAAS,qBAAqB,SAAS,CAAC,GAAG,CAAC,SAAS,CAAC;AAC/E;","names":[]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { MakeswiftGraphQLApiClient } from "../../../api/graphql-api-client";
|
|
3
|
+
import { useReactRuntime } from "./use-react-runtime";
|
|
4
|
+
function useMakeswiftGraphQLApiClient() {
|
|
5
|
+
const runtime = useReactRuntime();
|
|
6
|
+
return new MakeswiftGraphQLApiClient({ endpoint: runtime.graphqlApiEndpoint });
|
|
7
|
+
}
|
|
8
|
+
export {
|
|
9
|
+
useMakeswiftGraphQLApiClient
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=use-graphql-api-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/runtimes/react/hooks/use-graphql-api-client.tsx"],"sourcesContent":["'use client'\n\nimport { MakeswiftGraphQLApiClient } from '../../../api/graphql-api-client'\n\nimport { useReactRuntime } from './use-react-runtime'\n\nexport function useMakeswiftGraphQLApiClient(): MakeswiftGraphQLApiClient {\n const runtime = useReactRuntime()\n return new MakeswiftGraphQLApiClient({ endpoint: runtime.graphqlApiEndpoint })\n}\n"],"mappings":";AAEA,SAAS,iCAAiC;AAE1C,SAAS,uBAAuB;AAEzB,SAAS,+BAA0D;AACxE,QAAM,UAAU,gBAAgB;AAChC,SAAO,IAAI,0BAA0B,EAAE,UAAU,QAAQ,mBAAmB,CAAC;AAC/E;","names":[]}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { useMemo } from "react";
|
|
2
|
-
import { useMakeswiftHostApiClient } from "../host-api-client";
|
|
3
2
|
import { createResourceResolver } from "../resource-resolver";
|
|
4
|
-
import {
|
|
3
|
+
import { useApiResourcesClient } from "./use-api-resources-client";
|
|
5
4
|
import { useDocumentKey, useDocumentLocale } from "./use-document-context";
|
|
5
|
+
import { useStore } from "./use-store";
|
|
6
6
|
function useResourceResolver() {
|
|
7
7
|
const store = useStore();
|
|
8
|
-
const apiClient =
|
|
8
|
+
const apiClient = useApiResourcesClient();
|
|
9
9
|
const documentKey = useDocumentKey();
|
|
10
10
|
const locale = useDocumentLocale();
|
|
11
11
|
return useMemo(
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/runtimes/react/hooks/use-resource-resolver.ts"],"sourcesContent":["import { useMemo } from 'react'\nimport { type ResourceResolver } from '@makeswift/controls'\n\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../../../src/runtimes/react/hooks/use-resource-resolver.ts"],"sourcesContent":["import { useMemo } from 'react'\nimport { type ResourceResolver } from '@makeswift/controls'\n\nimport { createResourceResolver } from '../resource-resolver'\n\nimport { useApiResourcesClient } from './use-api-resources-client'\nimport { useDocumentKey, useDocumentLocale } from './use-document-context'\nimport { useStore } from './use-store'\n\nexport function useResourceResolver(): ResourceResolver {\n const store = useStore()\n const apiClient = useApiResourcesClient()\n\n const documentKey = useDocumentKey()\n const locale = useDocumentLocale()\n\n return useMemo<ResourceResolver>(\n () =>\n createResourceResolver({\n store,\n apiClient,\n documentKey,\n locale,\n }),\n [store, apiClient, documentKey, locale],\n )\n}\n"],"mappings":"AAAA,SAAS,eAAe;AAGxB,SAAS,8BAA8B;AAEvC,SAAS,6BAA6B;AACtC,SAAS,gBAAgB,yBAAyB;AAClD,SAAS,gBAAgB;AAElB,SAAS,sBAAwC;AACtD,QAAM,QAAQ,SAAS;AACvB,QAAM,YAAY,sBAAsB;AAExC,QAAM,cAAc,eAAe;AACnC,QAAM,SAAS,kBAAkB;AAEjC,SAAO;AAAA,IACL,MACE,uBAAuB;AAAA,MACrB;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF,CAAC;AAAA,IACH,CAAC,OAAO,WAAW,aAAa,MAAM;AAAA,EACxC;AACF;","names":[]}
|
|
@@ -47,16 +47,12 @@ class RuntimeCore {
|
|
|
47
47
|
getOrCreateStore({ siteVersion, locale }) {
|
|
48
48
|
const key = storeCacheKey({ siteVersion, locale });
|
|
49
49
|
const createStore = () => {
|
|
50
|
-
const
|
|
51
|
-
uri: new URL("graphql", this.apiOrigin).href,
|
|
52
|
-
fetch: this.fetch,
|
|
53
|
-
preloadedState: { siteVersion, locale }
|
|
54
|
-
});
|
|
50
|
+
const apiResourcesClient = this.createApiResourcesClient({ siteVersion, locale });
|
|
55
51
|
const isReadOnly = siteVersion == null;
|
|
56
52
|
return configureReadWriteStore({
|
|
57
53
|
name: `Runtime read-write store (site version: ${key})`,
|
|
58
54
|
appOrigin: this.appOrigin,
|
|
59
|
-
|
|
55
|
+
apiResourcesClient,
|
|
60
56
|
preloadedState: { ...this.protoStore.getState(), siteVersion, isReadOnly, locale }
|
|
61
57
|
});
|
|
62
58
|
};
|
|
@@ -89,6 +85,15 @@ class RuntimeCore {
|
|
|
89
85
|
getBreakpoints() {
|
|
90
86
|
return getBreakpoints(this.protoStore.getState());
|
|
91
87
|
}
|
|
88
|
+
get graphqlApiEndpoint() {
|
|
89
|
+
return new URL("graphql", this.apiOrigin).href;
|
|
90
|
+
}
|
|
91
|
+
createApiResourcesClient(preloadedState) {
|
|
92
|
+
return new MakeswiftHostApiClient({
|
|
93
|
+
fetch: this.fetch,
|
|
94
|
+
preloadedState
|
|
95
|
+
});
|
|
96
|
+
}
|
|
92
97
|
shouldUsePersistentStore(key) {
|
|
93
98
|
return !isServer() || this.requestKey !== void 0 && storeCacheKey(this.requestKey) === key;
|
|
94
99
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/runtimes/react/runtime-core.ts"],"sourcesContent":["import { type SerializableReplacementContext } from '@makeswift/controls'\n\nimport { MakeswiftHostApiClient } from '../../api/client'\nimport { type HttpFetch } from '../../state/api-client/fetch-api-resource'\nimport { type SiteVersion } from '../../api/site-version'\n\nimport {\n Breakpoints,\n BreakpointsInput,\n parseBreakpointsInput,\n} from '../../state/modules/breakpoints'\n\nimport { copyElementTree } from '../../state/ops/copy-element-tree'\n\nimport { getBreakpoints, type Element, type ElementData } from '../../state/read-only-state'\nimport {\n configureProtoStore,\n configureReadWriteStore,\n type ProtoStore,\n type Store,\n} from '../../state/store'\n\nimport { RefCountedMap } from '../../utils/ref-counted-map'\nimport { isServer } from '../../utils/is-server'\n\nexport type StoreKey = {\n siteVersion: SiteVersion | null\n locale: string | undefined\n}\n\nconst VERSION_TAG_LIVE = 'ref:live'\n\nexport class RuntimeCore {\n // The unowned entry TTL affects performance, not correctness. The TTL controls how long an unretained store stays\n // in the map. If an entry expires and is removed from the map before React commits, the store remains retained\n // via `<StoreContext.Provider>`. The only impact is that future lookups will create a new store instance instead of\n // reusing the existing one, reducing cache efficiency.\n private readonly activeStores = new RefCountedMap<string | null, Store>({\n unownedEntryTtlMs: 1000,\n // Checking on retain/release is sufficient on the client, and we don't need to check on get on the server\n // as the only scenario in which we add the store to the map is when the runtime is already bound to the\n // requested site version, which should be the only site version for which the store is requested\n ttlCheck: RefCountedMap.TTLCheck.ON_RETAIN | RefCountedMap.TTLCheck.ON_RELEASE,\n })\n\n readonly protoStore: ProtoStore\n readonly appOrigin: string\n readonly apiOrigin: string\n readonly requestKey: StoreKey | undefined\n readonly fetch: HttpFetch\n\n constructor({\n appOrigin = 'https://app.makeswift.com',\n apiOrigin = 'https://api.makeswift.com',\n breakpoints,\n requestKey,\n fetch,\n }: {\n appOrigin?: string\n apiOrigin?: string\n breakpoints?: BreakpointsInput\n requestKey?: StoreKey\n fetch: HttpFetch\n }) {\n this.appOrigin = validateOrigin(appOrigin, 'appOrigin')\n this.apiOrigin = validateOrigin(apiOrigin, 'apiOrigin')\n this.requestKey = requestKey\n this.fetch = fetch\n\n this.protoStore = configureProtoStore({\n name: 'Runtime proto-store',\n breakpoints: breakpoints ? parseBreakpointsInput(breakpoints) : undefined,\n })\n }\n\n getOrCreateStore({ siteVersion, locale }: StoreKey): Store {\n const key = storeCacheKey({ siteVersion, locale })\n\n const createStore = () => {\n //
|
|
1
|
+
{"version":3,"sources":["../../../../src/runtimes/react/runtime-core.ts"],"sourcesContent":["import { type SerializableReplacementContext } from '@makeswift/controls'\n\nimport { MakeswiftHostApiClient } from '../../api/client'\nimport { type HttpFetch } from '../../state/api-client/fetch-api-resource'\nimport { type SiteVersion } from '../../api/site-version'\n\nimport {\n Breakpoints,\n BreakpointsInput,\n parseBreakpointsInput,\n} from '../../state/modules/breakpoints'\n\nimport { copyElementTree } from '../../state/ops/copy-element-tree'\n\nimport { getBreakpoints, type Element, type ElementData } from '../../state/read-only-state'\nimport {\n configureProtoStore,\n configureReadWriteStore,\n type ProtoStore,\n type Store,\n} from '../../state/store'\n\nimport { RefCountedMap } from '../../utils/ref-counted-map'\nimport { isServer } from '../../utils/is-server'\n\nexport type StoreKey = {\n siteVersion: SiteVersion | null\n locale: string | undefined\n}\n\nconst VERSION_TAG_LIVE = 'ref:live'\n\nexport class RuntimeCore {\n // The unowned entry TTL affects performance, not correctness. The TTL controls how long an unretained store stays\n // in the map. If an entry expires and is removed from the map before React commits, the store remains retained\n // via `<StoreContext.Provider>`. The only impact is that future lookups will create a new store instance instead of\n // reusing the existing one, reducing cache efficiency.\n private readonly activeStores = new RefCountedMap<string | null, Store>({\n unownedEntryTtlMs: 1000,\n // Checking on retain/release is sufficient on the client, and we don't need to check on get on the server\n // as the only scenario in which we add the store to the map is when the runtime is already bound to the\n // requested site version, which should be the only site version for which the store is requested\n ttlCheck: RefCountedMap.TTLCheck.ON_RETAIN | RefCountedMap.TTLCheck.ON_RELEASE,\n })\n\n readonly protoStore: ProtoStore\n readonly appOrigin: string\n readonly apiOrigin: string\n readonly requestKey: StoreKey | undefined\n readonly fetch: HttpFetch\n\n constructor({\n appOrigin = 'https://app.makeswift.com',\n apiOrigin = 'https://api.makeswift.com',\n breakpoints,\n requestKey,\n fetch,\n }: {\n appOrigin?: string\n apiOrigin?: string\n breakpoints?: BreakpointsInput\n requestKey?: StoreKey\n fetch: HttpFetch\n }) {\n this.appOrigin = validateOrigin(appOrigin, 'appOrigin')\n this.apiOrigin = validateOrigin(apiOrigin, 'apiOrigin')\n this.requestKey = requestKey\n this.fetch = fetch\n\n this.protoStore = configureProtoStore({\n name: 'Runtime proto-store',\n breakpoints: breakpoints ? parseBreakpointsInput(breakpoints) : undefined,\n })\n }\n\n getOrCreateStore({ siteVersion, locale }: StoreKey): Store {\n const key = storeCacheKey({ siteVersion, locale })\n\n const createStore = () => {\n // API resources client includes an in-memory cache of the site's resources and thus also has to be versioned\n const apiResourcesClient = this.createApiResourcesClient({ siteVersion, locale })\n\n // TODO: we need to decouple editability from the site version; specifically, previewing\n // a draft version of the site should not lead to switching to the read-write state\n const isReadOnly = siteVersion == null\n\n return configureReadWriteStore({\n name: `Runtime read-write store (site version: ${key})`,\n appOrigin: this.appOrigin,\n apiResourcesClient,\n preloadedState: { ...this.protoStore.getState(), siteVersion, isReadOnly, locale },\n })\n }\n\n // On the server, stores are ephemeral by default so SSR does not retain them in a long-lived runtime.\n // The exception is a runtime that is already bound to the requested site version & locale, where we\n // can safely reuse the store across multiple root regions and benefit from the host API client's\n // in-memory cache.\n //\n // On the client, stores are reference-counted by site version so multiple root regions can share a store\n // instance, which preserves the pre-v0.17 per-site-version store behavior without requiring a separate\n // runtime per root.\n const usePersistentStore = this.shouldUsePersistentStore(key)\n return usePersistentStore ? this.activeStores.getOrCreate(key, createStore) : createStore()\n }\n\n retainStore({ siteVersion, locale }: StoreKey, store: Store): void {\n const key = storeCacheKey({ siteVersion, locale })\n\n if (!this.shouldUsePersistentStore(key)) {\n console.error('RuntimeCore: attempt to retain an ephemeral store', { key })\n return\n }\n\n if (this.activeStores.retain(key, store)) {\n store.startBreakpointWatch()\n }\n }\n\n releaseStore({ siteVersion, locale }: StoreKey, store: Store): void {\n const key = storeCacheKey({ siteVersion, locale })\n\n if (!this.shouldUsePersistentStore(key)) {\n console.error('RuntimeCore: attempt to release an ephemeral store', { key })\n return\n }\n\n if (this.activeStores.release(key, store)) {\n store.stopBreakpointWatch()\n }\n }\n\n copyElementTree(\n elementTree: ElementData,\n replacementContext: SerializableReplacementContext,\n ): Element {\n return copyElementTree(this.protoStore.getState(), elementTree, replacementContext)\n }\n\n getBreakpoints(): Breakpoints {\n return getBreakpoints(this.protoStore.getState())\n }\n\n get graphqlApiEndpoint(): string {\n return new URL('graphql', this.apiOrigin).href\n }\n\n private createApiResourcesClient(preloadedState: {\n siteVersion: SiteVersion | null\n locale: string | undefined\n }) {\n return new MakeswiftHostApiClient({\n fetch: this.fetch,\n preloadedState,\n })\n }\n\n private shouldUsePersistentStore(key: string): boolean {\n // don't persist stores on the server unless the runtime instance is bound to a request\n // and the requested store matches the request's site version and locale\n return !isServer() || (this.requestKey !== undefined && storeCacheKey(this.requestKey) === key)\n }\n}\n\nconst storeCacheKey = ({ siteVersion, locale }: StoreKey): string =>\n `${siteVersionTag(siteVersion)}/${locale ?? 'default'}`\n\nconst siteVersionTag = (siteVersion: SiteVersion | null): string =>\n siteVersion?.version ?? VERSION_TAG_LIVE\n\nfunction validateOrigin(url: string, name: string): string {\n try {\n return new URL(url).origin\n } catch {\n throw new Error(`The Makeswift runtime received an invalid \\`${name}\\` parameter: \"${url}\".`)\n }\n}\n"],"mappings":"AAEA,SAAS,8BAA8B;AAIvC;AAAA,EAGE;AAAA,OAC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AAW;AAE1B,SAAS,eAAe,KAAa,MAAsB;AACzD,MAAI;AACF,WAAO,IAAI,IAAI,GAAG,EAAE;AAAA,EACtB,QAAQ;AACN,UAAM,IAAI,MAAM,+CAA+C,IAAI,kBAAkB,GAAG,IAAI;AAAA,EAC9F;AACF;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/state/middleware/makeswift-api-client-sync.ts"],"sourcesContent":["import { type Middleware } from '@reduxjs/toolkit'\n\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../../src/state/middleware/makeswift-api-client-sync.ts"],"sourcesContent":["import { type Middleware } from '@reduxjs/toolkit'\n\nimport { ApiResourcesClient } from '../../api/api-resources-client'\n\nimport { type Action } from '../actions'\nimport { actionMiddleware } from '../toolkit'\nimport { type State, type Dispatch } from '../unified-state'\n\nexport function makeswiftApiClientSyncMiddleware(\n client: ApiResourcesClient,\n): Middleware<Dispatch, State, Dispatch> {\n return actionMiddleware(() => next => {\n return (action: Action) => {\n client.store.dispatch(action)\n\n return next(action)\n }\n })\n}\n"],"mappings":"AAKA,SAAS,wBAAwB;AAG1B,SAAS,iCACd,QACuC;AACvC,SAAO,iBAAiB,MAAM,UAAQ;AACpC,WAAO,CAAC,WAAmB;AACzB,aAAO,MAAM,SAAS,MAAM;AAE5B,aAAO,KAAK,MAAM;AAAA,IACpB;AAAA,EACF,CAAC;AACH;","names":[]}
|
package/dist/esm/state/store.js
CHANGED
|
@@ -94,7 +94,7 @@ function withMixin(mixin) {
|
|
|
94
94
|
function configureReadWriteStore({
|
|
95
95
|
name,
|
|
96
96
|
appOrigin,
|
|
97
|
-
|
|
97
|
+
apiResourcesClient,
|
|
98
98
|
preloadedState
|
|
99
99
|
}) {
|
|
100
100
|
const readWriteMiddlewareRef = {
|
|
@@ -138,7 +138,7 @@ function configureReadWriteStore({
|
|
|
138
138
|
name,
|
|
139
139
|
preloadedState,
|
|
140
140
|
middleware: () => [
|
|
141
|
-
makeswiftApiClientSyncMiddleware(
|
|
141
|
+
makeswiftApiClientSyncMiddleware(apiResourcesClient),
|
|
142
142
|
conditionalReadWriteMiddleware(readWriteMiddlewareRef)
|
|
143
143
|
],
|
|
144
144
|
enhancers: () => new Tuple(
|
|
@@ -150,7 +150,7 @@ function configureReadWriteStore({
|
|
|
150
150
|
})
|
|
151
151
|
),
|
|
152
152
|
withMixin({
|
|
153
|
-
|
|
153
|
+
apiResourcesClient,
|
|
154
154
|
loadReadWriteStateIfNeeded: async () => {
|
|
155
155
|
const { isReadOnly } = store.getState();
|
|
156
156
|
if (isReadOnly) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/state/store.ts"],"sourcesContent":["import {\n type Middleware,\n type StoreEnhancer,\n type MiddlewareAPI,\n Tuple,\n configureStore as configureReduxStore,\n combineReducers,\n compose,\n} from '@reduxjs/toolkit'\n\nimport { MakeswiftHostApiClient } from '../api/client'\n\nimport { actionMiddleware, middlewareOptions, devToolsConfig } from './toolkit'\nimport { BuilderActionTypes } from './builder-api/actions'\nimport { HostActionTypes } from './host-api'\n\nimport * as Breakpoints from './modules/breakpoints'\n\nimport { readOnlyElementTreeMiddleware } from './middleware/read-only-element-tree'\nimport { makeswiftApiClientSyncMiddleware } from './middleware/makeswift-api-client-sync'\nimport { type BreakpointWatch, breakpointWatchMixin } from './mixins/breakpoint-watch'\n\nimport { type Action } from './actions'\n\nimport { type State as ReadWriteState } from './read-write-state'\nimport * as ReadOnlyState from './read-only-state'\nimport {\n type State,\n type Dispatch,\n type ReadOnlyReducer,\n type ReadWriteDispatch,\n} from './unified-state'\n\nexport { type State } from './unified-state'\n\nconst configureStore = <Items extends readonly StoreEnhancer[] = []>({\n name,\n preloadedState,\n enhancers,\n middleware,\n}: {\n name: string\n preloadedState: Partial<State>\n enhancers: () => Tuple<Items>\n middleware?: () => Middleware[]\n}) => {\n const store = configureReduxStore({\n reducer: combineReducers(ReadOnlyState.reducers),\n preloadedState,\n\n middleware: getDefaultMiddleware =>\n getDefaultMiddleware(middlewareOptions).concat([\n readOnlyElementTreeMiddleware(),\n ...(middleware ? middleware() : []),\n ]),\n\n enhancers: getDefaultEnhancers => getDefaultEnhancers().concat(enhancers()),\n\n devTools: devToolsConfig({\n name: `${name} (${new Date().toISOString()})`,\n actionsDenylist: [\n HostActionTypes.BUILDER_POINTER_MOVE,\n BuilderActionTypes.HANDLE_POINTER_MOVE,\n BuilderActionTypes.ELEMENT_FROM_POINT_CHANGE,\n ],\n }),\n })\n\n return store\n}\n\nexport function configureProtoStore({\n name,\n breakpoints,\n}: {\n name: string\n breakpoints: Breakpoints.Breakpoints | undefined\n}) {\n return configureStore({\n name,\n preloadedState: {\n breakpoints: Breakpoints.getInitialState(breakpoints),\n },\n enhancers: () => new Tuple(),\n })\n}\n\nexport type ProtoStore = ReturnType<typeof configureProtoStore>\n\ntype ReadWriteMiddleware = ReturnType<\n typeof import('./middleware/read-write').createReadWriteMiddleware\n>\n\ntype ReadWriteMiddlewareRef = {\n current: ReadWriteMiddleware | null\n}\n\nexport function conditionalReadWriteMiddleware(\n middlewareRef: ReadWriteMiddlewareRef,\n): Middleware<Dispatch, State, Dispatch> {\n let readWriteActionBuffer: Action[] = []\n let middlewares: ReadWriteMiddleware | null = null\n let enhancedDispatch: Dispatch | null = null\n\n return actionMiddleware(({ dispatch, getState }) => next => {\n return (action: Action) => {\n const state = getState()\n\n if (middlewareRef.current == null) {\n if (!state.isReadOnly) {\n // because switching to the read-write state is an asynchronous operation,\n // we need to buffer all actions dispatched after the isReadOnly state is\n // set to false but before the read-write middleware is installed\n readWriteActionBuffer.push(action)\n }\n\n return next(action)\n }\n\n if (state.isReadOnly) {\n console.error('Read-write state mismatch', {\n isReadOnly: state.isReadOnly,\n middlewareRef: middlewareRef.current,\n siteVersion: state.siteVersion,\n })\n }\n\n // build and cache the enhanced dispatch chain when read-write middleware is installed\n if (enhancedDispatch == null || middlewares !== middlewareRef.current) {\n middlewares = middlewareRef.current\n\n const middlewareApi = { dispatch, getState } as MiddlewareAPI<\n ReadWriteDispatch,\n ReadWriteState\n >\n\n enhancedDispatch = compose<Dispatch>(...middlewares.map(mw => mw(middlewareApi)))(next)\n }\n\n // dispatch buffered actions, if any\n if (readWriteActionBuffer.length > 0) {\n const readWriteActions = [...readWriteActionBuffer]\n readWriteActionBuffer = []\n\n // Note that we're rerunning the actions through the entire middleware chain,\n // including the read-only middleware and the reducers, some of which have\n // already processed these actions once. This is safe to do because actions that\n // are run as part of page initialization are idempotent.\n for (const bufferedAction of readWriteActions) {\n enhancedDispatch(bufferedAction)\n }\n }\n\n return enhancedDispatch(action)\n }\n })\n}\n\nexport interface ReadWriteStateMixin {\n readonly hostApiClient: MakeswiftHostApiClient\n\n loadReadWriteStateIfNeeded(): Promise<() => void>\n}\n\nfunction withMixin<M extends {}>(mixin: M): StoreEnhancer<M> {\n return next => (reducer, preloadedState?) => ({\n ...next(reducer, preloadedState),\n ...mixin,\n })\n}\n\nexport function configureReadWriteStore({\n name,\n appOrigin,\n hostApiClient,\n preloadedState,\n}: {\n name: string\n appOrigin: string\n hostApiClient: MakeswiftHostApiClient\n preloadedState: Partial<State>\n}) {\n const readWriteMiddlewareRef: ReadWriteMiddlewareRef = {\n current: null,\n }\n\n let refCount = 0\n let readWriteCleanup: (() => void) | null = null\n let readWriteSetupPromise: Promise<void> | null = null\n\n const loadReadWriteState = async (): Promise<void> => {\n if (readWriteCleanup != null) {\n return\n }\n\n if (readWriteSetupPromise != null) {\n await readWriteSetupPromise\n return\n }\n\n readWriteSetupPromise = (async () => {\n // import all the modules needed for read-write mode before proceeding with\n // the setup to avoid race conditions when `setup` is called concurrently\n // in two different page regions\n const { BuilderAPIProxy } = await import('./builder-api/proxy')\n const { createRootReducer, setupBuilderProxy } = await import('./read-write-state')\n const { createReadWriteMiddleware } = await import('./middleware/read-write')\n\n // IMPORTANT: only synchronous code after this point\n\n // with all modules imported, check if another concurrent setup already\n // initialized the read-write middleware\n if (readWriteMiddlewareRef.current != null) {\n return\n }\n\n store.replaceReducer(createRootReducer() as ReadOnlyReducer)\n\n const builderProxy = new BuilderAPIProxy({ appOrigin })\n readWriteMiddlewareRef.current = createReadWriteMiddleware({ builderProxy })\n\n const dispatch = store.dispatch as ReadWriteDispatch\n const builderProxyCleanup = dispatch(setupBuilderProxy(builderProxy))\n\n readWriteCleanup = () => {\n readWriteMiddlewareRef.current = null\n builderProxyCleanup()\n }\n })()\n\n try {\n await readWriteSetupPromise\n } finally {\n readWriteSetupPromise = null\n }\n }\n\n const store = configureStore({\n name,\n preloadedState,\n\n middleware: () => [\n makeswiftApiClientSyncMiddleware(hostApiClient),\n conditionalReadWriteMiddleware(readWriteMiddlewareRef),\n ],\n\n enhancers: () =>\n new Tuple(\n withMixin<BreakpointWatch>(\n breakpointWatchMixin({\n dispatch: (...args: Parameters<Dispatch>) => store.dispatch(...args),\n getState: (): State => store.getState(),\n subscribe: (listener): VoidFunction => store.subscribe(listener),\n }),\n ),\n\n withMixin<ReadWriteStateMixin>({\n hostApiClient,\n loadReadWriteStateIfNeeded: async () => {\n const { isReadOnly } = store.getState()\n\n if (isReadOnly) {\n if (refCount > 0) {\n console.error('Read-write state mismatch', { isReadOnly, refCount })\n }\n\n return () => {}\n }\n\n await loadReadWriteState()\n refCount += 1\n\n let didCleanup = false\n return () => {\n if (didCleanup) {\n return\n }\n\n didCleanup = true\n refCount -= 1\n if (refCount === 0 && readWriteCleanup != null) {\n readWriteCleanup()\n readWriteCleanup = null\n }\n }\n },\n }),\n ),\n })\n\n return store\n}\n\nexport type Store = ReturnType<typeof configureReadWriteStore>\n"],"mappings":"AAAA;AAAA,EAIE;AAAA,EACA,kBAAkB;AAAA,EAClB;AAAA,EACA;AAAA,OACK;AAIP,SAAS,kBAAkB,mBAAmB,sBAAsB;AACpE,SAAS,0BAA0B;AACnC,SAAS,uBAAuB;AAEhC,YAAY,iBAAiB;AAE7B,SAAS,qCAAqC;AAC9C,SAAS,wCAAwC;AACjD,SAA+B,4BAA4B;AAK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AA,EACJ,CAAC;AAED,SAAO;AACT;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../src/state/store.ts"],"sourcesContent":["import {\n type Middleware,\n type StoreEnhancer,\n type MiddlewareAPI,\n Tuple,\n configureStore as configureReduxStore,\n combineReducers,\n compose,\n} from '@reduxjs/toolkit'\n\nimport { ApiResourcesClient } from '../api/api-resources-client'\n\nimport { actionMiddleware, middlewareOptions, devToolsConfig } from './toolkit'\nimport { BuilderActionTypes } from './builder-api/actions'\nimport { HostActionTypes } from './host-api'\n\nimport * as Breakpoints from './modules/breakpoints'\n\nimport { readOnlyElementTreeMiddleware } from './middleware/read-only-element-tree'\nimport { makeswiftApiClientSyncMiddleware } from './middleware/makeswift-api-client-sync'\nimport { type BreakpointWatch, breakpointWatchMixin } from './mixins/breakpoint-watch'\n\nimport { type Action } from './actions'\n\nimport { type State as ReadWriteState } from './read-write-state'\nimport * as ReadOnlyState from './read-only-state'\nimport {\n type State,\n type Dispatch,\n type ReadOnlyReducer,\n type ReadWriteDispatch,\n} from './unified-state'\n\nexport { type State } from './unified-state'\n\nconst configureStore = <Items extends readonly StoreEnhancer[] = []>({\n name,\n preloadedState,\n enhancers,\n middleware,\n}: {\n name: string\n preloadedState: Partial<State>\n enhancers: () => Tuple<Items>\n middleware?: () => Middleware[]\n}) => {\n const store = configureReduxStore({\n reducer: combineReducers(ReadOnlyState.reducers),\n preloadedState,\n\n middleware: getDefaultMiddleware =>\n getDefaultMiddleware(middlewareOptions).concat([\n readOnlyElementTreeMiddleware(),\n ...(middleware ? middleware() : []),\n ]),\n\n enhancers: getDefaultEnhancers => getDefaultEnhancers().concat(enhancers()),\n\n devTools: devToolsConfig({\n name: `${name} (${new Date().toISOString()})`,\n actionsDenylist: [\n HostActionTypes.BUILDER_POINTER_MOVE,\n BuilderActionTypes.HANDLE_POINTER_MOVE,\n BuilderActionTypes.ELEMENT_FROM_POINT_CHANGE,\n ],\n }),\n })\n\n return store\n}\n\nexport function configureProtoStore({\n name,\n breakpoints,\n}: {\n name: string\n breakpoints: Breakpoints.Breakpoints | undefined\n}) {\n return configureStore({\n name,\n preloadedState: {\n breakpoints: Breakpoints.getInitialState(breakpoints),\n },\n enhancers: () => new Tuple(),\n })\n}\n\nexport type ProtoStore = ReturnType<typeof configureProtoStore>\n\ntype ReadWriteMiddleware = ReturnType<\n typeof import('./middleware/read-write').createReadWriteMiddleware\n>\n\ntype ReadWriteMiddlewareRef = {\n current: ReadWriteMiddleware | null\n}\n\nexport function conditionalReadWriteMiddleware(\n middlewareRef: ReadWriteMiddlewareRef,\n): Middleware<Dispatch, State, Dispatch> {\n let readWriteActionBuffer: Action[] = []\n let middlewares: ReadWriteMiddleware | null = null\n let enhancedDispatch: Dispatch | null = null\n\n return actionMiddleware(({ dispatch, getState }) => next => {\n return (action: Action) => {\n const state = getState()\n\n if (middlewareRef.current == null) {\n if (!state.isReadOnly) {\n // because switching to the read-write state is an asynchronous operation,\n // we need to buffer all actions dispatched after the isReadOnly state is\n // set to false but before the read-write middleware is installed\n readWriteActionBuffer.push(action)\n }\n\n return next(action)\n }\n\n if (state.isReadOnly) {\n console.error('Read-write state mismatch', {\n isReadOnly: state.isReadOnly,\n middlewareRef: middlewareRef.current,\n siteVersion: state.siteVersion,\n })\n }\n\n // build and cache the enhanced dispatch chain when read-write middleware is installed\n if (enhancedDispatch == null || middlewares !== middlewareRef.current) {\n middlewares = middlewareRef.current\n\n const middlewareApi = { dispatch, getState } as MiddlewareAPI<\n ReadWriteDispatch,\n ReadWriteState\n >\n\n enhancedDispatch = compose<Dispatch>(...middlewares.map(mw => mw(middlewareApi)))(next)\n }\n\n // dispatch buffered actions, if any\n if (readWriteActionBuffer.length > 0) {\n const readWriteActions = [...readWriteActionBuffer]\n readWriteActionBuffer = []\n\n // Note that we're rerunning the actions through the entire middleware chain,\n // including the read-only middleware and the reducers, some of which have\n // already processed these actions once. This is safe to do because actions that\n // are run as part of page initialization are idempotent.\n for (const bufferedAction of readWriteActions) {\n enhancedDispatch(bufferedAction)\n }\n }\n\n return enhancedDispatch(action)\n }\n })\n}\n\nexport interface ReadWriteStateMixin {\n readonly apiResourcesClient: ApiResourcesClient\n\n loadReadWriteStateIfNeeded(): Promise<() => void>\n}\n\nfunction withMixin<M extends {}>(mixin: M): StoreEnhancer<M> {\n return next => (reducer, preloadedState?) => ({\n ...next(reducer, preloadedState),\n ...mixin,\n })\n}\n\nexport function configureReadWriteStore({\n name,\n appOrigin,\n apiResourcesClient,\n preloadedState,\n}: {\n name: string\n appOrigin: string\n apiResourcesClient: ApiResourcesClient\n preloadedState: Partial<State>\n}) {\n const readWriteMiddlewareRef: ReadWriteMiddlewareRef = {\n current: null,\n }\n\n let refCount = 0\n let readWriteCleanup: (() => void) | null = null\n let readWriteSetupPromise: Promise<void> | null = null\n\n const loadReadWriteState = async (): Promise<void> => {\n if (readWriteCleanup != null) {\n return\n }\n\n if (readWriteSetupPromise != null) {\n await readWriteSetupPromise\n return\n }\n\n readWriteSetupPromise = (async () => {\n // import all the modules needed for read-write mode before proceeding with\n // the setup to avoid race conditions when `setup` is called concurrently\n // in two different page regions\n const { BuilderAPIProxy } = await import('./builder-api/proxy')\n const { createRootReducer, setupBuilderProxy } = await import('./read-write-state')\n const { createReadWriteMiddleware } = await import('./middleware/read-write')\n\n // IMPORTANT: only synchronous code after this point\n\n // with all modules imported, check if another concurrent setup already\n // initialized the read-write middleware\n if (readWriteMiddlewareRef.current != null) {\n return\n }\n\n store.replaceReducer(createRootReducer() as ReadOnlyReducer)\n\n const builderProxy = new BuilderAPIProxy({ appOrigin })\n readWriteMiddlewareRef.current = createReadWriteMiddleware({ builderProxy })\n\n const dispatch = store.dispatch as ReadWriteDispatch\n const builderProxyCleanup = dispatch(setupBuilderProxy(builderProxy))\n\n readWriteCleanup = () => {\n readWriteMiddlewareRef.current = null\n builderProxyCleanup()\n }\n })()\n\n try {\n await readWriteSetupPromise\n } finally {\n readWriteSetupPromise = null\n }\n }\n\n const store = configureStore({\n name,\n preloadedState,\n\n middleware: () => [\n makeswiftApiClientSyncMiddleware(apiResourcesClient),\n conditionalReadWriteMiddleware(readWriteMiddlewareRef),\n ],\n\n enhancers: () =>\n new Tuple(\n withMixin<BreakpointWatch>(\n breakpointWatchMixin({\n dispatch: (...args: Parameters<Dispatch>) => store.dispatch(...args),\n getState: (): State => store.getState(),\n subscribe: (listener): VoidFunction => store.subscribe(listener),\n }),\n ),\n\n withMixin<ReadWriteStateMixin>({\n apiResourcesClient,\n loadReadWriteStateIfNeeded: async () => {\n const { isReadOnly } = store.getState()\n\n if (isReadOnly) {\n if (refCount > 0) {\n console.error('Read-write state mismatch', { isReadOnly, refCount })\n }\n\n return () => {}\n }\n\n await loadReadWriteState()\n refCount += 1\n\n let didCleanup = false\n return () => {\n if (didCleanup) {\n return\n }\n\n didCleanup = true\n refCount -= 1\n if (refCount === 0 && readWriteCleanup != null) {\n readWriteCleanup()\n readWriteCleanup = null\n }\n }\n },\n }),\n ),\n })\n\n return store\n}\n\nexport type Store = ReturnType<typeof configureReadWriteStore>\n"],"mappings":"AAAA;AAAA,EAIE;AAAA,EACA,kBAAkB;AAAA,EAClB;AAAA,EACA;AAAA,OACK;AAIP,SAAS,kBAAkB,mBAAmB,sBAAsB;AACpE,SAAS,0BAA0B;AACnC,SAAS,uBAAuB;AAEhC,YAAY,iBAAiB;AAE7B,SAAS,qCAAqC;AAC9C,SAAS,wCAAwC;AACjD,SAA+B,4BAA4B;AAK3D,YAAY,mBAAmB;AAU/B,MAAM,iBAAiB,CAA8C;AAAA,EACnE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MAKM;AACJ,QAAM,QAAQ,oBAAoB;AAAA,IAChC,SAAS,gBAAgB,cAAc,QAAQ;AAAA,IAC/C;AAAA,IAEA,YAAY,0BACV,qBAAqB,iBAAiB,EAAE,OAAO;AAAA,MAC7C,8BAA8B;AAAA,MAC9B,GAAI,aAAa,WAAW,IAAI,CAAC;AAAA,IACnC,CAAC;AAAA,IAEH,WAAW,yBAA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AAEA,QAAM,QAAQ,eAAe;AAAA,IAC3B;AAAA,IACA;AAAA,IAEA,YAAY,MAAM;AAAA,MAChB,iCAAiC,kBAAkB;AAAA,MACnD,+BAA+B,sBAAsB;AAAA,IACvD;AAAA,IAEA,WAAW,MACT,IAAI;AAAA,MACF;AAAA,QACE,qBAAqB;AAAA,UACnB,UAAU,IAAI,SAA+B,MAAM,SAAS,GAAG,IAAI;AAAA,UACnE,UAAU,MAAa,MAAM,SAAS;AAAA,UACtC,WAAW,CAAC,aAA2B,MAAM,UAAU,QAAQ;AAAA,QACjE,CAAC;AAAA,MACH;AAAA,MAEA,UAA+B;AAAA,QAC7B;AAAA,QACA,4BAA4B,YAAY;AACtC,gBAAM,EAAE,WAAW,IAAI,MAAM,SAAS;AAEtC,cAAI,YAAY;AACd,gBAAI,WAAW,GAAG;AAChB,sBAAQ,MAAM,6BAA6B,EAAE,YAAY,SAAS,CAAC;AAAA,YACrE;AAEA,mBAAO,MAAM;AAAA,YAAC;AAAA,UAChB;AAEA,gBAAM,mBAAmB;AACzB,sBAAY;AAEZ,cAAI,aAAa;AACjB,iBAAO,MAAM;AACX,gBAAI,YAAY;AACd;AAAA,YACF;AAEA,yBAAa;AACb,wBAAY;AACZ,gBAAI,aAAa,KAAK,oBAAoB,MAAM;AAC9C,+BAAiB;AACjB,iCAAmB;AAAA,YACrB;AAAA,UACF;AAAA,QACF;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACJ,CAAC;AAED,SAAO;AACT;","names":[]}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { type State as ApiClientState } from '../state/api-client/state';
|
|
2
2
|
import { type HttpFetch } from '../state/api-client/fetch-api-resource';
|
|
3
3
|
import { type File, type GlobalElement, type LocalizedGlobalElement, type PagePathnameSlice, type Swatch, type Table, type Typography } from './types';
|
|
4
|
-
import { GraphQLClient } from './graphql/client';
|
|
5
4
|
import { ApiResourcesClient } from './api-resources-client';
|
|
6
5
|
export { CacheData } from './api-resources-client';
|
|
7
6
|
/**
|
|
@@ -24,10 +23,8 @@ export { CacheData } from './api-resources-client';
|
|
|
24
23
|
* snapshot for use in the builder, not the lives pages.
|
|
25
24
|
*/
|
|
26
25
|
export declare class MakeswiftHostApiClient extends ApiResourcesClient {
|
|
27
|
-
readonly graphqlClient: GraphQLClient;
|
|
28
26
|
readonly fetch: HttpFetch;
|
|
29
|
-
constructor({
|
|
30
|
-
uri: string;
|
|
27
|
+
constructor({ fetch, preloadedState, }: {
|
|
31
28
|
fetch: HttpFetch;
|
|
32
29
|
preloadedState: Partial<ApiClientState>;
|
|
33
30
|
});
|
|
@@ -44,6 +41,5 @@ export declare class MakeswiftHostApiClient extends ApiResourcesClient {
|
|
|
44
41
|
locale: string | null;
|
|
45
42
|
}): Promise<PagePathnameSlice | null>;
|
|
46
43
|
fetchTable(tableId: string): Promise<Table | null>;
|
|
47
|
-
createTableRecord(tableId: string, columns: any): Promise<void>;
|
|
48
44
|
}
|
|
49
45
|
//# sourceMappingURL=client.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/api/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,KAAK,IAAI,cAAc,EAAE,MAAM,2BAA2B,CAAA;AACxE,OAAO,EAAE,KAAK,SAAS,EAAoB,MAAM,wCAAwC,CAAA;AAGzF,OAAO,EACL,KAAK,IAAI,EACT,KAAK,aAAa,EAClB,KAAK,sBAAsB,EAC3B,KAAK,iBAAiB,EACtB,KAAK,MAAM,EACX,KAAK,KAAK,EACV,KAAK,UAAU,EAEhB,MAAM,SAAS,CAAA;AAEhB,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/api/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,KAAK,IAAI,cAAc,EAAE,MAAM,2BAA2B,CAAA;AACxE,OAAO,EAAE,KAAK,SAAS,EAAoB,MAAM,wCAA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C,KAAK,GAAG,IAAI,CAAC;CAGzD"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { GraphQLClient } from './graphql/client';
|
|
2
|
+
export declare class MakeswiftGraphQLApiClient {
|
|
3
|
+
readonly graphqlClient: GraphQLClient;
|
|
4
|
+
constructor({ endpoint }: {
|
|
5
|
+
endpoint: string;
|
|
6
|
+
});
|
|
7
|
+
createTableRecord(tableId: string, columns: any): Promise<void>;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=graphql-api-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graphql-api-client.d.ts","sourceRoot":"","sources":["../../../src/api/graphql-api-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAOhD,qBAAa,yBAAyB;IACpC,QAAQ,CAAC,aAAa,EAAE,aAAa,CAAA;gBAEzB,EAAE,QAAQ,EAAE,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAA;KAAE;IAIxC,iBAAiB,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC;CAMtE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GoogleFontLink.d.ts","sourceRoot":"","sources":["../../../../../src/runtimes/react/components/GoogleFontLink.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,IAAI,EAAE,MAAM,iBAAiB,CAAA;AAY3C,KAAK,KAAK,GAAG;IACX,KAAK,EAAE,IAAI,EAAE,CAAA;IACb,MAAM,EAAE,MAAM,GAAG,IAAI,CAAA;CACtB,CAAA;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,KAAK,
|
|
1
|
+
{"version":3,"file":"GoogleFontLink.d.ts","sourceRoot":"","sources":["../../../../../src/runtimes/react/components/GoogleFontLink.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,IAAI,EAAE,MAAM,iBAAiB,CAAA;AAY3C,KAAK,KAAK,GAAG;IACX,KAAK,EAAE,IAAI,EAAE,CAAA;IACb,MAAM,EAAE,MAAM,GAAG,IAAI,CAAA;CACtB,CAAA;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,KAAK,kDAkBtD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PageHead.d.ts","sourceRoot":"","sources":["../../../../../../src/runtimes/react/components/page/PageHead.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAiC,SAAS,EAAE,MAAM,OAAO,CAAA;AAEhE,OAAO,EAAE,KAAK,qBAAqB,EAAE,MAAM,oBAAoB,CAAA;
|
|
1
|
+
{"version":3,"file":"PageHead.d.ts","sourceRoot":"","sources":["../../../../../../src/runtimes/react/components/page/PageHead.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAiC,SAAS,EAAE,MAAM,OAAO,CAAA;AAEhE,OAAO,EAAE,KAAK,qBAAqB,EAAE,MAAM,oBAAoB,CAAA;AAS/D,OAAO,EAAE,KAAK,oBAAoB,EAAE,MAAM,qBAAqB,CAAA;AAS/D,KAAK,KAAK,GAAG;IACX,QAAQ,EAAE,qBAAqB,CAAA;IAC/B,QAAQ,CAAC,EAAE,oBAAoB,CAAA;CAChC,CAAA;AAED,wBAAgB,QAAQ,CAAC,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAa,EAAE,EAAE,KAAK,GAAG,SAAS,CAuG5E"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-api-resources-client.d.ts","sourceRoot":"","sources":["../../../../../src/runtimes/react/hooks/use-api-resources-client.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,mCAAmC,CAAA;AAItE,wBAAgB,qBAAqB,IAAI,kBAAkB,CAE1D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-graphql-api-client.d.ts","sourceRoot":"","sources":["../../../../../src/runtimes/react/hooks/use-graphql-api-client.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,yBAAyB,EAAE,MAAM,iCAAiC,CAAA;AAI3E,wBAAgB,4BAA4B,IAAI,yBAAyB,CAGxE"}
|
|
@@ -27,6 +27,8 @@ export declare class RuntimeCore {
|
|
|
27
27
|
releaseStore({ siteVersion, locale }: StoreKey, store: Store): void;
|
|
28
28
|
copyElementTree(elementTree: ElementData, replacementContext: SerializableReplacementContext): Element;
|
|
29
29
|
getBreakpoints(): Breakpoints;
|
|
30
|
+
get graphqlApiEndpoint(): string;
|
|
31
|
+
private createApiResourcesClient;
|
|
30
32
|
private shouldUsePersistentStore;
|
|
31
33
|
}
|
|
32
34
|
//# sourceMappingURL=runtime-core.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime-core.d.ts","sourceRoot":"","sources":["../../../../src/runtimes/react/runtime-core.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,8BAA8B,EAAE,MAAM,qBAAqB,CAAA;AAGzE,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,2CAA2C,CAAA;AAC1E,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,wBAAwB,CAAA;AAEzD,OAAO,EACL,WAAW,EACX,gBAAgB,EAEjB,MAAM,iCAAiC,CAAA;AAIxC,OAAO,EAAkB,KAAK,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,6BAA6B,CAAA;AAC5F,OAAO,EAGL,KAAK,UAAU,EACf,KAAK,KAAK,EACX,MAAM,mBAAmB,CAAA;AAK1B,MAAM,MAAM,QAAQ,GAAG;IACrB,WAAW,EAAE,WAAW,GAAG,IAAI,CAAA;IAC/B,MAAM,EAAE,MAAM,GAAG,SAAS,CAAA;CAC3B,CAAA;AAID,qBAAa,WAAW;IAKtB,OAAO,CAAC,QAAQ,CAAC,YAAY,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AAQ,CAAC,YAAY,CAM3B;IAEF,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAA;IAC/B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAC1B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAC1B,QAAQ,CAAC,UAAU,EAAE,QAAQ,GAAG,SAAS,CAAA;IACzC,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAA;gBAEb,EACV,SAAuC,EACvC,SAAuC,EACvC,WAAW,EACX,UAAU,EACV,KAAK,GACN,EAAE;QACD,SAAS,CAAC,EAAE,MAAM,CAAA;QAClB,SAAS,CAAC,EAAE,MAAM,CAAA;QAClB,WAAW,CAAC,EAAE,gBAAgB,CAAA;QAC9B,UAAU,CAAC,EAAE,QAAQ,CAAA;QACrB,KAAK,EAAE,SAAS,CAAA;KACjB;IAYD,gBAAgB,CAAC,EAAE,WAAW,EAAE,MAAM,EAAE,EAAE,QAAQ,GAAG,KAAK;IA+B1D,WAAW,CAAC,EAAE,WAAW,EAAE,MAAM,EAAE,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,GAAG,IAAI;IAalE,YAAY,CAAC,EAAE,WAAW,EAAE,MAAM,EAAE,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,GAAG,IAAI;IAanE,eAAe,CACb,WAAW,EAAE,WAAW,EACxB,kBAAkB,EAAE,8BAA8B,GACjD,OAAO;IAIV,cAAc,IAAI,WAAW;IAI7B,IAAI,kBAAkB,IAAI,MAAM,CAE/B;IAED,OAAO,CAAC,wBAAwB;IAUhC,OAAO,CAAC,wBAAwB;CAKjC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type Middleware } from '@reduxjs/toolkit';
|
|
2
|
-
import {
|
|
2
|
+
import { ApiResourcesClient } from '../../api/api-resources-client';
|
|
3
3
|
import { type State, type Dispatch } from '../unified-state';
|
|
4
|
-
export declare function makeswiftApiClientSyncMiddleware(client:
|
|
4
|
+
export declare function makeswiftApiClientSyncMiddleware(client: ApiResourcesClient): Middleware<Dispatch, State, Dispatch>;
|
|
5
5
|
//# sourceMappingURL=makeswift-api-client-sync.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"makeswift-api-client-sync.d.ts","sourceRoot":"","sources":["../../../../src/state/middleware/makeswift-api-client-sync.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAElD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"makeswift-api-client-sync.d.ts","sourceRoot":"","sources":["../../../../src/state/middleware/makeswift-api-client-sync.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAElD,OAAO,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAA;AAInE,OAAO,EAAE,KAAK,KAAK,EAAE,KAAK,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAE5D,wBAAgB,gCAAgC,CAC9C,MAAM,EAAE,kBAAkB,GACzB,UAAU,CAAC,QAAQ,EAAE,KAAK,EAAE,QAAQ,CAAC,CAQvC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type Middleware, type StoreEnhancer, Tuple } from '@reduxjs/toolkit';
|
|
2
|
-
import {
|
|
2
|
+
import { ApiResourcesClient } from '../api/api-resources-client';
|
|
3
3
|
import * as Breakpoints from './modules/breakpoints';
|
|
4
4
|
import { type BreakpointWatch } from './mixins/breakpoint-watch';
|
|
5
5
|
import { type Action } from './actions';
|
|
@@ -45,13 +45,13 @@ type ReadWriteMiddlewareRef = {
|
|
|
45
45
|
};
|
|
46
46
|
export declare function conditionalReadWriteMiddleware(middlewareRef: ReadWriteMiddlewareRef): Middleware<Dispatch, State, Dispatch>;
|
|
47
47
|
export interface ReadWriteStateMixin {
|
|
48
|
-
readonly
|
|
48
|
+
readonly apiResourcesClient: ApiResourcesClient;
|
|
49
49
|
loadReadWriteStateIfNeeded(): Promise<() => void>;
|
|
50
50
|
}
|
|
51
|
-
export declare function configureReadWriteStore({ name, appOrigin,
|
|
51
|
+
export declare function configureReadWriteStore({ name, appOrigin, apiResourcesClient, preloadedState, }: {
|
|
52
52
|
name: string;
|
|
53
53
|
appOrigin: string;
|
|
54
|
-
|
|
54
|
+
apiResourcesClient: ApiResourcesClient;
|
|
55
55
|
preloadedState: Partial<State>;
|
|
56
56
|
}): import("@reduxjs/toolkit").EnhancedStore<{
|
|
57
57
|
siteVersion: import("./modules/site-version").State;
|