@makeswift/runtime 0.28.7-canary.2 → 0.28.7-canary.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/api/api-resources-client.js +160 -0
- package/dist/cjs/api/api-resources-client.js.map +1 -0
- package/dist/cjs/api/client.js +20 -190
- package/dist/cjs/api/client.js.map +1 -1
- package/dist/cjs/api/graphql-api-client.js +39 -0
- package/dist/cjs/api/graphql-api-client.js.map +1 -0
- package/dist/cjs/api-handler/handlers/manifest.js +1 -1
- package/dist/cjs/client/index.js +3 -3
- package/dist/cjs/components/builtin/Form/Form.js +2 -2
- package/dist/cjs/components/builtin/Form/Form.js.map +1 -1
- package/dist/cjs/controls/index.js +2 -2
- package/dist/cjs/controls/index.js.map +1 -1
- package/dist/cjs/next/fetch.js.map +1 -1
- package/dist/cjs/runtimes/react/components/GoogleFontLink.js +2 -2
- package/dist/cjs/runtimes/react/components/GoogleFontLink.js.map +1 -1
- package/dist/cjs/runtimes/react/components/hooks/use-page-snippets.js +2 -2
- package/dist/cjs/runtimes/react/components/hooks/use-page-snippets.js.map +1 -1
- package/dist/cjs/runtimes/react/components/page/PageHead.js +2 -2
- package/dist/cjs/runtimes/react/components/page/PageHead.js.map +1 -1
- package/dist/cjs/runtimes/react/hooks/makeswift-api.js +10 -10
- package/dist/cjs/runtimes/react/hooks/makeswift-api.js.map +1 -1
- package/dist/cjs/runtimes/react/{host-api-client.js → hooks/use-api-resources-client.js} +9 -9
- package/dist/cjs/runtimes/react/hooks/use-api-resources-client.js.map +1 -0
- package/dist/cjs/runtimes/react/hooks/use-cache-data.js +2 -2
- package/dist/cjs/runtimes/react/hooks/use-cache-data.js.map +1 -1
- package/dist/cjs/runtimes/react/hooks/use-graphql-api-client.js +35 -0
- package/dist/cjs/runtimes/react/hooks/use-graphql-api-client.js.map +1 -0
- package/dist/cjs/runtimes/react/hooks/use-resource-resolver.js +13 -34
- package/dist/cjs/runtimes/react/hooks/use-resource-resolver.js.map +1 -1
- package/dist/cjs/runtimes/react/resource-resolver.js +52 -0
- package/dist/cjs/runtimes/react/resource-resolver.js.map +1 -0
- package/dist/cjs/runtimes/react/runtime-core.js +11 -6
- package/dist/cjs/runtimes/react/runtime-core.js.map +1 -1
- package/dist/cjs/slate/InlinePlugin/index.js +1 -1
- package/dist/cjs/slate/InlinePlugin/index.js.map +1 -1
- package/dist/cjs/slate/InlinePlugin/types.js +3 -3
- package/dist/cjs/slate/InlinePlugin/types.js.map +1 -1
- package/dist/cjs/slate/TextAlignPlugin/index.js +5 -5
- package/dist/cjs/slate/TextAlignPlugin/index.js.map +1 -1
- package/dist/cjs/state/actions/internal/read-write-actions.js.map +1 -1
- package/dist/cjs/state/api-client/client-store.js +81 -0
- package/dist/cjs/state/api-client/client-store.js.map +1 -0
- package/dist/cjs/state/{makeswift-api-client.js → api-client/fetch-api-resource.js} +15 -101
- package/dist/cjs/state/api-client/fetch-api-resource.js.map +1 -0
- package/dist/cjs/state/api-client/state.js +89 -0
- package/dist/cjs/state/api-client/state.js.map +1 -0
- package/dist/cjs/state/api-client/store.js +36 -0
- package/dist/cjs/state/api-client/store.js.map +1 -0
- package/dist/cjs/state/middleware/makeswift-api-client-sync.js +1 -1
- package/dist/cjs/state/middleware/makeswift-api-client-sync.js.map +1 -1
- package/dist/cjs/state/store.js +3 -3
- package/dist/cjs/state/store.js.map +1 -1
- package/dist/esm/api/api-resources-client.js +127 -0
- package/dist/esm/api/api-resources-client.js.map +1 -0
- package/dist/esm/api/client.js +19 -179
- package/dist/esm/api/client.js.map +1 -1
- package/dist/esm/api/graphql-api-client.js +15 -0
- package/dist/esm/api/graphql-api-client.js.map +1 -0
- package/dist/esm/api-handler/handlers/manifest.js +1 -1
- package/dist/esm/client/index.js +3 -3
- package/dist/esm/components/builtin/Form/Form.js +2 -2
- package/dist/esm/components/builtin/Form/Form.js.map +1 -1
- package/dist/esm/controls/index.js +2 -2
- package/dist/esm/controls/index.js.map +1 -1
- package/dist/esm/next/fetch.js.map +1 -1
- package/dist/esm/runtimes/react/components/GoogleFontLink.js +2 -2
- package/dist/esm/runtimes/react/components/GoogleFontLink.js.map +1 -1
- package/dist/esm/runtimes/react/components/hooks/use-page-snippets.js +2 -2
- package/dist/esm/runtimes/react/components/hooks/use-page-snippets.js.map +1 -1
- package/dist/esm/runtimes/react/components/page/PageHead.js +2 -2
- package/dist/esm/runtimes/react/components/page/PageHead.js.map +1 -1
- package/dist/esm/runtimes/react/hooks/makeswift-api.js +10 -10
- package/dist/esm/runtimes/react/hooks/makeswift-api.js.map +1 -1
- package/dist/esm/runtimes/react/hooks/use-api-resources-client.js +9 -0
- package/dist/esm/runtimes/react/hooks/use-api-resources-client.js.map +1 -0
- package/dist/esm/runtimes/react/hooks/use-cache-data.js +2 -2
- package/dist/esm/runtimes/react/hooks/use-cache-data.js.map +1 -1
- package/dist/esm/runtimes/react/hooks/use-graphql-api-client.js +11 -0
- package/dist/esm/runtimes/react/hooks/use-graphql-api-client.js.map +1 -0
- package/dist/esm/runtimes/react/hooks/use-resource-resolver.js +13 -24
- package/dist/esm/runtimes/react/hooks/use-resource-resolver.js.map +1 -1
- package/dist/esm/runtimes/react/resource-resolver.js +28 -0
- package/dist/esm/runtimes/react/resource-resolver.js.map +1 -0
- package/dist/esm/runtimes/react/runtime-core.js +11 -6
- package/dist/esm/runtimes/react/runtime-core.js.map +1 -1
- package/dist/esm/slate/InlinePlugin/index.js +2 -2
- package/dist/esm/slate/InlinePlugin/index.js.map +1 -1
- package/dist/esm/slate/InlinePlugin/types.js +4 -4
- package/dist/esm/slate/InlinePlugin/types.js.map +1 -1
- package/dist/esm/slate/TextAlignPlugin/index.js +6 -6
- package/dist/esm/slate/TextAlignPlugin/index.js.map +1 -1
- package/dist/esm/state/actions/internal/read-write-actions.js.map +1 -1
- package/dist/esm/state/api-client/client-store.js +49 -0
- package/dist/esm/state/api-client/client-store.js.map +1 -0
- package/dist/esm/state/api-client/fetch-api-resource.js +93 -0
- package/dist/esm/state/api-client/fetch-api-resource.js.map +1 -0
- package/dist/esm/state/api-client/state.js +52 -0
- package/dist/esm/state/api-client/state.js.map +1 -0
- package/dist/esm/state/api-client/store.js +12 -0
- package/dist/esm/state/api-client/store.js.map +1 -0
- package/dist/esm/state/middleware/makeswift-api-client-sync.js +1 -1
- package/dist/esm/state/middleware/makeswift-api-client-sync.js.map +1 -1
- package/dist/esm/state/store.js +3 -3
- package/dist/esm/state/store.js.map +1 -1
- package/dist/types/api/api-resources-client.d.ts +57 -0
- package/dist/types/api/api-resources-client.d.ts.map +1 -0
- package/dist/types/api/client.d.ts +10 -46
- package/dist/types/api/client.d.ts.map +1 -1
- package/dist/types/api/graphql-api-client.d.ts +9 -0
- package/dist/types/api/graphql-api-client.d.ts.map +1 -0
- package/dist/types/client/index.d.ts +9 -9
- package/dist/types/controls/index.d.ts +1 -1
- package/dist/types/controls/index.d.ts.map +1 -1
- package/dist/types/next/fetch.d.ts +1 -1
- package/dist/types/next/fetch.d.ts.map +1 -1
- package/dist/types/runtimes/react/components/GoogleFontLink.d.ts.map +1 -1
- package/dist/types/runtimes/react/components/page/PageHead.d.ts.map +1 -1
- package/dist/types/runtimes/react/hooks/use-api-resources-client.d.ts +3 -0
- package/dist/types/runtimes/react/hooks/use-api-resources-client.d.ts.map +1 -0
- package/dist/types/runtimes/react/hooks/use-graphql-api-client.d.ts +3 -0
- package/dist/types/runtimes/react/hooks/use-graphql-api-client.d.ts.map +1 -0
- package/dist/types/runtimes/react/hooks/use-resource-resolver.d.ts.map +1 -1
- package/dist/types/runtimes/react/resource-resolver.d.ts +10 -0
- package/dist/types/runtimes/react/resource-resolver.d.ts.map +1 -0
- package/dist/types/runtimes/react/runtime-core.d.ts +5 -3
- package/dist/types/runtimes/react/runtime-core.d.ts.map +1 -1
- package/dist/types/slate/InlinePlugin/types.d.ts +3 -3
- package/dist/types/slate/InlinePlugin/types.d.ts.map +1 -1
- package/dist/types/slate/TextAlignPlugin/index.d.ts.map +1 -1
- package/dist/types/state/actions/internal/read-write-actions.d.ts +1 -1
- package/dist/types/state/actions/internal/read-write-actions.d.ts.map +1 -1
- package/dist/types/state/api-client/client-store.d.ts +6 -0
- package/dist/types/state/api-client/client-store.d.ts.map +1 -0
- package/dist/types/state/api-client/fetch-api-resource.d.ts +11 -0
- package/dist/types/state/api-client/fetch-api-resource.d.ts.map +1 -0
- package/dist/types/state/api-client/state.d.ts +30 -0
- package/dist/types/state/api-client/state.d.ts.map +1 -0
- package/dist/types/state/api-client/store.d.ts +18 -0
- package/dist/types/state/api-client/store.d.ts.map +1 -0
- package/dist/types/state/middleware/makeswift-api-client-sync.d.ts +2 -2
- package/dist/types/state/middleware/makeswift-api-client-sync.d.ts.map +1 -1
- package/dist/types/state/store.d.ts +4 -4
- package/dist/types/state/store.d.ts.map +1 -1
- package/package.json +3 -3
- package/dist/cjs/runtimes/react/host-api-client.js.map +0 -1
- package/dist/cjs/state/makeswift-api-client.js.map +0 -1
- package/dist/esm/runtimes/react/host-api-client.js +0 -9
- package/dist/esm/runtimes/react/host-api-client.js.map +0 -1
- package/dist/esm/state/makeswift-api-client.js +0 -179
- package/dist/esm/state/makeswift-api-client.js.map +0 -1
- package/dist/types/runtimes/react/host-api-client.d.ts +0 -3
- package/dist/types/runtimes/react/host-api-client.d.ts.map +0 -1
- package/dist/types/state/makeswift-api-client.d.ts +0 -51
- package/dist/types/state/makeswift-api-client.d.ts.map +0 -1
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var api_resources_client_exports = {};
|
|
30
|
+
__export(api_resources_client_exports, {
|
|
31
|
+
ApiResourcesClient: () => ApiResourcesClient,
|
|
32
|
+
CacheData: () => CacheData
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(api_resources_client_exports);
|
|
35
|
+
var ApiClientState = __toESM(require("../state/api-client/state"));
|
|
36
|
+
var import_types = require("./types");
|
|
37
|
+
const CacheData = {
|
|
38
|
+
empty() {
|
|
39
|
+
return {
|
|
40
|
+
apiResources: {},
|
|
41
|
+
localizedResourcesMap: {}
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
class ApiResourcesClient {
|
|
46
|
+
store;
|
|
47
|
+
subscribe;
|
|
48
|
+
constructor({ store }) {
|
|
49
|
+
this.store = store;
|
|
50
|
+
this.subscribe = this.store.subscribe;
|
|
51
|
+
}
|
|
52
|
+
readSwatch(swatchId) {
|
|
53
|
+
return ApiClientState.getAPIResource(this.store.getState(), import_types.APIResourceType.Swatch, swatchId);
|
|
54
|
+
}
|
|
55
|
+
resolveSwatch(swatchId) {
|
|
56
|
+
return this.resolveResource(import_types.APIResourceType.Swatch, {
|
|
57
|
+
id: swatchId,
|
|
58
|
+
read: (id) => this.readSwatch(id),
|
|
59
|
+
fetch: (id) => this.fetchSwatch(id)
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
readFile(fileId) {
|
|
63
|
+
return ApiClientState.getAPIResource(this.store.getState(), import_types.APIResourceType.File, fileId);
|
|
64
|
+
}
|
|
65
|
+
resolveFile(fileId) {
|
|
66
|
+
return this.resolveResource(import_types.APIResourceType.File, {
|
|
67
|
+
id: fileId,
|
|
68
|
+
read: (id) => this.readFile(id),
|
|
69
|
+
fetch: (id) => this.fetchFile(id)
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
readTypography(typographyId) {
|
|
73
|
+
return ApiClientState.getAPIResource(
|
|
74
|
+
this.store.getState(),
|
|
75
|
+
import_types.APIResourceType.Typography,
|
|
76
|
+
typographyId
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
resolveTypography(typographyId) {
|
|
80
|
+
return this.resolveResource(import_types.APIResourceType.Typography, {
|
|
81
|
+
id: typographyId,
|
|
82
|
+
read: (id) => this.readTypography(id),
|
|
83
|
+
fetch: (id) => this.fetchTypography(id)
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
readGlobalElement(globalElementId) {
|
|
87
|
+
return ApiClientState.getAPIResource(
|
|
88
|
+
this.store.getState(),
|
|
89
|
+
import_types.APIResourceType.GlobalElement,
|
|
90
|
+
globalElementId
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
readLocalizedGlobalElement({
|
|
94
|
+
globalElementId,
|
|
95
|
+
locale
|
|
96
|
+
}) {
|
|
97
|
+
return ApiClientState.getAPIResource(
|
|
98
|
+
this.store.getState(),
|
|
99
|
+
import_types.APIResourceType.LocalizedGlobalElement,
|
|
100
|
+
globalElementId,
|
|
101
|
+
locale
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
readPagePathnameSlice({
|
|
105
|
+
pageId,
|
|
106
|
+
locale
|
|
107
|
+
}) {
|
|
108
|
+
return ApiClientState.getAPIResource(
|
|
109
|
+
this.store.getState(),
|
|
110
|
+
import_types.APIResourceType.PagePathnameSlice,
|
|
111
|
+
pageId,
|
|
112
|
+
locale
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
resolvePagePathnameSlice({
|
|
116
|
+
pageId,
|
|
117
|
+
locale
|
|
118
|
+
}) {
|
|
119
|
+
return this.resolveResource(import_types.APIResourceType.PagePathnameSlice, {
|
|
120
|
+
id: pageId,
|
|
121
|
+
read: (id) => this.readPagePathnameSlice({ pageId: id, locale }),
|
|
122
|
+
fetch: (id) => this.fetchPagePathnameSlice({ pageId: id, locale })
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
resolveResource(type, {
|
|
126
|
+
id,
|
|
127
|
+
read,
|
|
128
|
+
fetch
|
|
129
|
+
}) {
|
|
130
|
+
const _read = () => id != null ? read(id) : null;
|
|
131
|
+
let lastValue = null;
|
|
132
|
+
return {
|
|
133
|
+
name: `${type}:${id}`,
|
|
134
|
+
readStable: () => lastValue = _read(),
|
|
135
|
+
subscribe: (onUpdate) => this.subscribe(() => {
|
|
136
|
+
if (_read() !== lastValue)
|
|
137
|
+
onUpdate();
|
|
138
|
+
}),
|
|
139
|
+
fetch: async () => id != null ? fetch(id) : null
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
readTable(tableId) {
|
|
143
|
+
return ApiClientState.getAPIResource(this.store.getState(), import_types.APIResourceType.Table, tableId);
|
|
144
|
+
}
|
|
145
|
+
readSite(siteId) {
|
|
146
|
+
return ApiClientState.getAPIResource(this.store.getState(), import_types.APIResourceType.Site, siteId);
|
|
147
|
+
}
|
|
148
|
+
readPage(pageId) {
|
|
149
|
+
return ApiClientState.getAPIResource(this.store.getState(), import_types.APIResourceType.Page, pageId);
|
|
150
|
+
}
|
|
151
|
+
readSnippet(snippetId) {
|
|
152
|
+
return ApiClientState.getAPIResource(this.store.getState(), import_types.APIResourceType.Snippet, snippetId);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
156
|
+
0 && (module.exports = {
|
|
157
|
+
ApiResourcesClient,
|
|
158
|
+
CacheData
|
|
159
|
+
});
|
|
160
|
+
//# sourceMappingURL=api-resources-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/api/api-resources-client.ts"],"sourcesContent":["import { type FetchableValue } from '@makeswift/controls'\n\nimport { type Store as ApiClientStore } from '../state/api-client/store'\nimport * as ApiClientState from '../state/api-client/state'\n\nimport {\n type File,\n type GlobalElement,\n type LocalizedGlobalElement,\n type Page,\n type PagePathnameSlice,\n type Site,\n type Snippet,\n type Swatch,\n type Table,\n type Typography,\n APIResourceType,\n} from './types'\n\nexport type CacheData = ApiClientState.SerializedState\n\nexport const CacheData = {\n empty(): CacheData {\n return {\n apiResources: {},\n localizedResourcesMap: {},\n }\n },\n}\nexport abstract class ApiResourcesClient {\n readonly store: ApiClientStore\n readonly subscribe: ApiClientStore['subscribe']\n\n constructor({ store }: { store: ApiClientStore }) {\n this.store = store\n this.subscribe = this.store.subscribe\n }\n\n abstract fetchSwatch(swatchId: string): Promise<Swatch | null>\n\n readSwatch(swatchId: string): Swatch | null {\n return ApiClientState.getAPIResource(this.store.getState(), APIResourceType.Swatch, swatchId)\n }\n\n resolveSwatch(swatchId: string | undefined): FetchableValue<Swatch | null> {\n return this.resolveResource(APIResourceType.Swatch, {\n id: swatchId,\n read: id => this.readSwatch(id),\n fetch: id => this.fetchSwatch(id),\n })\n }\n\n abstract fetchFile(fileId: string): Promise<File | null>\n\n readFile(fileId: string): File | null {\n return ApiClientState.getAPIResource(this.store.getState(), APIResourceType.File, fileId)\n }\n\n resolveFile(fileId: string | undefined): FetchableValue<File | null> {\n return this.resolveResource(APIResourceType.File, {\n id: fileId,\n read: id => this.readFile(id),\n fetch: id => this.fetchFile(id),\n })\n }\n\n abstract fetchTypography(typographyId: string): Promise<Typography | null>\n\n readTypography(typographyId: string): Typography | null {\n return ApiClientState.getAPIResource(\n this.store.getState(),\n APIResourceType.Typography,\n typographyId,\n )\n }\n\n resolveTypography(typographyId: string | undefined): FetchableValue<Typography | null> {\n return this.resolveResource(APIResourceType.Typography, {\n id: typographyId,\n read: id => this.readTypography(id),\n fetch: id => this.fetchTypography(id),\n })\n }\n\n abstract fetchGlobalElement(globalElementId: string): Promise<GlobalElement | null>\n\n readGlobalElement(globalElementId: string): GlobalElement | null {\n return ApiClientState.getAPIResource(\n this.store.getState(),\n APIResourceType.GlobalElement,\n globalElementId,\n )\n }\n\n abstract fetchLocalizedGlobalElement({\n globalElementId,\n locale,\n }: {\n globalElementId: string\n locale: string\n }): Promise<LocalizedGlobalElement | null>\n\n readLocalizedGlobalElement({\n globalElementId,\n locale,\n }: {\n globalElementId: string\n locale: string\n }): LocalizedGlobalElement | null {\n return ApiClientState.getAPIResource(\n this.store.getState(),\n APIResourceType.LocalizedGlobalElement,\n globalElementId,\n locale,\n )\n }\n\n readPagePathnameSlice({\n pageId,\n locale,\n }: {\n pageId: string\n locale: string | null\n }): PagePathnameSlice | null {\n return ApiClientState.getAPIResource(\n this.store.getState(),\n APIResourceType.PagePathnameSlice,\n pageId,\n locale,\n )\n }\n\n abstract fetchPagePathnameSlice({\n pageId,\n locale,\n }: {\n pageId: string\n locale: string | null\n }): Promise<PagePathnameSlice | null>\n\n resolvePagePathnameSlice({\n pageId,\n locale,\n }: {\n pageId: string | undefined\n locale: string | null\n }): FetchableValue<PagePathnameSlice | null> {\n return this.resolveResource(APIResourceType.PagePathnameSlice, {\n id: pageId,\n read: id => this.readPagePathnameSlice({ pageId: id, locale }),\n fetch: id => this.fetchPagePathnameSlice({ pageId: id, locale }),\n })\n }\n\n resolveResource<R>(\n type: APIResourceType,\n {\n id,\n read,\n fetch,\n }: {\n id: string | undefined\n read: (id: string) => R | null\n fetch: (id: string) => Promise<R | null>\n },\n ): FetchableValue<R | null> {\n const _read = () => (id != null ? read(id) : null)\n let lastValue: R | null = null\n return {\n name: `${type}:${id}`,\n readStable: () => (lastValue = _read()),\n subscribe: (onUpdate: () => void) =>\n this.subscribe(() => {\n if (_read() !== lastValue) onUpdate()\n }),\n fetch: async () => (id != null ? fetch(id) : null),\n }\n }\n\n abstract fetchTable(tableId: string): Promise<Table | null>\n\n readTable(tableId: string): Table | null {\n return ApiClientState.getAPIResource(this.store.getState(), APIResourceType.Table, tableId)\n }\n\n readSite(siteId: string): Site | null {\n return ApiClientState.getAPIResource(this.store.getState(), APIResourceType.Site, siteId)\n }\n\n readPage(pageId: string): Page | null {\n return ApiClientState.getAPIResource(this.store.getState(), APIResourceType.Page, pageId)\n }\n\n readSnippet(snippetId: string): Snippet | null {\n return ApiClientState.getAPIResource(this.store.getState(), APIResourceType.Snippet, snippetId)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,qBAAgC;AAEhC,mBAYO;AAIA,MAAM,YAAY;AAAA,EACvB,QAAmB;AACjB,WAAO;AAAA,MACL,cAAc,CAAC;AAAA,MACf,uBAAuB,CAAC;AAAA,IAC1B;AAAA,EACF;AACF;AACO,MAAe,mBAAmB;AAAA,EAC9B;AAAA,EACA;AAAA,EAET,YAAY,EAAE,MAAM,GAA8B;AAChD,SAAK,QAAQ;AACb,SAAK,YAAY,KAAK,MAAM;AAAA,EAC9B;AAAA,EAIA,WAAW,UAAiC;AAC1C,WAAO,eAAe,eAAe,KAAK,MAAM,SAAS,GAAG,6BAAgB,QAAQ,QAAQ;AAAA,EAC9F;AAAA,EAEA,cAAc,UAA6D;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client.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
6
|
var __export = (target, all) => {
|
|
9
7
|
for (var name in all)
|
|
@@ -17,231 +15,63 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
15
|
}
|
|
18
16
|
return to;
|
|
19
17
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
19
|
var client_exports = {};
|
|
30
20
|
__export(client_exports, {
|
|
31
|
-
CacheData: () => CacheData,
|
|
21
|
+
CacheData: () => import_api_resources_client2.CacheData,
|
|
32
22
|
MakeswiftHostApiClient: () => MakeswiftHostApiClient
|
|
33
23
|
});
|
|
34
24
|
module.exports = __toCommonJS(client_exports);
|
|
35
|
-
var
|
|
25
|
+
var import_fetch_api_resource = require("../state/api-client/fetch-api-resource");
|
|
26
|
+
var import_client_store = require("../state/api-client/client-store");
|
|
36
27
|
var import_types = require("./types");
|
|
37
|
-
var
|
|
38
|
-
var
|
|
39
|
-
|
|
40
|
-
empty() {
|
|
41
|
-
return {
|
|
42
|
-
apiResources: {},
|
|
43
|
-
localizedResourcesMap: {}
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
class MakeswiftHostApiClient {
|
|
48
|
-
graphqlClient;
|
|
49
|
-
makeswiftApiClient;
|
|
50
|
-
subscribe;
|
|
28
|
+
var import_api_resources_client = require("./api-resources-client");
|
|
29
|
+
var import_api_resources_client2 = require("./api-resources-client");
|
|
30
|
+
class MakeswiftHostApiClient extends import_api_resources_client.ApiResourcesClient {
|
|
51
31
|
fetch;
|
|
52
32
|
constructor({
|
|
53
|
-
uri,
|
|
54
33
|
fetch,
|
|
55
34
|
preloadedState
|
|
56
35
|
}) {
|
|
57
|
-
|
|
58
|
-
|
|
36
|
+
super({
|
|
37
|
+
store: (0, import_client_store.configureClientStore)({ preloadedState })
|
|
38
|
+
});
|
|
59
39
|
this.fetch = fetch;
|
|
60
|
-
this.subscribe = this.makeswiftApiClient.subscribe;
|
|
61
|
-
}
|
|
62
|
-
readSwatch(swatchId) {
|
|
63
|
-
return MakeswiftApiClient.getAPIResource(
|
|
64
|
-
this.makeswiftApiClient.getState(),
|
|
65
|
-
import_types.APIResourceType.Swatch,
|
|
66
|
-
swatchId
|
|
67
|
-
);
|
|
68
40
|
}
|
|
69
41
|
async fetchSwatch(swatchId) {
|
|
70
|
-
return await this.
|
|
71
|
-
MakeswiftApiClient.fetchAPIResource(import_types.APIResourceType.Swatch, swatchId, this.fetch)
|
|
72
|
-
);
|
|
73
|
-
}
|
|
74
|
-
resolveSwatch(swatchId) {
|
|
75
|
-
return this.resolveResource(import_types.APIResourceType.Swatch, {
|
|
76
|
-
id: swatchId,
|
|
77
|
-
read: (id) => this.readSwatch(id),
|
|
78
|
-
fetch: (id) => this.fetchSwatch(id)
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
readFile(fileId) {
|
|
82
|
-
return MakeswiftApiClient.getAPIResource(
|
|
83
|
-
this.makeswiftApiClient.getState(),
|
|
84
|
-
import_types.APIResourceType.File,
|
|
85
|
-
fileId
|
|
86
|
-
);
|
|
42
|
+
return await this.store.dispatch((0, import_fetch_api_resource.fetchAPIResource)(import_types.APIResourceType.Swatch, swatchId, this.fetch));
|
|
87
43
|
}
|
|
88
44
|
async fetchFile(fileId) {
|
|
89
|
-
return await this.
|
|
90
|
-
MakeswiftApiClient.fetchAPIResource(import_types.APIResourceType.File, fileId, this.fetch)
|
|
91
|
-
);
|
|
92
|
-
}
|
|
93
|
-
resolveFile(fileId) {
|
|
94
|
-
return this.resolveResource(import_types.APIResourceType.File, {
|
|
95
|
-
id: fileId,
|
|
96
|
-
read: (id) => this.readFile(id),
|
|
97
|
-
fetch: (id) => this.fetchFile(id)
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
readTypography(typographyId) {
|
|
101
|
-
return MakeswiftApiClient.getAPIResource(
|
|
102
|
-
this.makeswiftApiClient.getState(),
|
|
103
|
-
import_types.APIResourceType.Typography,
|
|
104
|
-
typographyId
|
|
105
|
-
);
|
|
45
|
+
return await this.store.dispatch((0, import_fetch_api_resource.fetchAPIResource)(import_types.APIResourceType.File, fileId, this.fetch));
|
|
106
46
|
}
|
|
107
47
|
async fetchTypography(typographyId) {
|
|
108
|
-
return await this.
|
|
109
|
-
|
|
110
|
-
);
|
|
111
|
-
}
|
|
112
|
-
resolveTypography(typographyId) {
|
|
113
|
-
return this.resolveResource(import_types.APIResourceType.Typography, {
|
|
114
|
-
id: typographyId,
|
|
115
|
-
read: (id) => this.readTypography(id),
|
|
116
|
-
fetch: (id) => this.fetchTypography(id)
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
readGlobalElement(globalElementId) {
|
|
120
|
-
return MakeswiftApiClient.getAPIResource(
|
|
121
|
-
this.makeswiftApiClient.getState(),
|
|
122
|
-
import_types.APIResourceType.GlobalElement,
|
|
123
|
-
globalElementId
|
|
48
|
+
return await this.store.dispatch(
|
|
49
|
+
(0, import_fetch_api_resource.fetchAPIResource)(import_types.APIResourceType.Typography, typographyId, this.fetch)
|
|
124
50
|
);
|
|
125
51
|
}
|
|
126
52
|
async fetchGlobalElement(globalElementId) {
|
|
127
|
-
return await this.
|
|
128
|
-
|
|
129
|
-
import_types.APIResourceType.GlobalElement,
|
|
130
|
-
globalElementId,
|
|
131
|
-
this.fetch
|
|
132
|
-
)
|
|
133
|
-
);
|
|
134
|
-
}
|
|
135
|
-
readLocalizedGlobalElement({
|
|
136
|
-
globalElementId,
|
|
137
|
-
locale
|
|
138
|
-
}) {
|
|
139
|
-
return MakeswiftApiClient.getAPIResource(
|
|
140
|
-
this.makeswiftApiClient.getState(),
|
|
141
|
-
import_types.APIResourceType.LocalizedGlobalElement,
|
|
142
|
-
globalElementId,
|
|
143
|
-
locale
|
|
53
|
+
return await this.store.dispatch(
|
|
54
|
+
(0, import_fetch_api_resource.fetchAPIResource)(import_types.APIResourceType.GlobalElement, globalElementId, this.fetch)
|
|
144
55
|
);
|
|
145
56
|
}
|
|
146
57
|
async fetchLocalizedGlobalElement({
|
|
147
58
|
globalElementId,
|
|
148
59
|
locale
|
|
149
60
|
}) {
|
|
150
|
-
return await this.
|
|
151
|
-
|
|
152
|
-
import_types.APIResourceType.LocalizedGlobalElement,
|
|
153
|
-
globalElementId,
|
|
154
|
-
this.fetch,
|
|
155
|
-
locale
|
|
156
|
-
)
|
|
157
|
-
);
|
|
158
|
-
}
|
|
159
|
-
readPagePathnameSlice({
|
|
160
|
-
pageId,
|
|
161
|
-
locale
|
|
162
|
-
}) {
|
|
163
|
-
return MakeswiftApiClient.getAPIResource(
|
|
164
|
-
this.makeswiftApiClient.getState(),
|
|
165
|
-
import_types.APIResourceType.PagePathnameSlice,
|
|
166
|
-
pageId,
|
|
167
|
-
locale
|
|
61
|
+
return await this.store.dispatch(
|
|
62
|
+
(0, import_fetch_api_resource.fetchAPIResource)(import_types.APIResourceType.LocalizedGlobalElement, globalElementId, this.fetch, locale)
|
|
168
63
|
);
|
|
169
64
|
}
|
|
170
65
|
async fetchPagePathnameSlice({
|
|
171
66
|
pageId,
|
|
172
67
|
locale
|
|
173
68
|
}) {
|
|
174
|
-
return await this.
|
|
175
|
-
|
|
176
|
-
import_types.APIResourceType.PagePathnameSlice,
|
|
177
|
-
pageId,
|
|
178
|
-
this.fetch,
|
|
179
|
-
locale
|
|
180
|
-
)
|
|
181
|
-
);
|
|
182
|
-
}
|
|
183
|
-
resolvePagePathnameSlice({
|
|
184
|
-
pageId,
|
|
185
|
-
locale
|
|
186
|
-
}) {
|
|
187
|
-
return this.resolveResource(import_types.APIResourceType.PagePathnameSlice, {
|
|
188
|
-
id: pageId,
|
|
189
|
-
read: (id) => this.readPagePathnameSlice({ pageId: id, locale }),
|
|
190
|
-
fetch: (id) => this.fetchPagePathnameSlice({ pageId: id, locale })
|
|
191
|
-
});
|
|
192
|
-
}
|
|
193
|
-
resolveResource(type, {
|
|
194
|
-
id,
|
|
195
|
-
read,
|
|
196
|
-
fetch
|
|
197
|
-
}) {
|
|
198
|
-
const _read = () => id != null ? read(id) : null;
|
|
199
|
-
let lastValue = null;
|
|
200
|
-
return {
|
|
201
|
-
name: `${type}:${id}`,
|
|
202
|
-
readStable: () => lastValue = _read(),
|
|
203
|
-
subscribe: (onUpdate) => this.subscribe(() => {
|
|
204
|
-
if (_read() !== lastValue)
|
|
205
|
-
onUpdate();
|
|
206
|
-
}),
|
|
207
|
-
fetch: async () => id != null ? fetch(id) : null
|
|
208
|
-
};
|
|
209
|
-
}
|
|
210
|
-
readTable(tableId) {
|
|
211
|
-
return MakeswiftApiClient.getAPIResource(
|
|
212
|
-
this.makeswiftApiClient.getState(),
|
|
213
|
-
import_types.APIResourceType.Table,
|
|
214
|
-
tableId
|
|
69
|
+
return await this.store.dispatch(
|
|
70
|
+
(0, import_fetch_api_resource.fetchAPIResource)(import_types.APIResourceType.PagePathnameSlice, pageId, this.fetch, locale)
|
|
215
71
|
);
|
|
216
72
|
}
|
|
217
73
|
async fetchTable(tableId) {
|
|
218
|
-
return await this.
|
|
219
|
-
MakeswiftApiClient.fetchAPIResource(import_types.APIResourceType.Table, tableId, this.fetch)
|
|
220
|
-
);
|
|
221
|
-
}
|
|
222
|
-
async createTableRecord(tableId, columns) {
|
|
223
|
-
await this.graphqlClient.request(import_documents.CreateTableRecordMutation, { input: { data: { tableId, columns } } });
|
|
224
|
-
}
|
|
225
|
-
readSite(siteId) {
|
|
226
|
-
return MakeswiftApiClient.getAPIResource(
|
|
227
|
-
this.makeswiftApiClient.getState(),
|
|
228
|
-
import_types.APIResourceType.Site,
|
|
229
|
-
siteId
|
|
230
|
-
);
|
|
231
|
-
}
|
|
232
|
-
readPage(pageId) {
|
|
233
|
-
return MakeswiftApiClient.getAPIResource(
|
|
234
|
-
this.makeswiftApiClient.getState(),
|
|
235
|
-
import_types.APIResourceType.Page,
|
|
236
|
-
pageId
|
|
237
|
-
);
|
|
238
|
-
}
|
|
239
|
-
readSnippet(snippetId) {
|
|
240
|
-
return MakeswiftApiClient.getAPIResource(
|
|
241
|
-
this.makeswiftApiClient.getState(),
|
|
242
|
-
import_types.APIResourceType.Snippet,
|
|
243
|
-
snippetId
|
|
244
|
-
);
|
|
74
|
+
return await this.store.dispatch((0, import_fetch_api_resource.fetchAPIResource)(import_types.APIResourceType.Table, tableId, this.fetch));
|
|
245
75
|
}
|
|
246
76
|
}
|
|
247
77
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/api/client.ts"],"sourcesContent":["import { type FetchableValue } from '@makeswift/controls'\n\nimport * as MakeswiftApiClient from '../state/makeswift-api-client'\n\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 preloadedState,\n }: {\n uri: string\n fetch: MakeswiftApiClient.HttpFetch\n preloadedState: Partial<MakeswiftApiClient.State>\n }) {\n this.graphqlClient = new GraphQLClient(uri)\n this.makeswiftApiClient = MakeswiftApiClient.configureStore({ preloadedState })\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;AAEA,yBAAoC;AAEpC,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,EACF,GAIG;AACD,SAAK,gBAAgB,IAAI,4BAAc,GAAG;AAC1C,SAAK,qBAAqB,mBAAmB,eAAe,EAAE,eAAe,CAAC;AAC9E,SAAK,QAAQ;AACb,SAAK,YAAY,KAAK,mBAAmB;AAAA,EAC3C;AAAA,EAEA,WAAW,UAAiC;AAC1C,WAAO,mBAAmB;AAAA,MACxB,KAAK,mBAAmB,SAAS;AAAA,MACjC,6BA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B;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/client.ts"],"sourcesContent":["import { type State as ApiClientState } from '../state/api-client/state'\nimport { type HttpFetch, fetchAPIResource } from '../state/api-client/fetch-api-resource'\nimport { configureClientStore } from '../state/api-client/client-store'\n\nimport {\n type File,\n type GlobalElement,\n type LocalizedGlobalElement,\n type PagePathnameSlice,\n type Swatch,\n type Table,\n type Typography,\n APIResourceType,\n} from './types'\n\nimport { ApiResourcesClient } from './api-resources-client'\n\nexport { CacheData } from './api-resources-client'\n\n/**\n * NOTE(miguel): This \"client\" is used to fetch Makeswift API resources needed for the host. For\n * example, swatches, files, typographies, etc. Ideally it's internal to the runtime and is only\n * used by controls to transform API references to API resources.\n *\n * Moreover, its use should be reserved for the builder only, since for live pages all Makeswift\n * API resources should be embedded in the \"page snapshot\". In the builder, this client serves the\n * purpose of sending requests for API resources and keeping a cache so that changes that happen in\n * the builder, like modifying a swatch, can be sent via `postMessage` to the host and the cache can\n * immediately update the value and re-render.\n *\n * Furthermore, the API resources requested shouldn't be requested directly from the Makeswift API\n * as that would require those resources to not be authenticated since the requests come from the\n * browser when running the host. Instead, the requests should go to the host directly, at the\n * Makeswift API endpoint (i.g., `/api/makeswift/[...makeswift]` dynamic route) where the host's\n * API key can be used, securely, in the server. For this reason, this client should really be a\n * client of the host's API, not Makeswift's, intended to build and continuously maintain a realtime\n * snapshot for use in the builder, not the lives pages.\n */\nexport class MakeswiftHostApiClient extends ApiResourcesClient {\n readonly fetch: HttpFetch\n\n constructor({\n fetch,\n preloadedState,\n }: {\n fetch: HttpFetch\n preloadedState: Partial<ApiClientState>\n }) {\n super({\n store: configureClientStore({ preloadedState }),\n })\n\n this.fetch = fetch\n }\n\n async fetchSwatch(swatchId: string): Promise<Swatch | null> {\n return await this.store.dispatch(fetchAPIResource(APIResourceType.Swatch, swatchId, this.fetch))\n }\n\n async fetchFile(fileId: string): Promise<File | null> {\n return await this.store.dispatch(fetchAPIResource(APIResourceType.File, fileId, this.fetch))\n }\n\n async fetchTypography(typographyId: string): Promise<Typography | null> {\n return await this.store.dispatch(\n fetchAPIResource(APIResourceType.Typography, typographyId, this.fetch),\n )\n }\n\n async fetchGlobalElement(globalElementId: string): Promise<GlobalElement | null> {\n return await this.store.dispatch(\n fetchAPIResource(APIResourceType.GlobalElement, globalElementId, this.fetch),\n )\n }\n\n async fetchLocalizedGlobalElement({\n globalElementId,\n locale,\n }: {\n globalElementId: string\n locale: string\n }): Promise<LocalizedGlobalElement | null> {\n return await this.store.dispatch(\n fetchAPIResource(APIResourceType.LocalizedGlobalElement, globalElementId, this.fetch, locale),\n )\n }\n\n async fetchPagePathnameSlice({\n pageId,\n locale,\n }: {\n pageId: string\n locale: string | null\n }): Promise<PagePathnameSlice | null> {\n return await this.store.dispatch(\n fetchAPIResource(APIResourceType.PagePathnameSlice, pageId, this.fetch, locale),\n )\n }\n\n async fetchTable(tableId: string): Promise<Table | null> {\n return await this.store.dispatch(fetchAPIResource(APIResourceType.Table, tableId, this.fetch))\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,gCAAiD;AACjD,0BAAqC;AAErC,mBASO;AAEP,kCAAmC;AAEnC,IAAAA,+BAA0B;AAqBnB,MAAM,+BAA+B,+CAAmB;AAAA,EACpD;AAAA,EAET,YAAY;AAAA,IACV;AAAA,IACA;AAAA,EACF,GAGG;AACD,UAAM;AAAA,MACJ,WAAO,0CAAqB,EAAE,eAAe,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yDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var graphql_api_client_exports = {};
|
|
20
|
+
__export(graphql_api_client_exports, {
|
|
21
|
+
MakeswiftGraphQLApiClient: () => MakeswiftGraphQLApiClient
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(graphql_api_client_exports);
|
|
24
|
+
var import_client = require("./graphql/client");
|
|
25
|
+
var import_documents = require("./graphql/documents");
|
|
26
|
+
class MakeswiftGraphQLApiClient {
|
|
27
|
+
graphqlClient;
|
|
28
|
+
constructor({ endpoint }) {
|
|
29
|
+
this.graphqlClient = new import_client.GraphQLClient(endpoint);
|
|
30
|
+
}
|
|
31
|
+
async createTableRecord(tableId, columns) {
|
|
32
|
+
await this.graphqlClient.request(import_documents.CreateTableRecordMutation, { input: { data: { tableId, columns } } });
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
36
|
+
0 && (module.exports = {
|
|
37
|
+
MakeswiftGraphQLApiClient
|
|
38
|
+
});
|
|
39
|
+
//# sourceMappingURL=graphql-api-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/api/graphql-api-client.ts"],"sourcesContent":["import { GraphQLClient } from './graphql/client'\nimport { CreateTableRecordMutation } from './graphql/documents'\nimport {\n CreateTableRecordMutationResult,\n CreateTableRecordMutationVariables,\n} from './graphql/generated/types'\n\nexport class MakeswiftGraphQLApiClient {\n readonly graphqlClient: GraphQLClient\n\n constructor({ endpoint }: { endpoint: string }) {\n this.graphqlClient = new GraphQLClient(endpoint)\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"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA8B;AAC9B,uBAA0C;AAMnC,MAAM,0BAA0B;AAAA,EAC5B;AAAA,EAET,YAAY,EAAE,SAAS,GAAyB;AAC9C,SAAK,gBAAgB,IAAI,4BAAc,QAAQ;AAAA,EACjD;AAAA,EAEA,MAAM,kBAAkB,SAAiB,SAA6B;AACpE,UAAM,KAAK,cAAc,QAGvB,4CAA2B,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,QAAQ,EAAE,EAAE,CAAC;AAAA,EACxE;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.28.7-canary.
|
|
31
|
+
version: "0.28.7-canary.4",
|
|
32
32
|
interactionMode: true,
|
|
33
33
|
clientSideNavigation: false,
|
|
34
34
|
elementFromPoint: false,
|
package/dist/cjs/client/index.js
CHANGED
|
@@ -214,7 +214,7 @@ Received "${apiKey}" instead.`
|
|
|
214
214
|
}
|
|
215
215
|
this.apiKey = apiKey;
|
|
216
216
|
this.graphqlClient = new import_client.GraphQLClient(new URL("graphql", runtime.apiOrigin).href, {
|
|
217
|
-
"makeswift-runtime-version": "0.28.7-canary.
|
|
217
|
+
"makeswift-runtime-version": "0.28.7-canary.4"
|
|
218
218
|
});
|
|
219
219
|
this.runtime = runtime;
|
|
220
220
|
}
|
|
@@ -226,7 +226,7 @@ Received "${apiKey}" instead.`
|
|
|
226
226
|
const requestHeaders = new Headers({
|
|
227
227
|
"x-api-key": this.apiKey,
|
|
228
228
|
"makeswift-site-api-key": this.apiKey,
|
|
229
|
-
"makeswift-runtime-version": "0.28.7-canary.
|
|
229
|
+
"makeswift-runtime-version": "0.28.7-canary.4"
|
|
230
230
|
});
|
|
231
231
|
if (siteVersion?.token) {
|
|
232
232
|
requestUrl.searchParams.set("version", siteVersion.version);
|
|
@@ -953,7 +953,7 @@ Received "${apiKey}" instead.`
|
|
|
953
953
|
headers: {
|
|
954
954
|
"x-api-key": this.apiKey,
|
|
955
955
|
"makeswift-site-api-key": this.apiKey,
|
|
956
|
-
"makeswift-runtime-version": "0.28.7-canary.
|
|
956
|
+
"makeswift-runtime-version": "0.28.7-canary.4",
|
|
957
957
|
"content-type": "application/json"
|
|
958
958
|
},
|
|
959
959
|
body: JSON.stringify({ token }),
|
|
@@ -47,7 +47,7 @@ var import_box_models = require("../../../state/modules/read-write/box-models");
|
|
|
47
47
|
var import_useTableFormFieldRefs = require("../../hooks/useTableFormFieldRefs");
|
|
48
48
|
var import_css = require("@emotion/css");
|
|
49
49
|
var import_responsive_style = require("../../utils/responsive-style");
|
|
50
|
-
var
|
|
50
|
+
var import_use_graphql_api_client = require("../../../runtimes/react/hooks/use-graphql-api-client");
|
|
51
51
|
var import_use_style = require("../../../runtimes/react/use-style");
|
|
52
52
|
var import_makeswift_api = require("../../../runtimes/react/hooks/makeswift-api");
|
|
53
53
|
const LOCAL_STORAGE_NAMESPACE = "@@makeswift/components/form";
|
|
@@ -203,7 +203,7 @@ const Form = (0, import_react.forwardRef)(function Form2({
|
|
|
203
203
|
const fields = (0, import_react.useMemo)(() => fieldsProp?.fields ?? [], [fieldsProp]);
|
|
204
204
|
const grid = (0, import_react.useMemo)(() => fieldsProp?.grid ?? [], [fieldsProp]);
|
|
205
205
|
const table = (0, import_makeswift_api.useTable)(tableId ?? null);
|
|
206
|
-
const client = (0,
|
|
206
|
+
const client = (0, import_use_graphql_api_client.useMakeswiftGraphQLApiClient)();
|
|
207
207
|
const [refEl, setRefEl] = (0, import_react.useState)(null);
|
|
208
208
|
const [propControllers, setPropControllers] = (0, import_react.useState)(null);
|
|
209
209
|
const [initialValues, setInitialValues] = (0, import_react.useState)(
|