@makeswift/runtime 0.25.0-canary.12 → 0.25.0-canary.13
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/react.js +10 -14
- package/dist/cjs/api/react.js.map +1 -1
- package/dist/cjs/api-handler/handlers/manifest.js +1 -1
- package/dist/cjs/next/components/framework-provider/index.js +3 -1
- package/dist/cjs/next/components/framework-provider/index.js.map +1 -1
- package/dist/cjs/runtimes/react/components/RuntimeProvider.js +6 -2
- package/dist/cjs/runtimes/react/components/RuntimeProvider.js.map +1 -1
- package/dist/cjs/runtimes/react/components/framework-context.js +14 -3
- package/dist/cjs/runtimes/react/components/framework-context.js.map +1 -1
- package/dist/cjs/runtimes/react/host-api-client.js +7 -2
- package/dist/cjs/runtimes/react/host-api-client.js.map +1 -1
- package/dist/cjs/state/makeswift-api-client.js +25 -36
- package/dist/cjs/state/makeswift-api-client.js.map +1 -1
- package/dist/esm/api/react.js +10 -14
- package/dist/esm/api/react.js.map +1 -1
- package/dist/esm/api-handler/handlers/manifest.js +1 -1
- package/dist/esm/next/components/framework-provider/index.js +7 -2
- package/dist/esm/next/components/framework-provider/index.js.map +1 -1
- package/dist/esm/runtimes/react/components/RuntimeProvider.js +6 -2
- package/dist/esm/runtimes/react/components/RuntimeProvider.js.map +1 -1
- package/dist/esm/runtimes/react/components/framework-context.js +12 -2
- package/dist/esm/runtimes/react/components/framework-context.js.map +1 -1
- package/dist/esm/runtimes/react/host-api-client.js +7 -2
- package/dist/esm/runtimes/react/host-api-client.js.map +1 -1
- package/dist/esm/state/makeswift-api-client.js +25 -36
- package/dist/esm/state/makeswift-api-client.js.map +1 -1
- package/dist/types/api/react.d.ts +3 -4
- package/dist/types/api/react.d.ts.map +1 -1
- package/dist/types/next/components/framework-provider/index.d.ts.map +1 -1
- package/dist/types/runtimes/react/components/RuntimeProvider.d.ts.map +1 -1
- package/dist/types/runtimes/react/components/framework-context.d.ts +4 -0
- package/dist/types/runtimes/react/components/framework-context.d.ts.map +1 -1
- package/dist/types/runtimes/react/host-api-client.d.ts.map +1 -1
- package/dist/types/state/makeswift-api-client.d.ts +2 -2
- package/dist/types/state/makeswift-api-client.d.ts.map +1 -1
- package/package.json +3 -3
package/dist/cjs/api/react.js
CHANGED
|
@@ -45,13 +45,13 @@ const CacheData = {
|
|
|
45
45
|
}
|
|
46
46
|
};
|
|
47
47
|
class MakeswiftHostApiClient {
|
|
48
|
-
siteVersion;
|
|
49
48
|
graphqlClient;
|
|
50
49
|
makeswiftApiClient;
|
|
51
50
|
subscribe;
|
|
51
|
+
fetch;
|
|
52
52
|
constructor({
|
|
53
53
|
uri,
|
|
54
|
-
|
|
54
|
+
fetch,
|
|
55
55
|
cacheData,
|
|
56
56
|
locale
|
|
57
57
|
}) {
|
|
@@ -60,7 +60,7 @@ class MakeswiftHostApiClient {
|
|
|
60
60
|
serializedState: cacheData,
|
|
61
61
|
defaultLocale: locale
|
|
62
62
|
});
|
|
63
|
-
this.
|
|
63
|
+
this.fetch = fetch;
|
|
64
64
|
this.subscribe = this.makeswiftApiClient.subscribe;
|
|
65
65
|
}
|
|
66
66
|
readSwatch(swatchId) {
|
|
@@ -72,7 +72,7 @@ class MakeswiftHostApiClient {
|
|
|
72
72
|
}
|
|
73
73
|
async fetchSwatch(swatchId) {
|
|
74
74
|
return await this.makeswiftApiClient.dispatch(
|
|
75
|
-
MakeswiftApiClient.fetchAPIResource(import_types.APIResourceType.Swatch, swatchId, this.
|
|
75
|
+
MakeswiftApiClient.fetchAPIResource(import_types.APIResourceType.Swatch, swatchId, this.fetch)
|
|
76
76
|
);
|
|
77
77
|
}
|
|
78
78
|
resolveSwatch(swatchId) {
|
|
@@ -91,7 +91,7 @@ class MakeswiftHostApiClient {
|
|
|
91
91
|
}
|
|
92
92
|
async fetchFile(fileId) {
|
|
93
93
|
return await this.makeswiftApiClient.dispatch(
|
|
94
|
-
MakeswiftApiClient.fetchAPIResource(import_types.APIResourceType.File, fileId, this.
|
|
94
|
+
MakeswiftApiClient.fetchAPIResource(import_types.APIResourceType.File, fileId, this.fetch)
|
|
95
95
|
);
|
|
96
96
|
}
|
|
97
97
|
resolveFile(fileId) {
|
|
@@ -110,11 +110,7 @@ class MakeswiftHostApiClient {
|
|
|
110
110
|
}
|
|
111
111
|
async fetchTypography(typographyId) {
|
|
112
112
|
return await this.makeswiftApiClient.dispatch(
|
|
113
|
-
MakeswiftApiClient.fetchAPIResource(
|
|
114
|
-
import_types.APIResourceType.Typography,
|
|
115
|
-
typographyId,
|
|
116
|
-
this.siteVersion
|
|
117
|
-
)
|
|
113
|
+
MakeswiftApiClient.fetchAPIResource(import_types.APIResourceType.Typography, typographyId, this.fetch)
|
|
118
114
|
);
|
|
119
115
|
}
|
|
120
116
|
resolveTypography(typographyId) {
|
|
@@ -136,7 +132,7 @@ class MakeswiftHostApiClient {
|
|
|
136
132
|
MakeswiftApiClient.fetchAPIResource(
|
|
137
133
|
import_types.APIResourceType.GlobalElement,
|
|
138
134
|
globalElementId,
|
|
139
|
-
this.
|
|
135
|
+
this.fetch
|
|
140
136
|
)
|
|
141
137
|
);
|
|
142
138
|
}
|
|
@@ -159,7 +155,7 @@ class MakeswiftHostApiClient {
|
|
|
159
155
|
MakeswiftApiClient.fetchAPIResource(
|
|
160
156
|
import_types.APIResourceType.LocalizedGlobalElement,
|
|
161
157
|
globalElementId,
|
|
162
|
-
this.
|
|
158
|
+
this.fetch,
|
|
163
159
|
locale
|
|
164
160
|
)
|
|
165
161
|
);
|
|
@@ -183,7 +179,7 @@ class MakeswiftHostApiClient {
|
|
|
183
179
|
MakeswiftApiClient.fetchAPIResource(
|
|
184
180
|
import_types.APIResourceType.PagePathnameSlice,
|
|
185
181
|
pageId,
|
|
186
|
-
this.
|
|
182
|
+
this.fetch,
|
|
187
183
|
locale
|
|
188
184
|
)
|
|
189
185
|
);
|
|
@@ -224,7 +220,7 @@ class MakeswiftHostApiClient {
|
|
|
224
220
|
}
|
|
225
221
|
async fetchTable(tableId) {
|
|
226
222
|
return await this.makeswiftApiClient.dispatch(
|
|
227
|
-
MakeswiftApiClient.fetchAPIResource(import_types.APIResourceType.Table, tableId, this.
|
|
223
|
+
MakeswiftApiClient.fetchAPIResource(import_types.APIResourceType.Table, tableId, this.fetch)
|
|
228
224
|
);
|
|
229
225
|
}
|
|
230
226
|
async createTableRecord(tableId, columns) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/api/react.ts"],"sourcesContent":["import { type FetchableValue } from '@makeswift/controls'\nimport * as MakeswiftApiClient from '../state/makeswift-api-client'\nimport {\n APIResourceType,\n File,\n GlobalElement,\n LocalizedGlobalElement,\n Page,\n PagePathnameSlice,\n Site,\n Snippet,\n Swatch,\n Table,\n Typography,\n} from './types'\nimport { GraphQLClient } from './graphql/client'\nimport { CreateTableRecordMutation } from './graphql/documents'\nimport {\n CreateTableRecordMutationResult,\n CreateTableRecordMutationVariables,\n} from './graphql/generated/types'\nimport { MakeswiftSiteVersion } from './site-version'\n\nexport type CacheData = MakeswiftApiClient.SerializedState\n\nexport const CacheData = {\n empty(): CacheData {\n return {\n apiResources: {},\n localizedResourcesMap: {},\n }\n },\n}\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 MakeswiftHostApiClient {\n siteVersion: MakeswiftSiteVersion\n graphqlClient: GraphQLClient\n makeswiftApiClient: MakeswiftApiClient.Store\n subscribe: MakeswiftApiClient.Store['subscribe']\n\n constructor({\n uri,\n siteVersion,\n cacheData,\n locale,\n }: {\n uri: string\n siteVersion: MakeswiftSiteVersion\n cacheData?: CacheData\n locale?: string\n }) {\n this.graphqlClient = new GraphQLClient(uri)\n this.makeswiftApiClient = MakeswiftApiClient.configureStore({\n serializedState: cacheData,\n defaultLocale: locale,\n })\n this.siteVersion = siteVersion\n this.subscribe = this.makeswiftApiClient.subscribe\n }\n\n readSwatch(swatchId: string): Swatch | null {\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.Swatch,\n swatchId,\n )\n }\n\n async fetchSwatch(swatchId: string): Promise<Swatch | null> {\n return await this.makeswiftApiClient.dispatch(\n MakeswiftApiClient.fetchAPIResource(APIResourceType.Swatch, swatchId, this.siteVersion),\n )\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 readFile(fileId: string): File | null {\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.File,\n fileId,\n )\n }\n\n async fetchFile(fileId: string): Promise<File | null> {\n return await this.makeswiftApiClient.dispatch(\n MakeswiftApiClient.fetchAPIResource(APIResourceType.File, fileId, this.siteVersion),\n )\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 readTypography(typographyId: string): Typography | null {\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.Typography,\n typographyId,\n )\n }\n\n async fetchTypography(typographyId: string): Promise<Typography | null> {\n return await this.makeswiftApiClient.dispatch(\n MakeswiftApiClient.fetchAPIResource(\n APIResourceType.Typography,\n typographyId,\n this.siteVersion,\n ),\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 readGlobalElement(globalElementId: string): GlobalElement | null {\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.GlobalElement,\n globalElementId,\n )\n }\n\n async fetchGlobalElement(globalElementId: string): Promise<GlobalElement | null> {\n return await this.makeswiftApiClient.dispatch(\n MakeswiftApiClient.fetchAPIResource(\n APIResourceType.GlobalElement,\n globalElementId,\n this.siteVersion,\n ),\n )\n }\n\n readLocalizedGlobalElement({\n globalElementId,\n locale,\n }: {\n globalElementId: string\n locale: string\n }): LocalizedGlobalElement | null {\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.LocalizedGlobalElement,\n globalElementId,\n locale,\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.makeswiftApiClient.dispatch(\n MakeswiftApiClient.fetchAPIResource(\n APIResourceType.LocalizedGlobalElement,\n globalElementId,\n this.siteVersion,\n locale,\n ),\n )\n }\n\n readPagePathnameSlice({\n pageId,\n locale,\n }: {\n pageId: string\n locale: string | null\n }): PagePathnameSlice | null {\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.PagePathnameSlice,\n pageId,\n 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.makeswiftApiClient.dispatch(\n MakeswiftApiClient.fetchAPIResource(\n APIResourceType.PagePathnameSlice,\n pageId,\n this.siteVersion,\n locale,\n ),\n )\n }\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 readTable(tableId: string): Table | null {\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.Table,\n tableId,\n )\n }\n\n async fetchTable(tableId: string): Promise<Table | null> {\n return await this.makeswiftApiClient.dispatch(\n MakeswiftApiClient.fetchAPIResource(APIResourceType.Table, tableId, this.siteVersion),\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 readSite(siteId: string): Site | null {\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.Site,\n siteId,\n )\n }\n\n readPage(pageId: string): Page | null {\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.Page,\n pageId,\n )\n }\n\n readSnippet(snippetId: string): Snippet | null {\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.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nB,YAAY,MAAO,YAAY,MAAM;AAAA,MACrC,WAAW,CAAC,aACV,KAAK,UAAU,MAAM;AACnB,YAAI,MAAM,MAAM;AAAW,mBAAS;AAAA,MACtC,CAAC;AAAA,MACH,OAAO,YAAa,MAAM,OAAO,MAAM,EAAE,IAAI;AAAA,IAC/C;AAAA,EACF;AAAA,EAEA,UAAU,SAA+B;AACvC,WAAO,mBAAmB;AAAA,MACxB,KAAK,mBAAmB,SAAS;AAAA,MACjC,6BAAgB;AAAA,MAChB;AAAA,IACF;AAAA,EACF;AAAA,EAEA,MAAM,WAAW,SAAwC;AACvD,WAAO,MAAM,KAAK,mBAAmB;AAAA,MACnC,mBAAmB,iBAAiB,6BAAgB,OAAO,SAAS,KAAK,WAAW;AAAA,IACtF;AAAA,EACF;AAAA,EAEA,MAAM,kBAAkB,SAAiB,SAA6B;AACpE,UAAM,KAAK,cAAc,QAGvB,4CAA2B,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,QAAQ,EAAE,EAAE,CAAC;AAAA,EACxE;AAAA,EAEA,SAAS,QAA6B;AACpC,WAAO,mBAAmB;AAAA,MACxB,KAAK,mBAAmB,SAAS;AAAA,MACjC,6BAAgB;AAAA,MAChB;AAAA,IACF;AAAA,EACF;AAAA,EAEA,SAAS,QAA6B;AACpC,WAAO,mBAAmB;AAAA,MACxB,KAAK,mBAAmB,SAAS;AAAA,MACjC,6BAAgB;AAAA,MAChB;AAAA,IACF;AAAA,EACF;AAAA,EAEA,YAAY,WAAmC;AAC7C,WAAO,mBAAmB;AAAA,MACxB,KAAK,mBAAmB,SAAS;AAAA,MACjC,6BAAgB;AAAA,MAChB;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../src/api/react.ts"],"sourcesContent":["import { type FetchableValue } from '@makeswift/controls'\nimport * as MakeswiftApiClient from '../state/makeswift-api-client'\nimport {\n APIResourceType,\n File,\n GlobalElement,\n LocalizedGlobalElement,\n Page,\n PagePathnameSlice,\n Site,\n Snippet,\n Swatch,\n Table,\n Typography,\n} from './types'\nimport { GraphQLClient } from './graphql/client'\nimport { CreateTableRecordMutation } from './graphql/documents'\nimport {\n CreateTableRecordMutationResult,\n CreateTableRecordMutationVariables,\n} from './graphql/generated/types'\n\nexport type CacheData = MakeswiftApiClient.SerializedState\n\nexport const CacheData = {\n empty(): CacheData {\n return {\n apiResources: {},\n localizedResourcesMap: {},\n }\n },\n}\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 MakeswiftHostApiClient {\n graphqlClient: GraphQLClient\n makeswiftApiClient: MakeswiftApiClient.Store\n subscribe: MakeswiftApiClient.Store['subscribe']\n fetch: MakeswiftApiClient.HttpFetch\n\n constructor({\n uri,\n fetch,\n cacheData,\n locale,\n }: {\n uri: string\n fetch: MakeswiftApiClient.HttpFetch\n cacheData?: CacheData\n locale?: string\n }) {\n this.graphqlClient = new GraphQLClient(uri)\n this.makeswiftApiClient = MakeswiftApiClient.configureStore({\n serializedState: cacheData,\n defaultLocale: locale,\n })\n this.fetch = fetch\n this.subscribe = this.makeswiftApiClient.subscribe\n }\n\n readSwatch(swatchId: string): Swatch | null {\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.Swatch,\n swatchId,\n )\n }\n\n async fetchSwatch(swatchId: string): Promise<Swatch | null> {\n return await this.makeswiftApiClient.dispatch(\n MakeswiftApiClient.fetchAPIResource(APIResourceType.Swatch, swatchId, this.fetch),\n )\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 readFile(fileId: string): File | null {\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.File,\n fileId,\n )\n }\n\n async fetchFile(fileId: string): Promise<File | null> {\n return await this.makeswiftApiClient.dispatch(\n MakeswiftApiClient.fetchAPIResource(APIResourceType.File, fileId, this.fetch),\n )\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 readTypography(typographyId: string): Typography | null {\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.Typography,\n typographyId,\n )\n }\n\n async fetchTypography(typographyId: string): Promise<Typography | null> {\n return await this.makeswiftApiClient.dispatch(\n MakeswiftApiClient.fetchAPIResource(APIResourceType.Typography, typographyId, this.fetch),\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 readGlobalElement(globalElementId: string): GlobalElement | null {\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.GlobalElement,\n globalElementId,\n )\n }\n\n async fetchGlobalElement(globalElementId: string): Promise<GlobalElement | null> {\n return await this.makeswiftApiClient.dispatch(\n MakeswiftApiClient.fetchAPIResource(\n APIResourceType.GlobalElement,\n globalElementId,\n this.fetch,\n ),\n )\n }\n\n readLocalizedGlobalElement({\n globalElementId,\n locale,\n }: {\n globalElementId: string\n locale: string\n }): LocalizedGlobalElement | null {\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.LocalizedGlobalElement,\n globalElementId,\n locale,\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.makeswiftApiClient.dispatch(\n MakeswiftApiClient.fetchAPIResource(\n APIResourceType.LocalizedGlobalElement,\n globalElementId,\n this.fetch,\n locale,\n ),\n )\n }\n\n readPagePathnameSlice({\n pageId,\n locale,\n }: {\n pageId: string\n locale: string | null\n }): PagePathnameSlice | null {\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.PagePathnameSlice,\n pageId,\n 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.makeswiftApiClient.dispatch(\n MakeswiftApiClient.fetchAPIResource(\n APIResourceType.PagePathnameSlice,\n pageId,\n this.fetch,\n locale,\n ),\n )\n }\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 readTable(tableId: string): Table | null {\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.Table,\n tableId,\n )\n }\n\n async fetchTable(tableId: string): Promise<Table | null> {\n return await this.makeswiftApiClient.dispatch(\n MakeswiftApiClient.fetchAPIResource(APIResourceType.Table, tableId, this.fetch),\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 readSite(siteId: string): Site | null {\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.Site,\n siteId,\n )\n }\n\n readPage(pageId: string): Page | null {\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.Page,\n pageId,\n )\n }\n\n readSnippet(snippetId: string): Snippet | null {\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.Snippet,\n snippetId,\n )\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,yBAAoC;AACpC,mBAYO;AACP,oBAA8B;AAC9B,uBAA0C;AAQnC,MAAM,YAAY;AAAA,EACvB,QAAmB;AACjB,WAAO;AAAA,MACL,cAAc,CAAC;AAAA,MACf,uBAAuB,CAAC;AAAA,IAC1B;AAAA,EACF;AACF;AAqBO,MAAM,uBAAuB;AAAA,EAClC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA,YAAY;AAAA,IACV;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,GAKG;AACD,SAAK,gBAAgB,IAAI,4BAAc,GAAG;AAC1C,SAAK,qBAAqB,mB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kB,SAAiB,SAA6B;AACpE,UAAM,KAAK,cAAc,QAGvB,4CAA2B,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,QAAQ,EAAE,EAAE,CAAC;AAAA,EACxE;AAAA,EAEA,SAAS,QAA6B;AACpC,WAAO,mBAAmB;AAAA,MACxB,KAAK,mBAAmB,SAAS;AAAA,MACjC,6BAAgB;AAAA,MAChB;AAAA,IACF;AAAA,EACF;AAAA,EAEA,SAAS,QAA6B;AACpC,WAAO,mBAAmB;AAAA,MACxB,KAAK,mBAAmB,SAAS;AAAA,MACjC,6BAAgB;AAAA,MAChB;AAAA,IACF;AAAA,EACF;AAAA,EAEA,YAAY,WAAmC;AAC7C,WAAO,mBAAmB;AAAA,MACxB,KAAK,mBAAmB,SAAS;AAAA,MACjC,6BAAgB;AAAA,MAChB;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
|
@@ -28,7 +28,7 @@ async function manifestHandler(req, { apiKey, manifest }) {
|
|
|
28
28
|
return import_request_response.ApiResponse.json({ message: "Unauthorized" }, { status: 401 });
|
|
29
29
|
}
|
|
30
30
|
return import_request_response.ApiResponse.json({
|
|
31
|
-
version: "0.25.0-canary.
|
|
31
|
+
version: "0.25.0-canary.13",
|
|
32
32
|
previewMode: false,
|
|
33
33
|
draftMode: false,
|
|
34
34
|
interactionMode: true,
|
|
@@ -37,6 +37,7 @@ var import_react = require("react");
|
|
|
37
37
|
var import_image = __toESM(require("next/image"));
|
|
38
38
|
var import_use_is_pages_router = require("../../hooks/use-is-pages-router");
|
|
39
39
|
var import_framework_context = require("../../../runtimes/react/components/framework-context");
|
|
40
|
+
var import_cache = require("../../cache");
|
|
40
41
|
var import_app_router = require("./app-router");
|
|
41
42
|
var import_pages_router = require("./pages-router");
|
|
42
43
|
var import_link = require("./link");
|
|
@@ -49,7 +50,8 @@ function FrameworkProvider({
|
|
|
49
50
|
() => ({
|
|
50
51
|
...isPagesRouter ? import_pages_router.context : import_app_router.context,
|
|
51
52
|
Image: import_image.default,
|
|
52
|
-
Link: import_link.Link
|
|
53
|
+
Link: import_link.Link,
|
|
54
|
+
versionedFetch: (siteVersion) => (url, init) => (0, import_framework_context.versionedFetch)(siteVersion)(url, { ...init, next: { tags: [import_cache.MAKESWIFT_CACHE_TAG] } })
|
|
53
55
|
}),
|
|
54
56
|
[isPagesRouter]
|
|
55
57
|
);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/next/components/framework-provider/index.tsx"],"sourcesContent":["'use client'\n\nimport { type PropsWithChildren, useMemo } from 'react'\nimport NextImage from 'next/image'\n\nimport { useIsPagesRouter } from '../../hooks/use-is-pages-router'\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../../../src/next/components/framework-provider/index.tsx"],"sourcesContent":["'use client'\n\nimport { type PropsWithChildren, useMemo } from 'react'\nimport NextImage from 'next/image'\n\nimport { useIsPagesRouter } from '../../hooks/use-is-pages-router'\nimport {\n FrameworkContext,\n versionedFetch,\n} from '../../../runtimes/react/components/framework-context'\n\nimport { MakeswiftSiteVersion } from '../../../api/site-version'\nimport { MAKESWIFT_CACHE_TAG } from '../../cache'\n\nimport { context as appRouterContext } from './app-router'\nimport { context as pagesRouterContext } from './pages-router'\nimport { Link } from './link'\n\nexport function FrameworkProvider({\n children,\n forcePagesRouter,\n}: PropsWithChildren<{ forcePagesRouter?: boolean }>) {\n const isPagesRouter = useIsPagesRouter() || forcePagesRouter\n const context = useMemo<FrameworkContext>(\n () => ({\n ...(isPagesRouter ? pagesRouterContext : appRouterContext),\n Image: NextImage,\n Link,\n versionedFetch: (siteVersion: MakeswiftSiteVersion) => (url, init) =>\n versionedFetch(siteVersion)(url, { ...init, next: { tags: [MAKESWIFT_CACHE_TAG] } }),\n }),\n [isPagesRouter],\n )\n\n return <FrameworkContext.Provider value={context}>{children}</FrameworkContext.Provider>\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAkCS;AAhCT,mBAAgD;AAChD,mBAAsB;AAEtB,iCAAiC;AACjC,+BAGO;AAGP,mBAAoC;AAEpC,wBAA4C;AAC5C,0BAA8C;AAC9C,kBAAqB;AAEd,SAAS,kBAAkB;AAAA,EAChC;AAAA,EACA;AACF,GAAsD;AACpD,QAAM,oBAAgB,6CAAiB,KAAK;AAC5C,QAAM,cAAU;AAAA,IACd,OAAO;AAAA,MACL,GAAI,gBAAgB,oBAAAA,UAAqB,kBAAAC;AAAA,MACzC,OAAO,aAAAC;AAAA,MACP;AAAA,MACA,gBAAgB,CAAC,gBAAsC,CAAC,KAAK,aAC3D,yCAAe,WAAW,EAAE,KAAK,EAAE,GAAG,MAAM,MAAM,EAAE,MAAM,CAAC,gCAAmB,EAAE,EAAE,CAAC;AAAA,IACvF;AAAA,IACA,CAAC,aAAa;AAAA,EAChB;AAEA,SAAO,4CAAC,0CAAiB,UAAjB,EAA0B,OAAO,SAAU,UAAS;AAC9D;","names":["pagesRouterContext","appRouterContext","NextImage"]}
|
|
@@ -40,6 +40,7 @@ var import_host_api_client = require("../host-api-client");
|
|
|
40
40
|
var import_site_version = require("../../../api/site-version");
|
|
41
41
|
var import_draft_switcher = require("./draft-switcher/draft-switcher");
|
|
42
42
|
var import_use_builder_connection_ping = require("./hooks/use-builder-connection-ping");
|
|
43
|
+
var import_use_framework_context = require("./hooks/use-framework-context");
|
|
43
44
|
const LiveProvider = (0, import_react.lazy)(() => Promise.resolve().then(() => __toESM(require("./LiveProvider"))));
|
|
44
45
|
const PreviewProvider = (0, import_react.lazy)(() => Promise.resolve().then(() => __toESM(require("./PreviewProvider"))));
|
|
45
46
|
function RuntimeProvider({
|
|
@@ -50,13 +51,16 @@ function RuntimeProvider({
|
|
|
50
51
|
apiOrigin = "https://api.makeswift.com",
|
|
51
52
|
locale = void 0
|
|
52
53
|
}) {
|
|
54
|
+
const { versionedFetch } = (0, import_use_framework_context.useFrameworkContext)();
|
|
53
55
|
const client = (0, import_react.useMemo)(
|
|
54
56
|
() => new import_react2.MakeswiftHostApiClient({
|
|
55
57
|
uri: new URL("graphql", apiOrigin).href,
|
|
56
58
|
locale,
|
|
57
|
-
|
|
59
|
+
fetch: versionedFetch(
|
|
60
|
+
previewMode ? import_site_version.MakeswiftSiteVersion.Working : import_site_version.MakeswiftSiteVersion.Live
|
|
61
|
+
)
|
|
58
62
|
}),
|
|
59
|
-
[apiOrigin, locale, previewMode]
|
|
63
|
+
[apiOrigin, locale, previewMode, versionedFetch]
|
|
60
64
|
);
|
|
61
65
|
const StoreProvider = previewMode ? PreviewProvider : LiveProvider;
|
|
62
66
|
(0, import_use_builder_connection_ping.useBuilderConnectionPing)({ appOrigin });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/runtimes/react/components/RuntimeProvider.tsx"],"sourcesContent":["'use client'\n\nimport { ReactNode, useMemo, lazy } from 'react'\n\nimport { MakeswiftHostApiClient } from '../../../api/react'\nimport { ReactRuntimeContext } from '../hooks/use-react-runtime'\nimport { ReactRuntime } from '../react-runtime'\nimport { MakeswiftHostApiClientProvider } from '../host-api-client'\nimport { MakeswiftSiteVersion } from '../../../api/site-version'\nimport { DraftSwitcher } from './draft-switcher/draft-switcher'\nimport { useBuilderConnectionPing } from './hooks/use-builder-connection-ping'\n\nconst LiveProvider = lazy(() => import('./LiveProvider'))\nconst PreviewProvider = lazy(() => import('./PreviewProvider'))\n\nexport function RuntimeProvider({\n children,\n runtime,\n previewMode,\n appOrigin = 'https://app.makeswift.com',\n apiOrigin = 'https://api.makeswift.com',\n locale = undefined,\n}: {\n children: ReactNode\n runtime: ReactRuntime\n previewMode: boolean\n apiOrigin?: string\n appOrigin?: string\n locale?: string\n}) {\n const client = useMemo(\n () =>\n new MakeswiftHostApiClient({\n uri: new URL('graphql', apiOrigin).href,\n locale,\n
|
|
1
|
+
{"version":3,"sources":["../../../../../src/runtimes/react/components/RuntimeProvider.tsx"],"sourcesContent":["'use client'\n\nimport { ReactNode, useMemo, lazy } from 'react'\n\nimport { MakeswiftHostApiClient } from '../../../api/react'\nimport { ReactRuntimeContext } from '../hooks/use-react-runtime'\nimport { ReactRuntime } from '../react-runtime'\nimport { MakeswiftHostApiClientProvider } from '../host-api-client'\nimport { MakeswiftSiteVersion } from '../../../api/site-version'\nimport { DraftSwitcher } from './draft-switcher/draft-switcher'\nimport { useBuilderConnectionPing } from './hooks/use-builder-connection-ping'\nimport { useFrameworkContext } from './hooks/use-framework-context'\n\nconst LiveProvider = lazy(() => import('./LiveProvider'))\nconst PreviewProvider = lazy(() => import('./PreviewProvider'))\n\nexport function RuntimeProvider({\n children,\n runtime,\n previewMode,\n appOrigin = 'https://app.makeswift.com',\n apiOrigin = 'https://api.makeswift.com',\n locale = undefined,\n}: {\n children: ReactNode\n runtime: ReactRuntime\n previewMode: boolean\n apiOrigin?: string\n appOrigin?: string\n locale?: string\n}) {\n const { versionedFetch } = useFrameworkContext()\n\n const client = useMemo(\n () =>\n new MakeswiftHostApiClient({\n uri: new URL('graphql', apiOrigin).href,\n locale,\n fetch: versionedFetch(\n previewMode ? MakeswiftSiteVersion.Working : MakeswiftSiteVersion.Live,\n ),\n }),\n [apiOrigin, locale, previewMode, versionedFetch],\n )\n\n const StoreProvider = previewMode ? PreviewProvider : LiveProvider\n\n useBuilderConnectionPing({ appOrigin })\n\n return (\n <ReactRuntimeContext.Provider value={runtime}>\n <MakeswiftHostApiClientProvider client={client}>\n <StoreProvider>\n {children}\n <DraftSwitcher isDraft={previewMode} />\n </StoreProvider>\n </MakeswiftHostApiClientProvider>\n </ReactRuntimeContext.Provider>\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAoDQ;AAlDR,mBAAyC;AAEzC,IAAAA,gBAAuC;AACvC,+BAAoC;AAEpC,6BAA+C;AAC/C,0BAAqC;AACrC,4BAA8B;AAC9B,yCAAyC;AACzC,mCAAoC;AAEpC,MAAM,mBAAe,mBAAK,MAAM,6CAAO,gBAAgB,GAAC;AACxD,MAAM,sBAAkB,mBAAK,MAAM,6CAAO,mBAAmB,GAAC;AAEvD,SAAS,gBAAgB;AAAA,EAC9B;AAAA,EACA;AAAA,EACA;AAAA,EACA,YAAY;AAAA,EACZ,YAAY;AAAA,EACZ,SAAS;AACX,GAOG;AACD,QAAM,EAAE,eAAe,QAAI,kDAAoB;AAE/C,QAAM,aAAS;AAAA,IACb,MACE,IAAI,qCAAuB;AAAA,MACzB,KAAK,IAAI,IAAI,WAAW,SAAS,EAAE;AAAA,MACnC;AAAA,MACA,OAAO;AAAA,QACL,cAAc,yCAAqB,UAAU,yCAAqB;AAAA,MACpE;AAAA,IACF,CAAC;AAAA,IACH,CAAC,WAAW,QAAQ,aAAa,cAAc;AAAA,EACjD;AAEA,QAAM,gBAAgB,cAAc,kBAAkB;AAEtD,mEAAyB,EAAE,UAAU,CAAC;AAEtC,SACE,4CAAC,6CAAoB,UAApB,EAA6B,OAAO,SACnC,sDAAC,yDAA+B,QAC9B,uDAAC,iBACE;AAAA;AAAA,IACD,4CAAC,uCAAc,SAAS,aAAa;AAAA,KACvC,GACF,GACF;AAEJ;","names":["import_react"]}
|
|
@@ -21,11 +21,13 @@ __export(framework_context_exports, {
|
|
|
21
21
|
DefaultHead: () => DefaultHead,
|
|
22
22
|
DefaultImage: () => DefaultImage,
|
|
23
23
|
DefaultLink: () => DefaultLink,
|
|
24
|
-
FrameworkContext: () => FrameworkContext
|
|
24
|
+
FrameworkContext: () => FrameworkContext,
|
|
25
|
+
versionedFetch: () => versionedFetch
|
|
25
26
|
});
|
|
26
27
|
module.exports = __toCommonJS(framework_context_exports);
|
|
27
28
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
28
29
|
var import_react = require("react");
|
|
30
|
+
var import_site_version = require("../../../api/site-version");
|
|
29
31
|
var import_HeadSnippet = require("./page/HeadSnippet");
|
|
30
32
|
const DefaultHead = ({ children }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children });
|
|
31
33
|
const DefaultImage = ({ priority, fill, style, ...props }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
@@ -46,17 +48,26 @@ const DefaultImage = ({ priority, fill, style, ...props }) => /* @__PURE__ */ (0
|
|
|
46
48
|
const DefaultLink = (0, import_react.forwardRef)(
|
|
47
49
|
({ linkType, ...props }, ref) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("a", { ...props, ref })
|
|
48
50
|
);
|
|
51
|
+
const versionedFetch = (siteVersion) => (url, init) => fetch(url, {
|
|
52
|
+
...init,
|
|
53
|
+
headers: {
|
|
54
|
+
...init?.headers,
|
|
55
|
+
[import_site_version.API_HANDLER_SITE_VERSION_HEADER]: siteVersion
|
|
56
|
+
}
|
|
57
|
+
});
|
|
49
58
|
const FrameworkContext = (0, import_react.createContext)({
|
|
50
59
|
Head: DefaultHead,
|
|
51
60
|
HeadSnippet: import_HeadSnippet.BaseHeadSnippet,
|
|
52
61
|
Image: DefaultImage,
|
|
53
|
-
Link: DefaultLink
|
|
62
|
+
Link: DefaultLink,
|
|
63
|
+
versionedFetch
|
|
54
64
|
});
|
|
55
65
|
// Annotate the CommonJS export names for ESM import in node:
|
|
56
66
|
0 && (module.exports = {
|
|
57
67
|
DefaultHead,
|
|
58
68
|
DefaultImage,
|
|
59
69
|
DefaultLink,
|
|
60
|
-
FrameworkContext
|
|
70
|
+
FrameworkContext,
|
|
71
|
+
versionedFetch
|
|
61
72
|
});
|
|
62
73
|
//# sourceMappingURL=framework-context.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/runtimes/react/components/framework-context.tsx"],"sourcesContent":["import {\n createContext,\n type ReactNode,\n type PropsWithChildren,\n type CSSProperties,\n type ComponentPropsWithoutRef,\n type MouseEvent,\n type ForwardRefExoticComponent,\n type RefAttributes,\n forwardRef,\n} from 'react'\n\nimport { type LinkData } from '@makeswift/prop-controllers'\n\nimport { type Snippet } from '../../../client'\n\nimport { BaseHeadSnippet } from './page/HeadSnippet'\n\ntype HeadComponent = (props: { children: ReactNode }) => ReactNode\ntype HeadSnippet = (props: { snippet: Snippet }) => ReactNode\ntype ImageComponent = (props: {\n src: string\n alt: string\n sizes?: string\n width?: number\n height?: number\n priority?: boolean\n fill?: boolean\n style?: CSSProperties\n}) => ReactNode\n\ntype LinkProps = Omit<ComponentPropsWithoutRef<'a'>, 'onClick'> & {\n linkType?: LinkData['type']\n onClick?: (event: MouseEvent<HTMLAnchorElement>) => unknown\n}\n\ntype LinkComponent = ForwardRefExoticComponent<RefAttributes<HTMLAnchorElement> & LinkProps>\n\nexport type FrameworkContext = {\n Head: HeadComponent\n HeadSnippet: HeadSnippet\n Image: ImageComponent\n Link: LinkComponent\n}\n\n// React 19 automatically hoists metadata tags to the <head>\nexport const DefaultHead = ({ children }: PropsWithChildren) => <>{children}</>\n\nexport const DefaultImage: ImageComponent = ({ priority, fill, style, ...props }) => (\n <img\n {...props}\n style={{\n ...(fill\n ? {\n height: '100%',\n width: '100%',\n objectFit: 'cover',\n }\n : {}),\n ...style,\n }}\n loading={priority ? 'eager' : 'lazy'}\n />\n)\n\nexport const DefaultLink: LinkComponent = forwardRef<HTMLAnchorElement, LinkProps>(\n ({ linkType, ...props }, ref) => <a {...props} ref={ref} />,\n)\n\nexport const FrameworkContext = createContext<FrameworkContext>({\n Head: DefaultHead,\n HeadSnippet: BaseHeadSnippet,\n Image: DefaultImage,\n Link: DefaultLink,\n})\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
1
|
+
{"version":3,"sources":["../../../../../src/runtimes/react/components/framework-context.tsx"],"sourcesContent":["import {\n createContext,\n type ReactNode,\n type PropsWithChildren,\n type CSSProperties,\n type ComponentPropsWithoutRef,\n type MouseEvent,\n type ForwardRefExoticComponent,\n type RefAttributes,\n forwardRef,\n} from 'react'\n\nimport { type LinkData } from '@makeswift/prop-controllers'\n\nimport { type Snippet } from '../../../client'\nimport { type HttpFetch } from '../../../state/makeswift-api-client'\nimport { API_HANDLER_SITE_VERSION_HEADER, MakeswiftSiteVersion } from '../../../api/site-version'\n\nimport { BaseHeadSnippet } from './page/HeadSnippet'\n\ntype HeadComponent = (props: { children: ReactNode }) => ReactNode\ntype HeadSnippet = (props: { snippet: Snippet }) => ReactNode\ntype ImageComponent = (props: {\n src: string\n alt: string\n sizes?: string\n width?: number\n height?: number\n priority?: boolean\n fill?: boolean\n style?: CSSProperties\n}) => ReactNode\n\ntype LinkProps = Omit<ComponentPropsWithoutRef<'a'>, 'onClick'> & {\n linkType?: LinkData['type']\n onClick?: (event: MouseEvent<HTMLAnchorElement>) => unknown\n}\n\ntype LinkComponent = ForwardRefExoticComponent<RefAttributes<HTMLAnchorElement> & LinkProps>\n\nexport type FrameworkContext = {\n Head: HeadComponent\n HeadSnippet: HeadSnippet\n Image: ImageComponent\n Link: LinkComponent\n versionedFetch: (siteVersion: MakeswiftSiteVersion) => HttpFetch\n}\n\n// React 19 automatically hoists metadata tags to the <head>\nexport const DefaultHead = ({ children }: PropsWithChildren) => <>{children}</>\n\nexport const DefaultImage: ImageComponent = ({ priority, fill, style, ...props }) => (\n <img\n {...props}\n style={{\n ...(fill\n ? {\n height: '100%',\n width: '100%',\n objectFit: 'cover',\n }\n : {}),\n ...style,\n }}\n loading={priority ? 'eager' : 'lazy'}\n />\n)\n\nexport const DefaultLink: LinkComponent = forwardRef<HTMLAnchorElement, LinkProps>(\n ({ linkType, ...props }, ref) => <a {...props} ref={ref} />,\n)\n\nexport const versionedFetch: FrameworkContext['versionedFetch'] = siteVersion => (url, init) =>\n fetch(url, {\n ...init,\n headers: {\n ...init?.headers,\n [API_HANDLER_SITE_VERSION_HEADER]: siteVersion,\n },\n })\n\nexport const FrameworkContext = createContext<FrameworkContext>({\n Head: DefaultHead,\n HeadSnippet: BaseHeadSnippet,\n Image: DefaultImage,\n Link: DefaultLink,\n versionedFetch,\n})\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAiDgE;AAjDhE,mBAUO;AAMP,0BAAsE;AAEtE,yBAAgC;AA+BzB,MAAM,cAAc,CAAC,EAAE,SAAS,MAAyB,2EAAG,UAAS;AAErE,MAAM,eAA+B,CAAC,EAAE,UAAU,MAAM,OAAO,GAAG,MAAM,MAC7E;AAAA,EAAC;AAAA;AAAA,IACE,GAAG;AAAA,IACJ,OAAO;AAAA,MACL,GAAI,OACA;AAAA,QACE,QAAQ;AAAA,QACR,OAAO;AAAA,QACP,WAAW;AAAA,MACb,IACA,CAAC;AAAA,MACL,GAAG;AAAA,IACL;AAAA,IACA,SAAS,WAAW,UAAU;AAAA;AAChC;AAGK,MAAM,kBAA6B;AAAA,EACxC,CAAC,EAAE,UAAU,GAAG,MAAM,GAAG,QAAQ,4CAAC,OAAG,GAAG,OAAO,KAAU;AAC3D;AAEO,MAAM,iBAAqD,iBAAe,CAAC,KAAK,SACrF,MAAM,KAAK;AAAA,EACT,GAAG;AAAA,EACH,SAAS;AAAA,IACP,GAAG,MAAM;AAAA,IACT,CAAC,mDAA+B,GAAG;AAAA,EACrC;AACF,CAAC;AAEI,MAAM,uBAAmB,4BAAgC;AAAA,EAC9D,MAAM;AAAA,EACN,aAAa;AAAA,EACb,OAAO;AAAA,EACP,MAAM;AAAA,EACN;AACF,CAAC;","names":[]}
|
|
@@ -26,11 +26,16 @@ module.exports = __toCommonJS(host_api_client_exports);
|
|
|
26
26
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
27
27
|
var import_react = require("react");
|
|
28
28
|
var import_react2 = require("../../api/react");
|
|
29
|
-
var import_site_version = require("../../api/site-version");
|
|
30
29
|
const Context = (0, import_react.createContext)(
|
|
31
30
|
new import_react2.MakeswiftHostApiClient({
|
|
32
31
|
uri: "https://api.makeswift.com/graphql",
|
|
33
|
-
|
|
32
|
+
fetch: async (url, init) => {
|
|
33
|
+
console.warn(
|
|
34
|
+
"Using fallback `fetch` implementation, resource revalidation may not work as expected.",
|
|
35
|
+
{ url }
|
|
36
|
+
);
|
|
37
|
+
return fetch(url, init);
|
|
38
|
+
}
|
|
34
39
|
})
|
|
35
40
|
);
|
|
36
41
|
function useMakeswiftHostApiClient() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/runtimes/react/host-api-client.tsx"],"sourcesContent":["'use client'\n\nimport { ReactNode, createContext, useContext } from 'react'\nimport { MakeswiftHostApiClient } from '../../api/react'\
|
|
1
|
+
{"version":3,"sources":["../../../../src/runtimes/react/host-api-client.tsx"],"sourcesContent":["'use client'\n\nimport { ReactNode, createContext, useContext } from 'react'\nimport { MakeswiftHostApiClient } from '../../api/react'\n\nconst Context = createContext(\n new MakeswiftHostApiClient({\n uri: 'https://api.makeswift.com/graphql',\n fetch: async (url, init) => {\n console.warn(\n 'Using fallback `fetch` implementation, resource revalidation may not work as expected.',\n { url },\n )\n return fetch(url, init)\n },\n }),\n)\n\nexport function useMakeswiftHostApiClient(): MakeswiftHostApiClient {\n return useContext(Context)\n}\n\nexport function MakeswiftHostApiClientProvider({\n client,\n children,\n}: {\n client: MakeswiftHostApiClient\n children: ReactNode\n}) {\n return <Context.Provider value={client}>{children}</Context.Provider>\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA6BS;AA3BT,mBAAqD;AACrD,IAAAA,gBAAuC;AAEvC,MAAM,cAAU;AAAA,EACd,IAAI,qCAAuB;AAAA,IACzB,KAAK;AAAA,IACL,OAAO,OAAO,KAAK,SAAS;AAC1B,cAAQ;AAAA,QACN;AAAA,QACA,EAAE,IAAI;AAAA,MACR;AACA,aAAO,MAAM,KAAK,IAAI;AAAA,IACxB;AAAA,EACF,CAAC;AACH;AAEO,SAAS,4BAAoD;AAClE,aAAO,yBAAW,OAAO;AAC3B;AAEO,SAAS,+BAA+B;AAAA,EAC7C;AAAA,EACA;AACF,GAGG;AACD,SAAO,4CAAC,QAAQ,UAAR,EAAiB,OAAO,QAAS,UAAS;AACpD;","names":["import_react"]}
|
|
@@ -40,8 +40,6 @@ var LocalizedResourcesMap = __toESM(require("./modules/localized-resources-map")
|
|
|
40
40
|
var import_actions = require("./actions");
|
|
41
41
|
var import_toolkit2 = require("./toolkit");
|
|
42
42
|
var import_api = require("../api");
|
|
43
|
-
var import_cache = require("../next/cache");
|
|
44
|
-
var import_site_version = require("../api/site-version");
|
|
45
43
|
const reducer = (0, import_toolkit.combineReducers)({
|
|
46
44
|
apiResources: APIResources.reducer,
|
|
47
45
|
localizedResourcesMap: LocalizedResourcesMap.reducer
|
|
@@ -79,26 +77,24 @@ function getAPIResource(state, resourceType, resourceId, locale) {
|
|
|
79
77
|
return APIResources.getAPIResource(state.apiResources, resourceType, resourceId, locale);
|
|
80
78
|
}
|
|
81
79
|
}
|
|
82
|
-
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
}
|
|
101
|
-
function fetchAPIResource(resourceType, resourceId, siteVersion, locale) {
|
|
80
|
+
function fetchAPIResource(resourceType, resourceId, fetch, locale) {
|
|
81
|
+
const fetchJson = async (url) => {
|
|
82
|
+
const response = await fetch(url, {
|
|
83
|
+
headers: {
|
|
84
|
+
"Content-Type": "application/json"
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
if (response.status === 404)
|
|
88
|
+
return null;
|
|
89
|
+
if (!response.ok)
|
|
90
|
+
throw new Error(response.statusText);
|
|
91
|
+
if (response.headers.get("content-type")?.includes("application/json") !== true) {
|
|
92
|
+
throw new Error(
|
|
93
|
+
`Expected JSON response from "${url}" but got "${response.headers.get("content-type")}"`
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
return response.json();
|
|
97
|
+
};
|
|
102
98
|
return async (dispatch, getState) => {
|
|
103
99
|
const state = getState();
|
|
104
100
|
if (getHasAPIResource(state, resourceType, resourceId, locale)) {
|
|
@@ -107,22 +103,16 @@ function fetchAPIResource(resourceType, resourceId, siteVersion, locale) {
|
|
|
107
103
|
let resource;
|
|
108
104
|
switch (resourceType) {
|
|
109
105
|
case import_api.APIResourceType.Swatch:
|
|
110
|
-
resource = await fetchJson(`/api/makeswift/swatches/${resourceId}
|
|
106
|
+
resource = await fetchJson(`/api/makeswift/swatches/${resourceId}`);
|
|
111
107
|
break;
|
|
112
108
|
case import_api.APIResourceType.File:
|
|
113
|
-
resource = await fetchJson(`/api/makeswift/files/${resourceId}
|
|
109
|
+
resource = await fetchJson(`/api/makeswift/files/${resourceId}`);
|
|
114
110
|
break;
|
|
115
111
|
case import_api.APIResourceType.Typography:
|
|
116
|
-
resource = await fetchJson(
|
|
117
|
-
`/api/makeswift/typographies/${resourceId}`,
|
|
118
|
-
siteVersion
|
|
119
|
-
);
|
|
112
|
+
resource = await fetchJson(`/api/makeswift/typographies/${resourceId}`);
|
|
120
113
|
break;
|
|
121
114
|
case import_api.APIResourceType.GlobalElement:
|
|
122
|
-
resource = await fetchJson(
|
|
123
|
-
`/api/makeswift/global-elements/${resourceId}`,
|
|
124
|
-
siteVersion
|
|
125
|
-
);
|
|
115
|
+
resource = await fetchJson(`/api/makeswift/global-elements/${resourceId}`);
|
|
126
116
|
break;
|
|
127
117
|
case import_api.APIResourceType.LocalizedGlobalElement: {
|
|
128
118
|
if (locale == null)
|
|
@@ -131,8 +121,7 @@ function fetchAPIResource(resourceType, resourceId, siteVersion, locale) {
|
|
|
131
121
|
return null;
|
|
132
122
|
}
|
|
133
123
|
resource = await fetchJson(
|
|
134
|
-
`/api/makeswift/localized-global-elements/${resourceId}/${locale}
|
|
135
|
-
siteVersion
|
|
124
|
+
`/api/makeswift/localized-global-elements/${resourceId}/${locale}`
|
|
136
125
|
);
|
|
137
126
|
dispatch(
|
|
138
127
|
(0, import_actions.setLocalizedResourceId)({
|
|
@@ -147,11 +136,11 @@ function fetchAPIResource(resourceType, resourceId, siteVersion, locale) {
|
|
|
147
136
|
const url = new URL(`/api/makeswift/page-pathname-slices/${resourceId}`, "http://n");
|
|
148
137
|
if (locale != null)
|
|
149
138
|
url.searchParams.set("locale", locale);
|
|
150
|
-
resource = await fetchJson(url.pathname + url.search
|
|
139
|
+
resource = await fetchJson(url.pathname + url.search);
|
|
151
140
|
break;
|
|
152
141
|
}
|
|
153
142
|
case import_api.APIResourceType.Table:
|
|
154
|
-
resource = await fetchJson(`/api/makeswift/tables/${resourceId}
|
|
143
|
+
resource = await fetchJson(`/api/makeswift/tables/${resourceId}`);
|
|
155
144
|
break;
|
|
156
145
|
default:
|
|
157
146
|
resource = null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/state/makeswift-api-client.ts"],"sourcesContent":["import {\n configureStore as configureReduxStore,\n combineReducers,\n type ThunkAction,\n type ThunkMiddleware,\n type ThunkDispatch,\n UnknownAction,\n} from '@reduxjs/toolkit'\n\nimport * as APIResources from './modules/api-resources'\nimport * as LocalizedResourcesMap from './modules/localized-resources-map'\nimport { type Action, ActionTypes, apiResourceFulfilled, setLocalizedResourceId } from './actions'\nimport { actionMiddleware, middlewareOptions, devToolsConfig } from './toolkit'\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'\nimport { MAKESWIFT_CACHE_TAG } from '../next/cache'\nimport { API_HANDLER_SITE_VERSION_HEADER, MakeswiftSiteVersion } from '../api/site-version'\n\nconst reducer = combineReducers({\n apiResources: APIResources.reducer,\n localizedResourcesMap: LocalizedResourcesMap.reducer,\n})\n\nexport type State = ReturnType<typeof reducer>\nexport type Dispatch = ThunkDispatch<State, unknown, Action>\n\nexport type SerializedState = {\n apiResources: APIResources.SerializedState\n localizedResourcesMap: LocalizedResourcesMap.SerializedState\n}\n\nfunction getLocalizedResourceId(\n state: State,\n locale: string,\n resourceId: string,\n): string | undefined | null {\n return LocalizedResourcesMap.getLocalizedResourceId(\n state.localizedResourcesMap,\n locale,\n resourceId,\n )\n}\n\nexport function getHasAPIResource<T extends APIResourceType>(\n state: State,\n resourceType: APIResourceType,\n resourceId: string,\n locale?: APIResourceLocale<T>,\n): boolean {\n switch (resourceType) {\n case APIResourceType.LocalizedGlobalElement:\n if (locale == null) {\n console.error(`Attempt to access ${resourceType} ${resourceId} without a locale`)\n return false\n }\n\n const localizedId = getLocalizedResourceId(state, locale, resourceId)\n return (\n localizedId != null &&\n APIResources.getHasAPIResource(state.apiResources, resourceType, localizedId, locale)\n )\n\n default:\n return APIResources.getHasAPIResource(state.apiResources, resourceType, resourceId, locale)\n }\n}\n\nexport function getAPIResource<T extends APIResourceType>(\n state: State,\n resourceType: T,\n resourceId: string,\n locale?: APIResourceLocale<T>,\n): Extract<APIResource, { __typename: T }> | null {\n switch (resourceType) {\n case APIResourceType.LocalizedGlobalElement:\n if (locale == null) {\n console.error(`Attempt to access ${resourceType} ${resourceId} without a locale`)\n return null\n }\n\n const localizedId = getLocalizedResourceId(state, locale, resourceId)\n return localizedId != null\n ? APIResources.getAPIResource(state.apiResources, resourceType, localizedId, locale)\n : null\n\n default:\n return APIResources.getAPIResource(state.apiResources, resourceType, resourceId, locale)\n }\n}\n\ntype Thunk<ReturnType> = ThunkAction<ReturnType, State, unknown, Action>\n\nasync function fetchJson<T>(url: string, siteVersion: MakeswiftSiteVersion): Promise<T | null> {\n const response = await fetch(url, {\n headers: {\n 'Content-Type': 'application/json',\n [API_HANDLER_SITE_VERSION_HEADER]: siteVersion,\n },\n next: { tags: [MAKESWIFT_CACHE_TAG] },\n })\n\n if (response.status === 404) return null\n\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\nexport function fetchAPIResource<T extends APIResourceType>(\n resourceType: T,\n resourceId: string,\n siteVersion: MakeswiftSiteVersion,\n locale?: APIResourceLocale<T>,\n): Thunk<Promise<Extract<APIResource, { __typename: T }> | null>> {\n return async (dispatch, getState) => {\n const state = getState()\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 fetchJson<Swatch>(`/api/makeswift/swatches/${resourceId}`, siteVersion)\n break\n\n case APIResourceType.File:\n resource = await fetchJson<File>(`/api/makeswift/files/${resourceId}`, siteVersion)\n break\n\n case APIResourceType.Typography:\n resource = await fetchJson<Typography>(\n `/api/makeswift/typographies/${resourceId}`,\n siteVersion,\n )\n break\n\n case APIResourceType.GlobalElement:\n resource = await fetchJson<GlobalElement>(\n `/api/makeswift/global-elements/${resourceId}`,\n siteVersion,\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 fetchJson<LocalizedGlobalElement>(\n `/api/makeswift/localized-global-elements/${resourceId}/${locale}`,\n siteVersion,\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 fetchJson<PagePathnameSlice>(url.pathname + url.search, siteVersion)\n break\n }\n\n case APIResourceType.Table:\n resource = await fetchJson<Table>(`/api/makeswift/tables/${resourceId}`, siteVersion)\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\n// FIXME: this middleware can be removed once we've upgraded the builder\n// to always provide the locale when dispatching resource actions\nfunction defaultLocaleMiddleware(\n defaultLocale: string | undefined,\n): ThunkMiddleware<State, UnknownAction> {\n return actionMiddleware(() => next => {\n return (action: Action) => {\n switch (action.type) {\n case ActionTypes.CHANGE_API_RESOURCE:\n case ActionTypes.EVICT_API_RESOURCE:\n case ActionTypes.SET_LOCALIZED_RESOURCE_ID: {\n const { locale } = action.payload\n return next({\n ...action,\n payload: { ...action.payload, locale: locale ?? defaultLocale },\n } as Action)\n }\n }\n\n return next(action)\n }\n })\n}\n\nexport function configureStore({\n defaultLocale,\n serializedState,\n}: {\n defaultLocale: string | undefined\n serializedState?: SerializedState\n}) {\n return configureReduxStore({\n reducer,\n preloadedState: {\n apiResources: APIResources.getInitialState(serializedState?.apiResources),\n localizedResourcesMap: LocalizedResourcesMap.getInitialState(\n serializedState?.localizedResourcesMap,\n ),\n },\n\n middleware: getDefaultMiddleware =>\n getDefaultMiddleware(middlewareOptions).concat(defaultLocaleMiddleware(defaultLocale)),\n\n devTools: devToolsConfig({\n name: `API client store (${new Date().toISOString()})`,\n actionsDenylist: [\n ActionTypes.BUILDER_POINTER_MOVE,\n ActionTypes.HANDLE_POINTER_MOVE,\n ActionTypes.ELEMENT_FROM_POINT_CHANGE,\n ],\n }),\n })\n}\n\nexport type Store = ReturnType<typeof configureStore>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAOO;AAEP,mBAA8B;AAC9B,4BAAuC;AACvC,qBAAuF;AACvF,IAAAA,kBAAoE;AAEpE,iBAWO;AACP,mBAAoC;AACpC,0BAAsE;A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AAY,CAAC;AAAA,MACnD,iBAAiB;AAAA,QACf,2BAAY;AAAA,QACZ,2BAAY;AAAA,QACZ,2BAAY;AAAA,MACd;AAAA,IACF,CAAC;AAAA,EACH,CAAC;AACH;","names":["import_toolkit","configureReduxStore"]}
|
|
1
|
+
{"version":3,"sources":["../../../src/state/makeswift-api-client.ts"],"sourcesContent":["import {\n configureStore as configureReduxStore,\n combineReducers,\n type ThunkAction,\n type ThunkMiddleware,\n type ThunkDispatch,\n UnknownAction,\n} from '@reduxjs/toolkit'\n\nimport * as APIResources from './modules/api-resources'\nimport * as LocalizedResourcesMap from './modules/localized-resources-map'\nimport { type Action, ActionTypes, apiResourceFulfilled, setLocalizedResourceId } from './actions'\nimport { actionMiddleware, middlewareOptions, devToolsConfig } from './toolkit'\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\nconst reducer = combineReducers({\n apiResources: APIResources.reducer,\n localizedResourcesMap: LocalizedResourcesMap.reducer,\n})\n\nexport type State = ReturnType<typeof reducer>\nexport type Dispatch = ThunkDispatch<State, unknown, Action>\nexport type HttpFetch = (url: string | URL, init?: RequestInit) => Promise<Response>\n\nexport type SerializedState = {\n apiResources: APIResources.SerializedState\n localizedResourcesMap: LocalizedResourcesMap.SerializedState\n}\n\nfunction getLocalizedResourceId(\n state: State,\n locale: string,\n resourceId: string,\n): string | undefined | null {\n return LocalizedResourcesMap.getLocalizedResourceId(\n state.localizedResourcesMap,\n locale,\n resourceId,\n )\n}\n\nexport function getHasAPIResource<T extends APIResourceType>(\n state: State,\n resourceType: APIResourceType,\n resourceId: string,\n locale?: APIResourceLocale<T>,\n): boolean {\n switch (resourceType) {\n case APIResourceType.LocalizedGlobalElement:\n if (locale == null) {\n console.error(`Attempt to access ${resourceType} ${resourceId} without a locale`)\n return false\n }\n\n const localizedId = getLocalizedResourceId(state, locale, resourceId)\n return (\n localizedId != null &&\n APIResources.getHasAPIResource(state.apiResources, resourceType, localizedId, locale)\n )\n\n default:\n return APIResources.getHasAPIResource(state.apiResources, resourceType, resourceId, locale)\n }\n}\n\nexport function getAPIResource<T extends APIResourceType>(\n state: State,\n resourceType: T,\n resourceId: string,\n locale?: APIResourceLocale<T>,\n): Extract<APIResource, { __typename: T }> | null {\n switch (resourceType) {\n case APIResourceType.LocalizedGlobalElement:\n if (locale == null) {\n console.error(`Attempt to access ${resourceType} ${resourceId} without a locale`)\n return null\n }\n\n const localizedId = getLocalizedResourceId(state, locale, resourceId)\n return localizedId != null\n ? APIResources.getAPIResource(state.apiResources, resourceType, localizedId, locale)\n : null\n\n default:\n return APIResources.getAPIResource(state.apiResources, resourceType, resourceId, locale)\n }\n}\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 fetchJson = async <T>(url: string): Promise<T | null> => {\n const response = await fetch(url, {\n headers: {\n 'Content-Type': 'application/json',\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\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 fetchJson<Swatch>(`/api/makeswift/swatches/${resourceId}`)\n break\n\n case APIResourceType.File:\n resource = await fetchJson<File>(`/api/makeswift/files/${resourceId}`)\n break\n\n case APIResourceType.Typography:\n resource = await fetchJson<Typography>(`/api/makeswift/typographies/${resourceId}`)\n break\n\n case APIResourceType.GlobalElement:\n resource = await fetchJson<GlobalElement>(`/api/makeswift/global-elements/${resourceId}`)\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 fetchJson<LocalizedGlobalElement>(\n `/api/makeswift/localized-global-elements/${resourceId}/${locale}`,\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 fetchJson<PagePathnameSlice>(url.pathname + url.search)\n break\n }\n\n case APIResourceType.Table:\n resource = await fetchJson<Table>(`/api/makeswift/tables/${resourceId}`)\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\n// FIXME: this middleware can be removed once we've upgraded the builder\n// to always provide the locale when dispatching resource actions\nfunction defaultLocaleMiddleware(\n defaultLocale: string | undefined,\n): ThunkMiddleware<State, UnknownAction> {\n return actionMiddleware(() => next => {\n return (action: Action) => {\n switch (action.type) {\n case ActionTypes.CHANGE_API_RESOURCE:\n case ActionTypes.EVICT_API_RESOURCE:\n case ActionTypes.SET_LOCALIZED_RESOURCE_ID: {\n const { locale } = action.payload\n return next({\n ...action,\n payload: { ...action.payload, locale: locale ?? defaultLocale },\n } as Action)\n }\n }\n\n return next(action)\n }\n })\n}\n\nexport function configureStore({\n defaultLocale,\n serializedState,\n}: {\n defaultLocale: string | undefined\n serializedState?: SerializedState\n}) {\n return configureReduxStore({\n reducer,\n preloadedState: {\n apiResources: APIResources.getInitialState(serializedState?.apiResources),\n localizedResourcesMap: LocalizedResourcesMap.getInitialState(\n serializedState?.localizedResourcesMap,\n ),\n },\n\n middleware: getDefaultMiddleware =>\n getDefaultMiddleware(middlewareOptions).concat(defaultLocaleMiddleware(defaultLocale)),\n\n devTools: devToolsConfig({\n name: `API client store (${new Date().toISOString()})`,\n actionsDenylist: [\n ActionTypes.BUILDER_POINTER_MOVE,\n ActionTypes.HANDLE_POINTER_MOVE,\n ActionTypes.ELEMENT_FROM_POINT_CHANGE,\n ],\n }),\n })\n}\n\nexport type Store = ReturnType<typeof configureStore>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAOO;AAEP,mBAA8B;AAC9B,4BAAuC;AACvC,qBAAuF;AACvF,IAAAA,kBAAoE;AAEpE,iBAWO;AAEP,MAAM,cAAU,gCAAgB;AAAA,EAC9B,cAAc,aAAa;AAAA,EAC3B,uBAAuB,sBAAsB;AAC/C,CAAC;AAWD,SAAS,uBACP,OACA,QACA,YAC2B;AAC3B,SAAO,sBAAsB;AAAA,IAC3B,MAAM;AAAA,IACN;AAAA,IACA;AAAA,EACF;AACF;AAEO,SAAS,kBACd,OACA,cACA,YACA,QACS;AACT,UAAQ,cAAc;AAAA,IACpB,KAAK,2BAAgB;AACnB,UAAI,UAAU,MAAM;AAClB,gBAAQ,MAAM,qBAAqB,YAAY,IAAI,UAAU,mBAAmB;AAChF,eAAO;AAAA,MACT;AAEA,YAAM,cAAc,uBAAuB,OAAO,QAAQ,UAAU;AACpE,aACE,eAAe,QACf,aAAa,kBAAkB,MAAM,cAAc,cAAc,aAAa,MAAM;AAAA,IAGxF;AACE,aAAO,aAAa,kBAAkB,MAAM,cAAc,cAAc,YAAY,MAAM;AAAA,EAC9F;AACF;AAEO,SAAS,eACd,OACA,cACA,YACA,QACgD;AAChD,UAAQ,cAAc;AAAA,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AO,KAAK,MAAM;AAAA,IACpB;AAAA,EACF,CAAC;AACH;AAEO,SAAS,eAAe;AAAA,EAC7B;AAAA,EACA;AACF,GAGG;AACD,aAAO,eAAAC,gBAAoB;AAAA,IACzB;AAAA,IACA,gBAAgB;AAAA,MACd,cAAc,aAAa,gBAAgB,iBAAiB,YAAY;AAAA,MACxE,uBAAuB,sBAAsB;AAAA,QAC3C,iBAAiB;AAAA,MACnB;AAAA,IACF;AAAA,IAEA,YAAY,0BACV,qBAAqB,iCAAiB,EAAE,OAAO,wBAAwB,aAAa,CAAC;AAAA,IAEvF,cAAU,gCAAe;AAAA,MACvB,MAAM,sBAAqB,oBAAI,KAAK,GAAE,YAAY,CAAC;AAAA,MACnD,iBAAiB;AAAA,QACf,2BAAY;AAAA,QACZ,2BAAY;AAAA,QACZ,2BAAY;AAAA,MACd;AAAA,IACF,CAAC;AAAA,EACH,CAAC;AACH;","names":["import_toolkit","configureReduxStore"]}
|
package/dist/esm/api/react.js
CHANGED
|
@@ -13,13 +13,13 @@ const CacheData = {
|
|
|
13
13
|
}
|
|
14
14
|
};
|
|
15
15
|
class MakeswiftHostApiClient {
|
|
16
|
-
siteVersion;
|
|
17
16
|
graphqlClient;
|
|
18
17
|
makeswiftApiClient;
|
|
19
18
|
subscribe;
|
|
19
|
+
fetch;
|
|
20
20
|
constructor({
|
|
21
21
|
uri,
|
|
22
|
-
|
|
22
|
+
fetch,
|
|
23
23
|
cacheData,
|
|
24
24
|
locale
|
|
25
25
|
}) {
|
|
@@ -28,7 +28,7 @@ class MakeswiftHostApiClient {
|
|
|
28
28
|
serializedState: cacheData,
|
|
29
29
|
defaultLocale: locale
|
|
30
30
|
});
|
|
31
|
-
this.
|
|
31
|
+
this.fetch = fetch;
|
|
32
32
|
this.subscribe = this.makeswiftApiClient.subscribe;
|
|
33
33
|
}
|
|
34
34
|
readSwatch(swatchId) {
|
|
@@ -40,7 +40,7 @@ class MakeswiftHostApiClient {
|
|
|
40
40
|
}
|
|
41
41
|
async fetchSwatch(swatchId) {
|
|
42
42
|
return await this.makeswiftApiClient.dispatch(
|
|
43
|
-
MakeswiftApiClient.fetchAPIResource(APIResourceType.Swatch, swatchId, this.
|
|
43
|
+
MakeswiftApiClient.fetchAPIResource(APIResourceType.Swatch, swatchId, this.fetch)
|
|
44
44
|
);
|
|
45
45
|
}
|
|
46
46
|
resolveSwatch(swatchId) {
|
|
@@ -59,7 +59,7 @@ class MakeswiftHostApiClient {
|
|
|
59
59
|
}
|
|
60
60
|
async fetchFile(fileId) {
|
|
61
61
|
return await this.makeswiftApiClient.dispatch(
|
|
62
|
-
MakeswiftApiClient.fetchAPIResource(APIResourceType.File, fileId, this.
|
|
62
|
+
MakeswiftApiClient.fetchAPIResource(APIResourceType.File, fileId, this.fetch)
|
|
63
63
|
);
|
|
64
64
|
}
|
|
65
65
|
resolveFile(fileId) {
|
|
@@ -78,11 +78,7 @@ class MakeswiftHostApiClient {
|
|
|
78
78
|
}
|
|
79
79
|
async fetchTypography(typographyId) {
|
|
80
80
|
return await this.makeswiftApiClient.dispatch(
|
|
81
|
-
MakeswiftApiClient.fetchAPIResource(
|
|
82
|
-
APIResourceType.Typography,
|
|
83
|
-
typographyId,
|
|
84
|
-
this.siteVersion
|
|
85
|
-
)
|
|
81
|
+
MakeswiftApiClient.fetchAPIResource(APIResourceType.Typography, typographyId, this.fetch)
|
|
86
82
|
);
|
|
87
83
|
}
|
|
88
84
|
resolveTypography(typographyId) {
|
|
@@ -104,7 +100,7 @@ class MakeswiftHostApiClient {
|
|
|
104
100
|
MakeswiftApiClient.fetchAPIResource(
|
|
105
101
|
APIResourceType.GlobalElement,
|
|
106
102
|
globalElementId,
|
|
107
|
-
this.
|
|
103
|
+
this.fetch
|
|
108
104
|
)
|
|
109
105
|
);
|
|
110
106
|
}
|
|
@@ -127,7 +123,7 @@ class MakeswiftHostApiClient {
|
|
|
127
123
|
MakeswiftApiClient.fetchAPIResource(
|
|
128
124
|
APIResourceType.LocalizedGlobalElement,
|
|
129
125
|
globalElementId,
|
|
130
|
-
this.
|
|
126
|
+
this.fetch,
|
|
131
127
|
locale
|
|
132
128
|
)
|
|
133
129
|
);
|
|
@@ -151,7 +147,7 @@ class MakeswiftHostApiClient {
|
|
|
151
147
|
MakeswiftApiClient.fetchAPIResource(
|
|
152
148
|
APIResourceType.PagePathnameSlice,
|
|
153
149
|
pageId,
|
|
154
|
-
this.
|
|
150
|
+
this.fetch,
|
|
155
151
|
locale
|
|
156
152
|
)
|
|
157
153
|
);
|
|
@@ -192,7 +188,7 @@ class MakeswiftHostApiClient {
|
|
|
192
188
|
}
|
|
193
189
|
async fetchTable(tableId) {
|
|
194
190
|
return await this.makeswiftApiClient.dispatch(
|
|
195
|
-
MakeswiftApiClient.fetchAPIResource(APIResourceType.Table, tableId, this.
|
|
191
|
+
MakeswiftApiClient.fetchAPIResource(APIResourceType.Table, tableId, this.fetch)
|
|
196
192
|
);
|
|
197
193
|
}
|
|
198
194
|
async createTableRecord(tableId, columns) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/api/react.ts"],"sourcesContent":["import { type FetchableValue } from '@makeswift/controls'\nimport * as MakeswiftApiClient from '../state/makeswift-api-client'\nimport {\n APIResourceType,\n File,\n GlobalElement,\n LocalizedGlobalElement,\n Page,\n PagePathnameSlice,\n Site,\n Snippet,\n Swatch,\n Table,\n Typography,\n} from './types'\nimport { GraphQLClient } from './graphql/client'\nimport { CreateTableRecordMutation } from './graphql/documents'\nimport {\n CreateTableRecordMutationResult,\n CreateTableRecordMutationVariables,\n} from './graphql/generated/types'\nimport { MakeswiftSiteVersion } from './site-version'\n\nexport type CacheData = MakeswiftApiClient.SerializedState\n\nexport const CacheData = {\n empty(): CacheData {\n return {\n apiResources: {},\n localizedResourcesMap: {},\n }\n },\n}\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 MakeswiftHostApiClient {\n siteVersion: MakeswiftSiteVersion\n graphqlClient: GraphQLClient\n makeswiftApiClient: MakeswiftApiClient.Store\n subscribe: MakeswiftApiClient.Store['subscribe']\n\n constructor({\n uri,\n siteVersion,\n cacheData,\n locale,\n }: {\n uri: string\n siteVersion: MakeswiftSiteVersion\n cacheData?: CacheData\n locale?: string\n }) {\n this.graphqlClient = new GraphQLClient(uri)\n this.makeswiftApiClient = MakeswiftApiClient.configureStore({\n serializedState: cacheData,\n defaultLocale: locale,\n })\n this.siteVersion = siteVersion\n this.subscribe = this.makeswiftApiClient.subscribe\n }\n\n readSwatch(swatchId: string): Swatch | null {\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.Swatch,\n swatchId,\n )\n }\n\n async fetchSwatch(swatchId: string): Promise<Swatch | null> {\n return await this.makeswiftApiClient.dispatch(\n MakeswiftApiClient.fetchAPIResource(APIResourceType.Swatch, swatchId, this.siteVersion),\n )\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 readFile(fileId: string): File | null {\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.File,\n fileId,\n )\n }\n\n async fetchFile(fileId: string): Promise<File | null> {\n return await this.makeswiftApiClient.dispatch(\n MakeswiftApiClient.fetchAPIResource(APIResourceType.File, fileId, this.siteVersion),\n )\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 readTypography(typographyId: string): Typography | null {\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.Typography,\n typographyId,\n )\n }\n\n async fetchTypography(typographyId: string): Promise<Typography | null> {\n return await this.makeswiftApiClient.dispatch(\n MakeswiftApiClient.fetchAPIResource(\n APIResourceType.Typography,\n typographyId,\n this.siteVersion,\n ),\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 readGlobalElement(globalElementId: string): GlobalElement | null {\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.GlobalElement,\n globalElementId,\n )\n }\n\n async fetchGlobalElement(globalElementId: string): Promise<GlobalElement | null> {\n return await this.makeswiftApiClient.dispatch(\n MakeswiftApiClient.fetchAPIResource(\n APIResourceType.GlobalElement,\n globalElementId,\n this.siteVersion,\n ),\n )\n }\n\n readLocalizedGlobalElement({\n globalElementId,\n locale,\n }: {\n globalElementId: string\n locale: string\n }): LocalizedGlobalElement | null {\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.LocalizedGlobalElement,\n globalElementId,\n locale,\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.makeswiftApiClient.dispatch(\n MakeswiftApiClient.fetchAPIResource(\n APIResourceType.LocalizedGlobalElement,\n globalElementId,\n this.siteVersion,\n locale,\n ),\n )\n }\n\n readPagePathnameSlice({\n pageId,\n locale,\n }: {\n pageId: string\n locale: string | null\n }): PagePathnameSlice | null {\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.PagePathnameSlice,\n pageId,\n 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.makeswiftApiClient.dispatch(\n MakeswiftApiClient.fetchAPIResource(\n APIResourceType.PagePathnameSlice,\n pageId,\n this.siteVersion,\n locale,\n ),\n )\n }\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 readTable(tableId: string): Table | null {\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.Table,\n tableId,\n )\n }\n\n async fetchTable(tableId: string): Promise<Table | null> {\n return await this.makeswiftApiClient.dispatch(\n MakeswiftApiClient.fetchAPIResource(APIResourceType.Table, tableId, this.siteVersion),\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 readSite(siteId: string): Site | null {\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.Site,\n siteId,\n )\n }\n\n readPage(pageId: string): Page | null {\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.Page,\n pageId,\n )\n }\n\n readSnippet(snippetId: string): Snippet | null {\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.Snippet,\n snippetId,\n )\n }\n}\n"],"mappings":"AACA,YAAY,wBAAwB;AACpC;AAAA,EACE;AAAA,OAWK;AACP,SAAS,qBAAqB;AAC9B,SAAS,iCAAiC;AASnC,MAAM,YAAY;AAAA,EACvB,QAAmB;AACjB,WAAO;AAAA,MACL,cAAc,CAAC;AAAA,MACf,uBAAuB,CAAC;AAAA,IAC1B;AAAA,EACF;AACF;AAqBO,MAAM,uBAAuB;AAAA,EAClC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA,YAAY;AAAA,IACV;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,GAKG;AACD,SAAK,gBAAgB,IAAI,cAAc,GAAG;AAC1C,SAAK,qBAAqB,mBAAmB,eAAe;AAAA,MAC1D,iBAAiB;AAAA,MACjB,eAAe;AAAA,IACjB,CAAC;AACD,SAAK,cAAc;AACnB,SAAK,YAAY,KAAK,mBAAmB;AAAA,EAC3C;AAAA,EAEA,WAAW,UAAiC;AAC1C,WAAO,mBAAmB;AAAA,MACxB,KAAK,mBAAmB,SAAS;AAAA,MACjC,gBAAgB;AAAA,MAChB;AAAA,IACF;AAAA,EACF;AAAA,EAEA,MAAM,YAAY,UAA0C;AAC1D,WAAO,MAAM,KAAK,mBAAmB;AAAA,MACnC,mBAAmB,iBAAiB,gBAAgB,QAAQ,UAAU,KAAK,WAAW;AA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IACF;AAAA,EACF;AAAA,EAEA,YAAY,WAAmC;AAC7C,WAAO,mBAAmB;AAAA,MACxB,KAAK,mBAAmB,SAAS;AAAA,MACjC,gBAAgB;AAAA,MAChB;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../src/api/react.ts"],"sourcesContent":["import { type FetchableValue } from '@makeswift/controls'\nimport * as MakeswiftApiClient from '../state/makeswift-api-client'\nimport {\n APIResourceType,\n File,\n GlobalElement,\n LocalizedGlobalElement,\n Page,\n PagePathnameSlice,\n Site,\n Snippet,\n Swatch,\n Table,\n Typography,\n} from './types'\nimport { GraphQLClient } from './graphql/client'\nimport { CreateTableRecordMutation } from './graphql/documents'\nimport {\n CreateTableRecordMutationResult,\n CreateTableRecordMutationVariables,\n} from './graphql/generated/types'\n\nexport type CacheData = MakeswiftApiClient.SerializedState\n\nexport const CacheData = {\n empty(): CacheData {\n return {\n apiResources: {},\n localizedResourcesMap: {},\n }\n },\n}\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 MakeswiftHostApiClient {\n graphqlClient: GraphQLClient\n makeswiftApiClient: MakeswiftApiClient.Store\n subscribe: MakeswiftApiClient.Store['subscribe']\n fetch: MakeswiftApiClient.HttpFetch\n\n constructor({\n uri,\n fetch,\n cacheData,\n locale,\n }: {\n uri: string\n fetch: MakeswiftApiClient.HttpFetch\n cacheData?: CacheData\n locale?: string\n }) {\n this.graphqlClient = new GraphQLClient(uri)\n this.makeswiftApiClient = MakeswiftApiClient.configureStore({\n serializedState: cacheData,\n defaultLocale: locale,\n })\n this.fetch = fetch\n this.subscribe = this.makeswiftApiClient.subscribe\n }\n\n readSwatch(swatchId: string): Swatch | null {\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.Swatch,\n swatchId,\n )\n }\n\n async fetchSwatch(swatchId: string): Promise<Swatch | null> {\n return await this.makeswiftApiClient.dispatch(\n MakeswiftApiClient.fetchAPIResource(APIResourceType.Swatch, swatchId, this.fetch),\n )\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 readFile(fileId: string): File | null {\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.File,\n fileId,\n )\n }\n\n async fetchFile(fileId: string): Promise<File | null> {\n return await this.makeswiftApiClient.dispatch(\n MakeswiftApiClient.fetchAPIResource(APIResourceType.File, fileId, this.fetch),\n )\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 readTypography(typographyId: string): Typography | null {\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.Typography,\n typographyId,\n )\n }\n\n async fetchTypography(typographyId: string): Promise<Typography | null> {\n return await this.makeswiftApiClient.dispatch(\n MakeswiftApiClient.fetchAPIResource(APIResourceType.Typography, typographyId, this.fetch),\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 readGlobalElement(globalElementId: string): GlobalElement | null {\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.GlobalElement,\n globalElementId,\n )\n }\n\n async fetchGlobalElement(globalElementId: string): Promise<GlobalElement | null> {\n return await this.makeswiftApiClient.dispatch(\n MakeswiftApiClient.fetchAPIResource(\n APIResourceType.GlobalElement,\n globalElementId,\n this.fetch,\n ),\n )\n }\n\n readLocalizedGlobalElement({\n globalElementId,\n locale,\n }: {\n globalElementId: string\n locale: string\n }): LocalizedGlobalElement | null {\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.LocalizedGlobalElement,\n globalElementId,\n locale,\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.makeswiftApiClient.dispatch(\n MakeswiftApiClient.fetchAPIResource(\n APIResourceType.LocalizedGlobalElement,\n globalElementId,\n this.fetch,\n locale,\n ),\n )\n }\n\n readPagePathnameSlice({\n pageId,\n locale,\n }: {\n pageId: string\n locale: string | null\n }): PagePathnameSlice | null {\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.PagePathnameSlice,\n pageId,\n 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.makeswiftApiClient.dispatch(\n MakeswiftApiClient.fetchAPIResource(\n APIResourceType.PagePathnameSlice,\n pageId,\n this.fetch,\n locale,\n ),\n )\n }\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 readTable(tableId: string): Table | null {\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.Table,\n tableId,\n )\n }\n\n async fetchTable(tableId: string): Promise<Table | null> {\n return await this.makeswiftApiClient.dispatch(\n MakeswiftApiClient.fetchAPIResource(APIResourceType.Table, tableId, this.fetch),\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 readSite(siteId: string): Site | null {\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.Site,\n siteId,\n )\n }\n\n readPage(pageId: string): Page | null {\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.Page,\n pageId,\n )\n }\n\n readSnippet(snippetId: string): Snippet | null {\n return MakeswiftApiClient.getAPIResource(\n this.makeswiftApiClient.getState(),\n APIResourceType.Snippet,\n snippetId,\n )\n }\n}\n"],"mappings":"AACA,YAAY,wBAAwB;AACpC;AAAA,EACE;AAAA,OAWK;AACP,SAAS,qBAAqB;AAC9B,SAAS,iCAAiC;AAQnC,MAAM,YAAY;AAAA,EAC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F;AAAA,EAEA,UAAU,SAA+B;AACvC,WAAO,mBAAmB;AAAA,MACxB,KAAK,mBAAmB,SAAS;AAAA,MACjC,gBAAgB;AAAA,MAChB;AAAA,IACF;AAAA,EACF;AAAA,EAEA,MAAM,WAAW,SAAwC;AACvD,WAAO,MAAM,KAAK,mBAAmB;AAAA,MACnC,mBAAmB,iBAAiB,gBAAgB,OAAO,SAAS,KAAK,KAAK;AAAA,IAChF;AAAA,EACF;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,SAAS,QAA6B;AACpC,WAAO,mBAAmB;AAAA,MACxB,KAAK,mBAAmB,SAAS;AAAA,MACjC,gBAAgB;AAAA,MAChB;AAAA,IACF;AAAA,EACF;AAAA,EAEA,SAAS,QAA6B;AACpC,WAAO,mBAAmB;AAAA,MACxB,KAAK,mBAAmB,SAAS;AAAA,MACjC,gBAAgB;AAAA,MAChB;AAAA,IACF;AAAA,EACF;AAAA,EAEA,YAAY,WAAmC;AAC7C,WAAO,mBAAmB;AAAA,MACxB,KAAK,mBAAmB,SAAS;AAAA,MACjC,gBAAgB;AAAA,MAChB;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
|
@@ -8,7 +8,7 @@ async function manifestHandler(req, { apiKey, manifest }) {
|
|
|
8
8
|
return ApiResponse.json({ message: "Unauthorized" }, { status: 401 });
|
|
9
9
|
}
|
|
10
10
|
return ApiResponse.json({
|
|
11
|
-
version: "0.25.0-canary.
|
|
11
|
+
version: "0.25.0-canary.13",
|
|
12
12
|
previewMode: false,
|
|
13
13
|
draftMode: false,
|
|
14
14
|
interactionMode: true,
|
|
@@ -3,7 +3,11 @@ import { jsx } from "react/jsx-runtime";
|
|
|
3
3
|
import { useMemo } from "react";
|
|
4
4
|
import NextImage from "next/image";
|
|
5
5
|
import { useIsPagesRouter } from "../../hooks/use-is-pages-router";
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
FrameworkContext,
|
|
8
|
+
versionedFetch
|
|
9
|
+
} from "../../../runtimes/react/components/framework-context";
|
|
10
|
+
import { MAKESWIFT_CACHE_TAG } from "../../cache";
|
|
7
11
|
import { context as appRouterContext } from "./app-router";
|
|
8
12
|
import { context as pagesRouterContext } from "./pages-router";
|
|
9
13
|
import { Link } from "./link";
|
|
@@ -16,7 +20,8 @@ function FrameworkProvider({
|
|
|
16
20
|
() => ({
|
|
17
21
|
...isPagesRouter ? pagesRouterContext : appRouterContext,
|
|
18
22
|
Image: NextImage,
|
|
19
|
-
Link
|
|
23
|
+
Link,
|
|
24
|
+
versionedFetch: (siteVersion) => (url, init) => versionedFetch(siteVersion)(url, { ...init, next: { tags: [MAKESWIFT_CACHE_TAG] } })
|
|
20
25
|
}),
|
|
21
26
|
[isPagesRouter]
|
|
22
27
|
);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/next/components/framework-provider/index.tsx"],"sourcesContent":["'use client'\n\nimport { type PropsWithChildren, useMemo } from 'react'\nimport NextImage from 'next/image'\n\nimport { useIsPagesRouter } from '../../hooks/use-is-pages-router'\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../../../src/next/components/framework-provider/index.tsx"],"sourcesContent":["'use client'\n\nimport { type PropsWithChildren, useMemo } from 'react'\nimport NextImage from 'next/image'\n\nimport { useIsPagesRouter } from '../../hooks/use-is-pages-router'\nimport {\n FrameworkContext,\n versionedFetch,\n} from '../../../runtimes/react/components/framework-context'\n\nimport { MakeswiftSiteVersion } from '../../../api/site-version'\nimport { MAKESWIFT_CACHE_TAG } from '../../cache'\n\nimport { context as appRouterContext } from './app-router'\nimport { context as pagesRouterContext } from './pages-router'\nimport { Link } from './link'\n\nexport function FrameworkProvider({\n children,\n forcePagesRouter,\n}: PropsWithChildren<{ forcePagesRouter?: boolean }>) {\n const isPagesRouter = useIsPagesRouter() || forcePagesRouter\n const context = useMemo<FrameworkContext>(\n () => ({\n ...(isPagesRouter ? pagesRouterContext : appRouterContext),\n Image: NextImage,\n Link,\n versionedFetch: (siteVersion: MakeswiftSiteVersion) => (url, init) =>\n versionedFetch(siteVersion)(url, { ...init, next: { tags: [MAKESWIFT_CACHE_TAG] } }),\n }),\n [isPagesRouter],\n )\n\n return <FrameworkContext.Provider value={context}>{children}</FrameworkContext.Provider>\n}\n"],"mappings":";AAkCS;AAhCT,SAAiC,eAAe;AAChD,OAAO,eAAe;AAEtB,SAAS,wBAAwB;AACjC;AAAA,EACE;AAAA,EACA;AAAA,OACK;AAGP,SAAS,2BAA2B;AAEpC,SAAS,WAAW,wBAAwB;AAC5C,SAAS,WAAW,0BAA0B;AAC9C,SAAS,YAAY;AAEd,SAAS,kBAAkB;AAAA,EAChC;AAAA,EACA;AACF,GAAsD;AACpD,QAAM,gBAAgB,iBAAiB,KAAK;AAC5C,QAAM,UAAU;AAAA,IACd,OAAO;AAAA,MACL,GAAI,gBAAgB,qBAAqB;AAAA,MACzC,OAAO;AAAA,MACP;AAAA,MACA,gBAAgB,CAAC,gBAAsC,CAAC,KAAK,SAC3D,eAAe,WAAW,EAAE,KAAK,EAAE,GAAG,MAAM,MAAM,EAAE,MAAM,CAAC,mBAAmB,EAAE,EAAE,CAAC;AAAA,IACvF;AAAA,IACA,CAAC,aAAa;AAAA,EAChB;AAEA,SAAO,oBAAC,iBAAiB,UAAjB,EAA0B,OAAO,SAAU,UAAS;AAC9D;","names":[]}
|
|
@@ -7,6 +7,7 @@ import { MakeswiftHostApiClientProvider } from "../host-api-client";
|
|
|
7
7
|
import { MakeswiftSiteVersion } from "../../../api/site-version";
|
|
8
8
|
import { DraftSwitcher } from "./draft-switcher/draft-switcher";
|
|
9
9
|
import { useBuilderConnectionPing } from "./hooks/use-builder-connection-ping";
|
|
10
|
+
import { useFrameworkContext } from "./hooks/use-framework-context";
|
|
10
11
|
const LiveProvider = lazy(() => import("./LiveProvider"));
|
|
11
12
|
const PreviewProvider = lazy(() => import("./PreviewProvider"));
|
|
12
13
|
function RuntimeProvider({
|
|
@@ -17,13 +18,16 @@ function RuntimeProvider({
|
|
|
17
18
|
apiOrigin = "https://api.makeswift.com",
|
|
18
19
|
locale = void 0
|
|
19
20
|
}) {
|
|
21
|
+
const { versionedFetch } = useFrameworkContext();
|
|
20
22
|
const client = useMemo(
|
|
21
23
|
() => new MakeswiftHostApiClient({
|
|
22
24
|
uri: new URL("graphql", apiOrigin).href,
|
|
23
25
|
locale,
|
|
24
|
-
|
|
26
|
+
fetch: versionedFetch(
|
|
27
|
+
previewMode ? MakeswiftSiteVersion.Working : MakeswiftSiteVersion.Live
|
|
28
|
+
)
|
|
25
29
|
}),
|
|
26
|
-
[apiOrigin, locale, previewMode]
|
|
30
|
+
[apiOrigin, locale, previewMode, versionedFetch]
|
|
27
31
|
);
|
|
28
32
|
const StoreProvider = previewMode ? PreviewProvider : LiveProvider;
|
|
29
33
|
useBuilderConnectionPing({ appOrigin });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/runtimes/react/components/RuntimeProvider.tsx"],"sourcesContent":["'use client'\n\nimport { ReactNode, useMemo, lazy } from 'react'\n\nimport { MakeswiftHostApiClient } from '../../../api/react'\nimport { ReactRuntimeContext } from '../hooks/use-react-runtime'\nimport { ReactRuntime } from '../react-runtime'\nimport { MakeswiftHostApiClientProvider } from '../host-api-client'\nimport { MakeswiftSiteVersion } from '../../../api/site-version'\nimport { DraftSwitcher } from './draft-switcher/draft-switcher'\nimport { useBuilderConnectionPing } from './hooks/use-builder-connection-ping'\n\nconst LiveProvider = lazy(() => import('./LiveProvider'))\nconst PreviewProvider = lazy(() => import('./PreviewProvider'))\n\nexport function RuntimeProvider({\n children,\n runtime,\n previewMode,\n appOrigin = 'https://app.makeswift.com',\n apiOrigin = 'https://api.makeswift.com',\n locale = undefined,\n}: {\n children: ReactNode\n runtime: ReactRuntime\n previewMode: boolean\n apiOrigin?: string\n appOrigin?: string\n locale?: string\n}) {\n const client = useMemo(\n () =>\n new MakeswiftHostApiClient({\n uri: new URL('graphql', apiOrigin).href,\n locale,\n
|
|
1
|
+
{"version":3,"sources":["../../../../../src/runtimes/react/components/RuntimeProvider.tsx"],"sourcesContent":["'use client'\n\nimport { ReactNode, useMemo, lazy } from 'react'\n\nimport { MakeswiftHostApiClient } from '../../../api/react'\nimport { ReactRuntimeContext } from '../hooks/use-react-runtime'\nimport { ReactRuntime } from '../react-runtime'\nimport { MakeswiftHostApiClientProvider } from '../host-api-client'\nimport { MakeswiftSiteVersion } from '../../../api/site-version'\nimport { DraftSwitcher } from './draft-switcher/draft-switcher'\nimport { useBuilderConnectionPing } from './hooks/use-builder-connection-ping'\nimport { useFrameworkContext } from './hooks/use-framework-context'\n\nconst LiveProvider = lazy(() => import('./LiveProvider'))\nconst PreviewProvider = lazy(() => import('./PreviewProvider'))\n\nexport function RuntimeProvider({\n children,\n runtime,\n previewMode,\n appOrigin = 'https://app.makeswift.com',\n apiOrigin = 'https://api.makeswift.com',\n locale = undefined,\n}: {\n children: ReactNode\n runtime: ReactRuntime\n previewMode: boolean\n apiOrigin?: string\n appOrigin?: string\n locale?: string\n}) {\n const { versionedFetch } = useFrameworkContext()\n\n const client = useMemo(\n () =>\n new MakeswiftHostApiClient({\n uri: new URL('graphql', apiOrigin).href,\n locale,\n fetch: versionedFetch(\n previewMode ? MakeswiftSiteVersion.Working : MakeswiftSiteVersion.Live,\n ),\n }),\n [apiOrigin, locale, previewMode, versionedFetch],\n )\n\n const StoreProvider = previewMode ? PreviewProvider : LiveProvider\n\n useBuilderConnectionPing({ appOrigin })\n\n return (\n <ReactRuntimeContext.Provider value={runtime}>\n <MakeswiftHostApiClientProvider client={client}>\n <StoreProvider>\n {children}\n <DraftSwitcher isDraft={previewMode} />\n </StoreProvider>\n </MakeswiftHostApiClientProvider>\n </ReactRuntimeContext.Provider>\n )\n}\n"],"mappings":";AAoDQ,SAEE,KAFF;AAlDR,SAAoB,SAAS,YAAY;AAEzC,SAAS,8BAA8B;AACvC,SAAS,2BAA2B;AAEpC,SAAS,sCAAsC;AAC/C,SAAS,4BAA4B;AACrC,SAAS,qBAAqB;AAC9B,SAAS,gCAAgC;AACzC,SAAS,2BAA2B;AAEpC,MAAM,eAAe,KAAK,MAAM,OAAO,gBAAgB,CAAC;AACxD,MAAM,kBAAkB,KAAK,MAAM,OAAO,mBAAmB,CAAC;AAEvD,SAAS,gBAAgB;AAAA,EAC9B;AAAA,EACA;AAAA,EACA;AAAA,EACA,YAAY;AAAA,EACZ,YAAY;AAAA,EACZ,SAAS;AACX,GAOG;AACD,QAAM,EAAE,eAAe,IAAI,oBAAoB;AAE/C,QAAM,SAAS;AAAA,IACb,MACE,IAAI,uBAAuB;AAAA,MACzB,KAAK,IAAI,IAAI,WAAW,SAAS,EAAE;AAAA,MACnC;AAAA,MACA,OAAO;AAAA,QACL,cAAc,qBAAqB,UAAU,qBAAqB;AAAA,MACpE;AAAA,IACF,CAAC;AAAA,IACH,CAAC,WAAW,QAAQ,aAAa,cAAc;AAAA,EACjD;AAEA,QAAM,gBAAgB,cAAc,kBAAkB;AAEtD,2BAAyB,EAAE,UAAU,CAAC;AAEtC,SACE,oBAAC,oBAAoB,UAApB,EAA6B,OAAO,SACnC,8BAAC,kCAA+B,QAC9B,+BAAC,iBACE;AAAA;AAAA,IACD,oBAAC,iBAAc,SAAS,aAAa;AAAA,KACvC,GACF,GACF;AAEJ;","names":[]}
|
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
createContext,
|
|
4
4
|
forwardRef
|
|
5
5
|
} from "react";
|
|
6
|
+
import { API_HANDLER_SITE_VERSION_HEADER } from "../../../api/site-version";
|
|
6
7
|
import { BaseHeadSnippet } from "./page/HeadSnippet";
|
|
7
8
|
const DefaultHead = ({ children }) => /* @__PURE__ */ jsx(Fragment, { children });
|
|
8
9
|
const DefaultImage = ({ priority, fill, style, ...props }) => /* @__PURE__ */ jsx(
|
|
@@ -23,16 +24,25 @@ const DefaultImage = ({ priority, fill, style, ...props }) => /* @__PURE__ */ js
|
|
|
23
24
|
const DefaultLink = forwardRef(
|
|
24
25
|
({ linkType, ...props }, ref) => /* @__PURE__ */ jsx("a", { ...props, ref })
|
|
25
26
|
);
|
|
27
|
+
const versionedFetch = (siteVersion) => (url, init) => fetch(url, {
|
|
28
|
+
...init,
|
|
29
|
+
headers: {
|
|
30
|
+
...init?.headers,
|
|
31
|
+
[API_HANDLER_SITE_VERSION_HEADER]: siteVersion
|
|
32
|
+
}
|
|
33
|
+
});
|
|
26
34
|
const FrameworkContext = createContext({
|
|
27
35
|
Head: DefaultHead,
|
|
28
36
|
HeadSnippet: BaseHeadSnippet,
|
|
29
37
|
Image: DefaultImage,
|
|
30
|
-
Link: DefaultLink
|
|
38
|
+
Link: DefaultLink,
|
|
39
|
+
versionedFetch
|
|
31
40
|
});
|
|
32
41
|
export {
|
|
33
42
|
DefaultHead,
|
|
34
43
|
DefaultImage,
|
|
35
44
|
DefaultLink,
|
|
36
|
-
FrameworkContext
|
|
45
|
+
FrameworkContext,
|
|
46
|
+
versionedFetch
|
|
37
47
|
};
|
|
38
48
|
//# sourceMappingURL=framework-context.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/runtimes/react/components/framework-context.tsx"],"sourcesContent":["import {\n createContext,\n type ReactNode,\n type PropsWithChildren,\n type CSSProperties,\n type ComponentPropsWithoutRef,\n type MouseEvent,\n type ForwardRefExoticComponent,\n type RefAttributes,\n forwardRef,\n} from 'react'\n\nimport { type LinkData } from '@makeswift/prop-controllers'\n\nimport { type Snippet } from '../../../client'\n\nimport { BaseHeadSnippet } from './page/HeadSnippet'\n\ntype HeadComponent = (props: { children: ReactNode }) => ReactNode\ntype HeadSnippet = (props: { snippet: Snippet }) => ReactNode\ntype ImageComponent = (props: {\n src: string\n alt: string\n sizes?: string\n width?: number\n height?: number\n priority?: boolean\n fill?: boolean\n style?: CSSProperties\n}) => ReactNode\n\ntype LinkProps = Omit<ComponentPropsWithoutRef<'a'>, 'onClick'> & {\n linkType?: LinkData['type']\n onClick?: (event: MouseEvent<HTMLAnchorElement>) => unknown\n}\n\ntype LinkComponent = ForwardRefExoticComponent<RefAttributes<HTMLAnchorElement> & LinkProps>\n\nexport type FrameworkContext = {\n Head: HeadComponent\n HeadSnippet: HeadSnippet\n Image: ImageComponent\n Link: LinkComponent\n}\n\n// React 19 automatically hoists metadata tags to the <head>\nexport const DefaultHead = ({ children }: PropsWithChildren) => <>{children}</>\n\nexport const DefaultImage: ImageComponent = ({ priority, fill, style, ...props }) => (\n <img\n {...props}\n style={{\n ...(fill\n ? {\n height: '100%',\n width: '100%',\n objectFit: 'cover',\n }\n : {}),\n ...style,\n }}\n loading={priority ? 'eager' : 'lazy'}\n />\n)\n\nexport const DefaultLink: LinkComponent = forwardRef<HTMLAnchorElement, LinkProps>(\n ({ linkType, ...props }, ref) => <a {...props} ref={ref} />,\n)\n\nexport const FrameworkContext = createContext<FrameworkContext>({\n Head: DefaultHead,\n HeadSnippet: BaseHeadSnippet,\n Image: DefaultImage,\n Link: DefaultLink,\n})\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../../../src/runtimes/react/components/framework-context.tsx"],"sourcesContent":["import {\n createContext,\n type ReactNode,\n type PropsWithChildren,\n type CSSProperties,\n type ComponentPropsWithoutRef,\n type MouseEvent,\n type ForwardRefExoticComponent,\n type RefAttributes,\n forwardRef,\n} from 'react'\n\nimport { type LinkData } from '@makeswift/prop-controllers'\n\nimport { type Snippet } from '../../../client'\nimport { type HttpFetch } from '../../../state/makeswift-api-client'\nimport { API_HANDLER_SITE_VERSION_HEADER, MakeswiftSiteVersion } from '../../../api/site-version'\n\nimport { BaseHeadSnippet } from './page/HeadSnippet'\n\ntype HeadComponent = (props: { children: ReactNode }) => ReactNode\ntype HeadSnippet = (props: { snippet: Snippet }) => ReactNode\ntype ImageComponent = (props: {\n src: string\n alt: string\n sizes?: string\n width?: number\n height?: number\n priority?: boolean\n fill?: boolean\n style?: CSSProperties\n}) => ReactNode\n\ntype LinkProps = Omit<ComponentPropsWithoutRef<'a'>, 'onClick'> & {\n linkType?: LinkData['type']\n onClick?: (event: MouseEvent<HTMLAnchorElement>) => unknown\n}\n\ntype LinkComponent = ForwardRefExoticComponent<RefAttributes<HTMLAnchorElement> & LinkProps>\n\nexport type FrameworkContext = {\n Head: HeadComponent\n HeadSnippet: HeadSnippet\n Image: ImageComponent\n Link: LinkComponent\n versionedFetch: (siteVersion: MakeswiftSiteVersion) => HttpFetch\n}\n\n// React 19 automatically hoists metadata tags to the <head>\nexport const DefaultHead = ({ children }: PropsWithChildren) => <>{children}</>\n\nexport const DefaultImage: ImageComponent = ({ priority, fill, style, ...props }) => (\n <img\n {...props}\n style={{\n ...(fill\n ? {\n height: '100%',\n width: '100%',\n objectFit: 'cover',\n }\n : {}),\n ...style,\n }}\n loading={priority ? 'eager' : 'lazy'}\n />\n)\n\nexport const DefaultLink: LinkComponent = forwardRef<HTMLAnchorElement, LinkProps>(\n ({ linkType, ...props }, ref) => <a {...props} ref={ref} />,\n)\n\nexport const versionedFetch: FrameworkContext['versionedFetch'] = siteVersion => (url, init) =>\n fetch(url, {\n ...init,\n headers: {\n ...init?.headers,\n [API_HANDLER_SITE_VERSION_HEADER]: siteVersion,\n },\n })\n\nexport const FrameworkContext = createContext<FrameworkContext>({\n Head: DefaultHead,\n HeadSnippet: BaseHeadSnippet,\n Image: DefaultImage,\n Link: DefaultLink,\n versionedFetch,\n})\n"],"mappings":"AAiDgE;AAjDhE;AAAA,EACE;AAAA,EAQA;AAAA,OACK;AAMP,SAAS,uCAA6D;AAEtE,SAAS,uBAAuB;AA+BzB,MAAM,cAAc,CAAC,EAAE,SAAS,MAAyB,gCAAG,UAAS;AAErE,MAAM,eAA+B,CAAC,EAAE,UAAU,MAAM,OAAO,GAAG,MAAM,MAC7E;AAAA,EAAC;AAAA;AAAA,IACE,GAAG;AAAA,IACJ,OAAO;AAAA,MACL,GAAI,OACA;AAAA,QACE,QAAQ;AAAA,QACR,OAAO;AAAA,QACP,WAAW;AAAA,MACb,IACA,CAAC;AAAA,MACL,GAAG;AAAA,IACL;AAAA,IACA,SAAS,WAAW,UAAU;AAAA;AAChC;AAGK,MAAM,cAA6B;AAAA,EACxC,CAAC,EAAE,UAAU,GAAG,MAAM,GAAG,QAAQ,oBAAC,OAAG,GAAG,OAAO,KAAU;AAC3D;AAEO,MAAM,iBAAqD,iBAAe,CAAC,KAAK,SACrF,MAAM,KAAK;AAAA,EACT,GAAG;AAAA,EACH,SAAS;AAAA,IACP,GAAG,MAAM;AAAA,IACT,CAAC,+BAA+B,GAAG;AAAA,EACrC;AACF,CAAC;AAEI,MAAM,mBAAmB,cAAgC;AAAA,EAC9D,MAAM;AAAA,EACN,aAAa;AAAA,EACb,OAAO;AAAA,EACP,MAAM;AAAA,EACN;AACF,CAAC;","names":[]}
|
|
@@ -2,11 +2,16 @@
|
|
|
2
2
|
import { jsx } from "react/jsx-runtime";
|
|
3
3
|
import { createContext, useContext } from "react";
|
|
4
4
|
import { MakeswiftHostApiClient } from "../../api/react";
|
|
5
|
-
import { MakeswiftSiteVersion } from "../../api/site-version";
|
|
6
5
|
const Context = createContext(
|
|
7
6
|
new MakeswiftHostApiClient({
|
|
8
7
|
uri: "https://api.makeswift.com/graphql",
|
|
9
|
-
|
|
8
|
+
fetch: async (url, init) => {
|
|
9
|
+
console.warn(
|
|
10
|
+
"Using fallback `fetch` implementation, resource revalidation may not work as expected.",
|
|
11
|
+
{ url }
|
|
12
|
+
);
|
|
13
|
+
return fetch(url, init);
|
|
14
|
+
}
|
|
10
15
|
})
|
|
11
16
|
);
|
|
12
17
|
function useMakeswiftHostApiClient() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/runtimes/react/host-api-client.tsx"],"sourcesContent":["'use client'\n\nimport { ReactNode, createContext, useContext } from 'react'\nimport { MakeswiftHostApiClient } from '../../api/react'\
|
|
1
|
+
{"version":3,"sources":["../../../../src/runtimes/react/host-api-client.tsx"],"sourcesContent":["'use client'\n\nimport { ReactNode, createContext, useContext } from 'react'\nimport { MakeswiftHostApiClient } from '../../api/react'\n\nconst Context = createContext(\n new MakeswiftHostApiClient({\n uri: 'https://api.makeswift.com/graphql',\n fetch: async (url, init) => {\n console.warn(\n 'Using fallback `fetch` implementation, resource revalidation may not work as expected.',\n { url },\n )\n return fetch(url, init)\n },\n }),\n)\n\nexport function useMakeswiftHostApiClient(): MakeswiftHostApiClient {\n return useContext(Context)\n}\n\nexport function MakeswiftHostApiClientProvider({\n client,\n children,\n}: {\n client: MakeswiftHostApiClient\n children: ReactNode\n}) {\n return <Context.Provider value={client}>{children}</Context.Provider>\n}\n"],"mappings":";AA6BS;AA3BT,SAAoB,eAAe,kBAAkB;AACrD,SAAS,8BAA8B;AAEvC,MAAM,UAAU;AAAA,EACd,IAAI,uBAAuB;AAAA,IACzB,KAAK;AAAA,IACL,OAAO,OAAO,KAAK,SAAS;AAC1B,cAAQ;AAAA,QACN;AAAA,QACA,EAAE,IAAI;AAAA,MACR;AACA,aAAO,MAAM,KAAK,IAAI;AAAA,IACxB;AAAA,EACF,CAAC;AACH;AAEO,SAAS,4BAAoD;AAClE,SAAO,WAAW,OAAO;AAC3B;AAEO,SAAS,+BAA+B;AAAA,EAC7C;AAAA,EACA;AACF,GAGG;AACD,SAAO,oBAAC,QAAQ,UAAR,EAAiB,OAAO,QAAS,UAAS;AACpD;","names":[]}
|
|
@@ -9,8 +9,6 @@ import { actionMiddleware, middlewareOptions, devToolsConfig } from "./toolkit";
|
|
|
9
9
|
import {
|
|
10
10
|
APIResourceType
|
|
11
11
|
} from "../api";
|
|
12
|
-
import { MAKESWIFT_CACHE_TAG } from "../next/cache";
|
|
13
|
-
import { API_HANDLER_SITE_VERSION_HEADER } from "../api/site-version";
|
|
14
12
|
const reducer = combineReducers({
|
|
15
13
|
apiResources: APIResources.reducer,
|
|
16
14
|
localizedResourcesMap: LocalizedResourcesMap.reducer
|
|
@@ -48,26 +46,24 @@ function getAPIResource(state, resourceType, resourceId, locale) {
|
|
|
48
46
|
return APIResources.getAPIResource(state.apiResources, resourceType, resourceId, locale);
|
|
49
47
|
}
|
|
50
48
|
}
|
|
51
|
-
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}
|
|
70
|
-
function fetchAPIResource(resourceType, resourceId, siteVersion, locale) {
|
|
49
|
+
function fetchAPIResource(resourceType, resourceId, fetch, locale) {
|
|
50
|
+
const fetchJson = async (url) => {
|
|
51
|
+
const response = await fetch(url, {
|
|
52
|
+
headers: {
|
|
53
|
+
"Content-Type": "application/json"
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
if (response.status === 404)
|
|
57
|
+
return null;
|
|
58
|
+
if (!response.ok)
|
|
59
|
+
throw new Error(response.statusText);
|
|
60
|
+
if (response.headers.get("content-type")?.includes("application/json") !== true) {
|
|
61
|
+
throw new Error(
|
|
62
|
+
`Expected JSON response from "${url}" but got "${response.headers.get("content-type")}"`
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
return response.json();
|
|
66
|
+
};
|
|
71
67
|
return async (dispatch, getState) => {
|
|
72
68
|
const state = getState();
|
|
73
69
|
if (getHasAPIResource(state, resourceType, resourceId, locale)) {
|
|
@@ -76,22 +72,16 @@ function fetchAPIResource(resourceType, resourceId, siteVersion, locale) {
|
|
|
76
72
|
let resource;
|
|
77
73
|
switch (resourceType) {
|
|
78
74
|
case APIResourceType.Swatch:
|
|
79
|
-
resource = await fetchJson(`/api/makeswift/swatches/${resourceId}
|
|
75
|
+
resource = await fetchJson(`/api/makeswift/swatches/${resourceId}`);
|
|
80
76
|
break;
|
|
81
77
|
case APIResourceType.File:
|
|
82
|
-
resource = await fetchJson(`/api/makeswift/files/${resourceId}
|
|
78
|
+
resource = await fetchJson(`/api/makeswift/files/${resourceId}`);
|
|
83
79
|
break;
|
|
84
80
|
case APIResourceType.Typography:
|
|
85
|
-
resource = await fetchJson(
|
|
86
|
-
`/api/makeswift/typographies/${resourceId}`,
|
|
87
|
-
siteVersion
|
|
88
|
-
);
|
|
81
|
+
resource = await fetchJson(`/api/makeswift/typographies/${resourceId}`);
|
|
89
82
|
break;
|
|
90
83
|
case APIResourceType.GlobalElement:
|
|
91
|
-
resource = await fetchJson(
|
|
92
|
-
`/api/makeswift/global-elements/${resourceId}`,
|
|
93
|
-
siteVersion
|
|
94
|
-
);
|
|
84
|
+
resource = await fetchJson(`/api/makeswift/global-elements/${resourceId}`);
|
|
95
85
|
break;
|
|
96
86
|
case APIResourceType.LocalizedGlobalElement: {
|
|
97
87
|
if (locale == null)
|
|
@@ -100,8 +90,7 @@ function fetchAPIResource(resourceType, resourceId, siteVersion, locale) {
|
|
|
100
90
|
return null;
|
|
101
91
|
}
|
|
102
92
|
resource = await fetchJson(
|
|
103
|
-
`/api/makeswift/localized-global-elements/${resourceId}/${locale}
|
|
104
|
-
siteVersion
|
|
93
|
+
`/api/makeswift/localized-global-elements/${resourceId}/${locale}`
|
|
105
94
|
);
|
|
106
95
|
dispatch(
|
|
107
96
|
setLocalizedResourceId({
|
|
@@ -116,11 +105,11 @@ function fetchAPIResource(resourceType, resourceId, siteVersion, locale) {
|
|
|
116
105
|
const url = new URL(`/api/makeswift/page-pathname-slices/${resourceId}`, "http://n");
|
|
117
106
|
if (locale != null)
|
|
118
107
|
url.searchParams.set("locale", locale);
|
|
119
|
-
resource = await fetchJson(url.pathname + url.search
|
|
108
|
+
resource = await fetchJson(url.pathname + url.search);
|
|
120
109
|
break;
|
|
121
110
|
}
|
|
122
111
|
case APIResourceType.Table:
|
|
123
|
-
resource = await fetchJson(`/api/makeswift/tables/${resourceId}
|
|
112
|
+
resource = await fetchJson(`/api/makeswift/tables/${resourceId}`);
|
|
124
113
|
break;
|
|
125
114
|
default:
|
|
126
115
|
resource = null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/state/makeswift-api-client.ts"],"sourcesContent":["import {\n configureStore as configureReduxStore,\n combineReducers,\n type ThunkAction,\n type ThunkMiddleware,\n type ThunkDispatch,\n UnknownAction,\n} from '@reduxjs/toolkit'\n\nimport * as APIResources from './modules/api-resources'\nimport * as LocalizedResourcesMap from './modules/localized-resources-map'\nimport { type Action, ActionTypes, apiResourceFulfilled, setLocalizedResourceId } from './actions'\nimport { actionMiddleware, middlewareOptions, devToolsConfig } from './toolkit'\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'\nimport { MAKESWIFT_CACHE_TAG } from '../next/cache'\nimport { API_HANDLER_SITE_VERSION_HEADER, MakeswiftSiteVersion } from '../api/site-version'\n\nconst reducer = combineReducers({\n apiResources: APIResources.reducer,\n localizedResourcesMap: LocalizedResourcesMap.reducer,\n})\n\nexport type State = ReturnType<typeof reducer>\nexport type Dispatch = ThunkDispatch<State, unknown, Action>\n\nexport type SerializedState = {\n apiResources: APIResources.SerializedState\n localizedResourcesMap: LocalizedResourcesMap.SerializedState\n}\n\nfunction getLocalizedResourceId(\n state: State,\n locale: string,\n resourceId: string,\n): string | undefined | null {\n return LocalizedResourcesMap.getLocalizedResourceId(\n state.localizedResourcesMap,\n locale,\n resourceId,\n )\n}\n\nexport function getHasAPIResource<T extends APIResourceType>(\n state: State,\n resourceType: APIResourceType,\n resourceId: string,\n locale?: APIResourceLocale<T>,\n): boolean {\n switch (resourceType) {\n case APIResourceType.LocalizedGlobalElement:\n if (locale == null) {\n console.error(`Attempt to access ${resourceType} ${resourceId} without a locale`)\n return false\n }\n\n const localizedId = getLocalizedResourceId(state, locale, resourceId)\n return (\n localizedId != null &&\n APIResources.getHasAPIResource(state.apiResources, resourceType, localizedId, locale)\n )\n\n default:\n return APIResources.getHasAPIResource(state.apiResources, resourceType, resourceId, locale)\n }\n}\n\nexport function getAPIResource<T extends APIResourceType>(\n state: State,\n resourceType: T,\n resourceId: string,\n locale?: APIResourceLocale<T>,\n): Extract<APIResource, { __typename: T }> | null {\n switch (resourceType) {\n case APIResourceType.LocalizedGlobalElement:\n if (locale == null) {\n console.error(`Attempt to access ${resourceType} ${resourceId} without a locale`)\n return null\n }\n\n const localizedId = getLocalizedResourceId(state, locale, resourceId)\n return localizedId != null\n ? APIResources.getAPIResource(state.apiResources, resourceType, localizedId, locale)\n : null\n\n default:\n return APIResources.getAPIResource(state.apiResources, resourceType, resourceId, locale)\n }\n}\n\ntype Thunk<ReturnType> = ThunkAction<ReturnType, State, unknown, Action>\n\nasync function fetchJson<T>(url: string, siteVersion: MakeswiftSiteVersion): Promise<T | null> {\n const response = await fetch(url, {\n headers: {\n 'Content-Type': 'application/json',\n [API_HANDLER_SITE_VERSION_HEADER]: siteVersion,\n },\n next: { tags: [MAKESWIFT_CACHE_TAG] },\n })\n\n if (response.status === 404) return null\n\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\nexport function fetchAPIResource<T extends APIResourceType>(\n resourceType: T,\n resourceId: string,\n siteVersion: MakeswiftSiteVersion,\n locale?: APIResourceLocale<T>,\n): Thunk<Promise<Extract<APIResource, { __typename: T }> | null>> {\n return async (dispatch, getState) => {\n const state = getState()\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 fetchJson<Swatch>(`/api/makeswift/swatches/${resourceId}`, siteVersion)\n break\n\n case APIResourceType.File:\n resource = await fetchJson<File>(`/api/makeswift/files/${resourceId}`, siteVersion)\n break\n\n case APIResourceType.Typography:\n resource = await fetchJson<Typography>(\n `/api/makeswift/typographies/${resourceId}`,\n siteVersion,\n )\n break\n\n case APIResourceType.GlobalElement:\n resource = await fetchJson<GlobalElement>(\n `/api/makeswift/global-elements/${resourceId}`,\n siteVersion,\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 fetchJson<LocalizedGlobalElement>(\n `/api/makeswift/localized-global-elements/${resourceId}/${locale}`,\n siteVersion,\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 fetchJson<PagePathnameSlice>(url.pathname + url.search, siteVersion)\n break\n }\n\n case APIResourceType.Table:\n resource = await fetchJson<Table>(`/api/makeswift/tables/${resourceId}`, siteVersion)\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\n// FIXME: this middleware can be removed once we've upgraded the builder\n// to always provide the locale when dispatching resource actions\nfunction defaultLocaleMiddleware(\n defaultLocale: string | undefined,\n): ThunkMiddleware<State, UnknownAction> {\n return actionMiddleware(() => next => {\n return (action: Action) => {\n switch (action.type) {\n case ActionTypes.CHANGE_API_RESOURCE:\n case ActionTypes.EVICT_API_RESOURCE:\n case ActionTypes.SET_LOCALIZED_RESOURCE_ID: {\n const { locale } = action.payload\n return next({\n ...action,\n payload: { ...action.payload, locale: locale ?? defaultLocale },\n } as Action)\n }\n }\n\n return next(action)\n }\n })\n}\n\nexport function configureStore({\n defaultLocale,\n serializedState,\n}: {\n defaultLocale: string | undefined\n serializedState?: SerializedState\n}) {\n return configureReduxStore({\n reducer,\n preloadedState: {\n apiResources: APIResources.getInitialState(serializedState?.apiResources),\n localizedResourcesMap: LocalizedResourcesMap.getInitialState(\n serializedState?.localizedResourcesMap,\n ),\n },\n\n middleware: getDefaultMiddleware =>\n getDefaultMiddleware(middlewareOptions).concat(defaultLocaleMiddleware(defaultLocale)),\n\n devTools: devToolsConfig({\n name: `API client store (${new Date().toISOString()})`,\n actionsDenylist: [\n ActionTypes.BUILDER_POINTER_MOVE,\n ActionTypes.HANDLE_POINTER_MOVE,\n ActionTypes.ELEMENT_FROM_POINT_CHANGE,\n ],\n }),\n })\n}\n\nexport type Store = ReturnType<typeof configureStore>\n"],"mappings":"AAAA;AAAA,EACE,kBAAkB;AAAA,EAClB;AAAA,OAKK;AAEP,YAAY,kBAAkB;AAC9B,YAAY,2BAA2B;AACvC,SAAsB,aAAa,sBAAsB,8BAA8B;AACvF,SAAS,kBAAkB,mBAAmB,sBAAsB;AAEpE;AAAA,EACE;AAAA,OAUK;AACP,SAAS,2BAA2B;AACpC,SAAS,uCAA6D;AAEtE,MAAM,UAAU,gBAAgB;AAAA,EAC9B,cAAc,aAAa;AAAA,EAC3B,uBAAuB,sBAAsB;AAC/C,CAAC;AAUD,SAAS,uBACP,OACA,QACA,YAC2B;AAC3B,SAAO,sBAAsB;AAAA,IAC3B,MAAM;AAAA,IACN;AAAA,IACA;AAAA,EACF;AACF;AAEO,SAAS,kBACd,OACA,cACA,YACA,QACS;AACT,UAAQ,cAAc;AAAA,IACpB,KAAK,gBAAgB;AACnB,UAAI,UAAU,MAAM;AAClB,gBAAQ,MAAM,qBAAqB,YAAY,IAAI,UAAU,mBAAmB;AAChF,eAA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Y,UAAU,MAAM,CAAC;AAEzE,WAAO;AAAA,EACT;AACF;AAIA,SAAS,wBACP,eACuC;AACvC,SAAO,iBAAiB,MAAM,UAAQ;AACpC,WAAO,CAAC,WAAmB;AACzB,cAAQ,OAAO,MAAM;AAAA,QACnB,KAAK,YAAY;AAAA,QACjB,KAAK,YAAY;AAAA,QACjB,KAAK,YAAY,2BAA2B;AAC1C,gBAAM,EAAE,OAAO,IAAI,OAAO;AAC1B,iBAAO,KAAK;AAAA,YACV,GAAG;AAAA,YACH,SAAS,EAAE,GAAG,OAAO,SAAS,QAAQ,UAAU,cAAc;AAAA,UAChE,CAAW;AAAA,QACb;AAAA,MACF;AAEA,aAAO,KAAK,MAAM;AAAA,IACpB;AAAA,EACF,CAAC;AACH;AAEO,SAAS,eAAe;AAAA,EAC7B;AAAA,EACA;AACF,GAGG;AACD,SAAO,oBAAoB;AAAA,IACzB;AAAA,IACA,gBAAgB;AAAA,MACd,cAAc,aAAa,gBAAgB,iBAAiB,YAAY;AAAA,MACxE,uBAAuB,sBAAsB;AAAA,QAC3C,iBAAiB;AAAA,MACnB;AAAA,IACF;AAAA,IAEA,YAAY,0BACV,qBAAqB,iBAAiB,EAAE,OAAO,wBAAwB,aAAa,CAAC;AAAA,IAEvF,UAAU,eAAe;AAAA,MACvB,MAAM,sBAAqB,oBAAI,KAAK,GAAE,YAAY,CAAC;AAAA,MACnD,iBAAiB;AAAA,QACf,YAAY;AAAA,QACZ,YAAY;AAAA,QACZ,YAAY;AAAA,MACd;AAAA,IACF,CAAC;AAAA,EACH,CAAC;AACH;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../../src/state/makeswift-api-client.ts"],"sourcesContent":["import {\n configureStore as configureReduxStore,\n combineReducers,\n type ThunkAction,\n type ThunkMiddleware,\n type ThunkDispatch,\n UnknownAction,\n} from '@reduxjs/toolkit'\n\nimport * as APIResources from './modules/api-resources'\nimport * as LocalizedResourcesMap from './modules/localized-resources-map'\nimport { type Action, ActionTypes, apiResourceFulfilled, setLocalizedResourceId } from './actions'\nimport { actionMiddleware, middlewareOptions, devToolsConfig } from './toolkit'\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\nconst reducer = combineReducers({\n apiResources: APIResources.reducer,\n localizedResourcesMap: LocalizedResourcesMap.reducer,\n})\n\nexport type State = ReturnType<typeof reducer>\nexport type Dispatch = ThunkDispatch<State, unknown, Action>\nexport type HttpFetch = (url: string | URL, init?: RequestInit) => Promise<Response>\n\nexport type SerializedState = {\n apiResources: APIResources.SerializedState\n localizedResourcesMap: LocalizedResourcesMap.SerializedState\n}\n\nfunction getLocalizedResourceId(\n state: State,\n locale: string,\n resourceId: string,\n): string | undefined | null {\n return LocalizedResourcesMap.getLocalizedResourceId(\n state.localizedResourcesMap,\n locale,\n resourceId,\n )\n}\n\nexport function getHasAPIResource<T extends APIResourceType>(\n state: State,\n resourceType: APIResourceType,\n resourceId: string,\n locale?: APIResourceLocale<T>,\n): boolean {\n switch (resourceType) {\n case APIResourceType.LocalizedGlobalElement:\n if (locale == null) {\n console.error(`Attempt to access ${resourceType} ${resourceId} without a locale`)\n return false\n }\n\n const localizedId = getLocalizedResourceId(state, locale, resourceId)\n return (\n localizedId != null &&\n APIResources.getHasAPIResource(state.apiResources, resourceType, localizedId, locale)\n )\n\n default:\n return APIResources.getHasAPIResource(state.apiResources, resourceType, resourceId, locale)\n }\n}\n\nexport function getAPIResource<T extends APIResourceType>(\n state: State,\n resourceType: T,\n resourceId: string,\n locale?: APIResourceLocale<T>,\n): Extract<APIResource, { __typename: T }> | null {\n switch (resourceType) {\n case APIResourceType.LocalizedGlobalElement:\n if (locale == null) {\n console.error(`Attempt to access ${resourceType} ${resourceId} without a locale`)\n return null\n }\n\n const localizedId = getLocalizedResourceId(state, locale, resourceId)\n return localizedId != null\n ? APIResources.getAPIResource(state.apiResources, resourceType, localizedId, locale)\n : null\n\n default:\n return APIResources.getAPIResource(state.apiResources, resourceType, resourceId, locale)\n }\n}\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 fetchJson = async <T>(url: string): Promise<T | null> => {\n const response = await fetch(url, {\n headers: {\n 'Content-Type': 'application/json',\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\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 fetchJson<Swatch>(`/api/makeswift/swatches/${resourceId}`)\n break\n\n case APIResourceType.File:\n resource = await fetchJson<File>(`/api/makeswift/files/${resourceId}`)\n break\n\n case APIResourceType.Typography:\n resource = await fetchJson<Typography>(`/api/makeswift/typographies/${resourceId}`)\n break\n\n case APIResourceType.GlobalElement:\n resource = await fetchJson<GlobalElement>(`/api/makeswift/global-elements/${resourceId}`)\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 fetchJson<LocalizedGlobalElement>(\n `/api/makeswift/localized-global-elements/${resourceId}/${locale}`,\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 fetchJson<PagePathnameSlice>(url.pathname + url.search)\n break\n }\n\n case APIResourceType.Table:\n resource = await fetchJson<Table>(`/api/makeswift/tables/${resourceId}`)\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\n// FIXME: this middleware can be removed once we've upgraded the builder\n// to always provide the locale when dispatching resource actions\nfunction defaultLocaleMiddleware(\n defaultLocale: string | undefined,\n): ThunkMiddleware<State, UnknownAction> {\n return actionMiddleware(() => next => {\n return (action: Action) => {\n switch (action.type) {\n case ActionTypes.CHANGE_API_RESOURCE:\n case ActionTypes.EVICT_API_RESOURCE:\n case ActionTypes.SET_LOCALIZED_RESOURCE_ID: {\n const { locale } = action.payload\n return next({\n ...action,\n payload: { ...action.payload, locale: locale ?? defaultLocale },\n } as Action)\n }\n }\n\n return next(action)\n }\n })\n}\n\nexport function configureStore({\n defaultLocale,\n serializedState,\n}: {\n defaultLocale: string | undefined\n serializedState?: SerializedState\n}) {\n return configureReduxStore({\n reducer,\n preloadedState: {\n apiResources: APIResources.getInitialState(serializedState?.apiResources),\n localizedResourcesMap: LocalizedResourcesMap.getInitialState(\n serializedState?.localizedResourcesMap,\n ),\n },\n\n middleware: getDefaultMiddleware =>\n getDefaultMiddleware(middlewareOptions).concat(defaultLocaleMiddleware(defaultLocale)),\n\n devTools: devToolsConfig({\n name: `API client store (${new Date().toISOString()})`,\n actionsDenylist: [\n ActionTypes.BUILDER_POINTER_MOVE,\n ActionTypes.HANDLE_POINTER_MOVE,\n ActionTypes.ELEMENT_FROM_POINT_CHANGE,\n ],\n }),\n })\n}\n\nexport type Store = ReturnType<typeof configureStore>\n"],"mappings":"AAAA;AAA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BAAI,KAAK,GAAE,YAAY,CAAC;AAAA,MACnD,iBAAiB;AAAA,QACf,YAAY;AAAA,QACZ,YAAY;AAAA,QACZ,YAAY;AAAA,MACd;AAAA,IACF,CAAC;AAAA,EACH,CAAC;AACH;","names":[]}
|
|
@@ -2,7 +2,6 @@ import { type FetchableValue } from '@makeswift/controls';
|
|
|
2
2
|
import * as MakeswiftApiClient from '../state/makeswift-api-client';
|
|
3
3
|
import { APIResourceType, File, GlobalElement, LocalizedGlobalElement, Page, PagePathnameSlice, Site, Snippet, Swatch, Table, Typography } from './types';
|
|
4
4
|
import { GraphQLClient } from './graphql/client';
|
|
5
|
-
import { MakeswiftSiteVersion } from './site-version';
|
|
6
5
|
export type CacheData = MakeswiftApiClient.SerializedState;
|
|
7
6
|
export declare const CacheData: {
|
|
8
7
|
empty(): CacheData;
|
|
@@ -27,13 +26,13 @@ export declare const CacheData: {
|
|
|
27
26
|
* snapshot for use in the builder, not the lives pages.
|
|
28
27
|
*/
|
|
29
28
|
export declare class MakeswiftHostApiClient {
|
|
30
|
-
siteVersion: MakeswiftSiteVersion;
|
|
31
29
|
graphqlClient: GraphQLClient;
|
|
32
30
|
makeswiftApiClient: MakeswiftApiClient.Store;
|
|
33
31
|
subscribe: MakeswiftApiClient.Store['subscribe'];
|
|
34
|
-
|
|
32
|
+
fetch: MakeswiftApiClient.HttpFetch;
|
|
33
|
+
constructor({ uri, fetch, cacheData, locale, }: {
|
|
35
34
|
uri: string;
|
|
36
|
-
|
|
35
|
+
fetch: MakeswiftApiClient.HttpFetch;
|
|
37
36
|
cacheData?: CacheData;
|
|
38
37
|
locale?: string;
|
|
39
38
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react.d.ts","sourceRoot":"","sources":["../../../src/api/react.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,qBAAqB,CAAA;AACzD,OAAO,KAAK,kBAAkB,MAAM,+BAA+B,CAAA;AACnE,OA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ources":["../../../../../src/next/components/framework-provider/index.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,iBAAiB,EAAW,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/next/components/framework-provider/index.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,iBAAiB,EAAW,MAAM,OAAO,CAAA;AAgBvD,wBAAgB,iBAAiB,CAAC,EAChC,QAAQ,EACR,gBAAgB,GACjB,EAAE,iBAAiB,CAAC;IAAE,gBAAgB,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC,2CAcnD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RuntimeProvider.d.ts","sourceRoot":"","sources":["../../../../../src/runtimes/react/components/RuntimeProvider.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAiB,MAAM,OAAO,CAAA;AAIhD,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;
|
|
1
|
+
{"version":3,"file":"RuntimeProvider.d.ts","sourceRoot":"","sources":["../../../../../src/runtimes/react/components/RuntimeProvider.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAiB,MAAM,OAAO,CAAA;AAIhD,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAU/C,wBAAgB,eAAe,CAAC,EAC9B,QAAQ,EACR,OAAO,EACP,WAAW,EACX,SAAuC,EACvC,SAAuC,EACvC,MAAkB,GACnB,EAAE;IACD,QAAQ,EAAE,SAAS,CAAA;IACnB,OAAO,EAAE,YAAY,CAAA;IACrB,WAAW,EAAE,OAAO,CAAA;IACpB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB,2CA6BA"}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { type ReactNode, type PropsWithChildren, type CSSProperties, type ComponentPropsWithoutRef, type MouseEvent, type ForwardRefExoticComponent, type RefAttributes } from 'react';
|
|
2
2
|
import { type LinkData } from '@makeswift/prop-controllers';
|
|
3
3
|
import { type Snippet } from '../../../client';
|
|
4
|
+
import { type HttpFetch } from '../../../state/makeswift-api-client';
|
|
5
|
+
import { MakeswiftSiteVersion } from '../../../api/site-version';
|
|
4
6
|
type HeadComponent = (props: {
|
|
5
7
|
children: ReactNode;
|
|
6
8
|
}) => ReactNode;
|
|
@@ -27,10 +29,12 @@ export type FrameworkContext = {
|
|
|
27
29
|
HeadSnippet: HeadSnippet;
|
|
28
30
|
Image: ImageComponent;
|
|
29
31
|
Link: LinkComponent;
|
|
32
|
+
versionedFetch: (siteVersion: MakeswiftSiteVersion) => HttpFetch;
|
|
30
33
|
};
|
|
31
34
|
export declare const DefaultHead: ({ children }: PropsWithChildren) => import("react/jsx-runtime").JSX.Element;
|
|
32
35
|
export declare const DefaultImage: ImageComponent;
|
|
33
36
|
export declare const DefaultLink: LinkComponent;
|
|
37
|
+
export declare const versionedFetch: FrameworkContext['versionedFetch'];
|
|
34
38
|
export declare const FrameworkContext: import("react").Context<FrameworkContext>;
|
|
35
39
|
export {};
|
|
36
40
|
//# sourceMappingURL=framework-context.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"framework-context.d.ts","sourceRoot":"","sources":["../../../../../src/runtimes/react/components/framework-context.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,SAAS,EACd,KAAK,iBAAiB,EACtB,KAAK,aAAa,EAClB,KAAK,wBAAwB,EAC7B,KAAK,UAAU,EACf,KAAK,yBAAyB,EAC9B,KAAK,aAAa,EAEnB,MAAM,OAAO,CAAA;AAEd,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,6BAA6B,CAAA;AAE3D,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,iBAAiB,CAAA;
|
|
1
|
+
{"version":3,"file":"framework-context.d.ts","sourceRoot":"","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AAK,aAAa,GAAG,yBAAyB,CAAC,aAAa,CAAC,iBAAiB,CAAC,GAAG,SAAS,CAAC,CAAA;AAE5F,MAAM,MAAM,gBAAgB,GAAG;IAC7B,IAAI,EAAE,aAAa,CAAA;IACnB,WAAW,EAAE,WAAW,CAAA;IACxB,KAAK,EAAE,cAAc,CAAA;IACrB,IAAI,EAAE,aAAa,CAAA;IACnB,cAAc,EAAE,CAAC,WAAW,EAAE,oBAAoB,KAAK,SAAS,CAAA;CACjE,CAAA;AAGD,eAAO,MAAM,WAAW,GAAI,cAAc,iBAAiB,4CAAoB,CAAA;AAE/E,eAAO,MAAM,YAAY,EAAE,cAe1B,CAAA;AAED,eAAO,MAAM,WAAW,EAAE,aAEzB,CAAA;AAED,eAAO,MAAM,cAAc,EAAE,gBAAgB,CAAC,gBAAgB,CAO1D,CAAA;AAEJ,eAAO,MAAM,gBAAgB,2CAM3B,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"host-api-client.d.ts","sourceRoot":"","sources":["../../../../src/runtimes/react/host-api-client.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAA6B,MAAM,OAAO,CAAA;AAC5D,OAAO,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAA;
|
|
1
|
+
{"version":3,"file":"host-api-client.d.ts","sourceRoot":"","sources":["../../../../src/runtimes/react/host-api-client.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAA6B,MAAM,OAAO,CAAA;AAC5D,OAAO,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAA;AAexD,wBAAgB,yBAAyB,IAAI,sBAAsB,CAElE;AAED,wBAAgB,8BAA8B,CAAC,EAC7C,MAAM,EACN,QAAQ,GACT,EAAE;IACD,MAAM,EAAE,sBAAsB,CAAA;IAC9B,QAAQ,EAAE,SAAS,CAAA;CACpB,2CAEA"}
|
|
@@ -3,7 +3,6 @@ import * as APIResources from './modules/api-resources';
|
|
|
3
3
|
import * as LocalizedResourcesMap from './modules/localized-resources-map';
|
|
4
4
|
import { type Action } from './actions';
|
|
5
5
|
import { APIResourceType, type APIResource, type APIResourceLocale } from '../api';
|
|
6
|
-
import { MakeswiftSiteVersion } from '../api/site-version';
|
|
7
6
|
declare const reducer: import("@reduxjs/toolkit").Reducer<{
|
|
8
7
|
apiResources: APIResources.State;
|
|
9
8
|
localizedResourcesMap: Map<string, Map<string, string | null>>;
|
|
@@ -13,6 +12,7 @@ declare const reducer: import("@reduxjs/toolkit").Reducer<{
|
|
|
13
12
|
}>>;
|
|
14
13
|
export type State = ReturnType<typeof reducer>;
|
|
15
14
|
export type Dispatch = ThunkDispatch<State, unknown, Action>;
|
|
15
|
+
export type HttpFetch = (url: string | URL, init?: RequestInit) => Promise<Response>;
|
|
16
16
|
export type SerializedState = {
|
|
17
17
|
apiResources: APIResources.SerializedState;
|
|
18
18
|
localizedResourcesMap: LocalizedResourcesMap.SerializedState;
|
|
@@ -22,7 +22,7 @@ export declare function getAPIResource<T extends APIResourceType>(state: State,
|
|
|
22
22
|
__typename: T;
|
|
23
23
|
}> | null;
|
|
24
24
|
type Thunk<ReturnType> = ThunkAction<ReturnType, State, unknown, Action>;
|
|
25
|
-
export declare function fetchAPIResource<T extends APIResourceType>(resourceType: T, resourceId: string,
|
|
25
|
+
export declare function fetchAPIResource<T extends APIResourceType>(resourceType: T, resourceId: string, fetch: HttpFetch, locale?: APIResourceLocale<T>): Thunk<Promise<Extract<APIResource, {
|
|
26
26
|
__typename: T;
|
|
27
27
|
}> | null>>;
|
|
28
28
|
export declare function configureStore({ defaultLocale, serializedState, }: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"makeswift-api-client.d.ts","sourceRoot":"","sources":["../../../src/state/makeswift-api-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,WAAW,EAEhB,KAAK,aAAa,EAClB,aAAa,EACd,MAAM,kBAAkB,CAAA;AAEzB,OAAO,KAAK,YAAY,MA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CAAC,EAAE,iBAAiB,CAAC,CAAC,CAAC,GAC5B,OAAO,CAiBT;AAED,wBAAgB,cAAc,CAAC,CAAC,SAAS,eAAe,EACtD,KAAK,EAAE,KAAK,EACZ,YAAY,EAAE,CAAC,EACf,UAAU,EAAE,MAAM,EAClB,MAAM,CAAC,EAAE,iBAAiB,CAAC,CAAC,CAAC,GAC5B,OAAO,CAAC,WAAW,EAAE;IAAE,UAAU,EAAE,CAAC,CAAA;CAAE,CAAC,GAAG,IAAI,CAgBhD;AAED,KAAK,KAAK,CAAC,UAAU,IAAI,WAAW,CAAC,UAAU,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,CAAC,CAAA;AAExE,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,eAAe,EACxD,YAAY,EAAE,CAAC,EACf,UAAU,EAAE,MAAM,EAClB,KAAK,EAAE,SAAS,EAChB,MAAM,CAAC,EAAE,iBAAiB,CAAC,CAAC,CAAC,GAC5B,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,WAAW,EAAE;IAAE,UAAU,EAAE,CAAC,CAAA;CAAE,CAAC,GAAG,IAAI,CAAC,CAAC,CA2FhE;AA0BD,wBAAgB,cAAc,CAAC,EAC7B,aAAa,EACb,eAAe,GAChB,EAAE;IACD,aAAa,EAAE,MAAM,GAAG,SAAS,CAAA;IACjC,eAAe,CAAC,EAAE,eAAe,CAAA;CAClC;;;;;;;;gDAsBA;AAED,MAAM,MAAM,KAAK,GAAG,UAAU,CAAC,OAAO,cAAc,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@makeswift/runtime",
|
|
3
|
-
"version": "0.25.0-canary.
|
|
3
|
+
"version": "0.25.0-canary.13",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
@@ -171,9 +171,9 @@
|
|
|
171
171
|
"use-sync-external-store": "^1.0.0-rc.0",
|
|
172
172
|
"uuid": "^9.0.0",
|
|
173
173
|
"zod": "^3.21.4",
|
|
174
|
+
"@makeswift/controls": "0.1.12",
|
|
174
175
|
"@makeswift/next-plugin": "0.4.1",
|
|
175
|
-
"@makeswift/prop-controllers": "0.4.6-canary.2"
|
|
176
|
-
"@makeswift/controls": "0.1.12"
|
|
176
|
+
"@makeswift/prop-controllers": "0.4.6-canary.2"
|
|
177
177
|
},
|
|
178
178
|
"devDependencies": {
|
|
179
179
|
"@emotion/jest": "^11.11.0",
|