@makeswift/runtime 0.27.1 → 0.27.2
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 +256 -0
- package/dist/cjs/api/react.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/next/api-handler/config/app-router.js +10 -1
- package/dist/cjs/next/api-handler/config/app-router.js.map +1 -1
- package/dist/cjs/runtimes/react/components/LiveProvider.js +50 -0
- package/dist/cjs/runtimes/react/components/LiveProvider.js.map +1 -0
- package/dist/cjs/runtimes/react/components/PreviewProvider.js +63 -0
- package/dist/cjs/runtimes/react/components/PreviewProvider.js.map +1 -0
- package/dist/cjs/runtimes/react/components/hooks/use-builder-connection-ping.js +62 -0
- package/dist/cjs/runtimes/react/components/hooks/use-builder-connection-ping.js.map +1 -0
- package/dist/cjs/runtimes/react/hooks/use-is-preview.js +33 -0
- package/dist/cjs/runtimes/react/hooks/use-is-preview.js.map +1 -0
- package/dist/cjs/state/actions/internal.js +205 -0
- package/dist/cjs/state/actions/internal.js.map +1 -0
- package/dist/cjs/state/mixins/setup-teardown.js +35 -0
- package/dist/cjs/state/mixins/setup-teardown.js.map +1 -0
- package/dist/cjs/state/modules/box-models.js +127 -0
- package/dist/cjs/state/modules/box-models.js.map +1 -0
- package/dist/cjs/state/modules/element-imperative-handles.js +60 -0
- package/dist/cjs/state/modules/element-imperative-handles.js.map +1 -0
- package/dist/cjs/state/modules/is-preview.js +47 -0
- package/dist/cjs/state/modules/is-preview.js.map +1 -0
- package/dist/cjs/state/modules/pointer.js +47 -0
- package/dist/cjs/state/modules/pointer.js.map +1 -0
- package/dist/cjs/state/modules/read-write-documents.js +98 -0
- package/dist/cjs/state/modules/read-write-documents.js.map +1 -0
- package/dist/cjs/state/react-builder-preview.js +586 -0
- package/dist/cjs/state/react-builder-preview.js.map +1 -0
- package/dist/cjs/state/react-page.js +313 -0
- package/dist/cjs/state/react-page.js.map +1 -0
- package/dist/esm/api/react.js +223 -0
- package/dist/esm/api/react.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/next/api-handler/config/app-router.js +10 -1
- package/dist/esm/next/api-handler/config/app-router.js.map +1 -1
- package/dist/esm/runtimes/react/components/LiveProvider.js +20 -0
- package/dist/esm/runtimes/react/components/LiveProvider.js.map +1 -0
- package/dist/esm/runtimes/react/components/PreviewProvider.js +33 -0
- package/dist/esm/runtimes/react/components/PreviewProvider.js.map +1 -0
- package/dist/esm/runtimes/react/components/hooks/use-builder-connection-ping.js +38 -0
- package/dist/esm/runtimes/react/components/hooks/use-builder-connection-ping.js.map +1 -0
- package/dist/esm/runtimes/react/hooks/use-is-preview.js +9 -0
- package/dist/esm/runtimes/react/hooks/use-is-preview.js.map +1 -0
- package/dist/esm/state/actions/internal.js +162 -0
- package/dist/esm/state/actions/internal.js.map +1 -0
- package/dist/esm/state/mixins/setup-teardown.js +11 -0
- package/dist/esm/state/mixins/setup-teardown.js.map +1 -0
- package/dist/esm/state/modules/box-models.js +98 -0
- package/dist/esm/state/modules/box-models.js.map +1 -0
- package/dist/esm/state/modules/element-imperative-handles.js +35 -0
- package/dist/esm/state/modules/element-imperative-handles.js.map +1 -0
- package/dist/esm/state/modules/is-preview.js +21 -0
- package/dist/esm/state/modules/is-preview.js.map +1 -0
- package/dist/esm/state/modules/pointer.js +22 -0
- package/dist/esm/state/modules/pointer.js.map +1 -0
- package/dist/esm/state/modules/read-write-documents.js +60 -0
- package/dist/esm/state/modules/read-write-documents.js.map +1 -0
- package/dist/esm/state/react-builder-preview.js +547 -0
- package/dist/esm/state/react-builder-preview.js.map +1 -0
- package/dist/esm/state/react-page.js +268 -0
- package/dist/esm/state/react-page.js.map +1 -0
- package/dist/types/api/react.d.ts +82 -0
- package/dist/types/api/react.d.ts.map +1 -0
- package/dist/types/next/api-handler/config/app-router.d.ts.map +1 -1
- package/dist/types/runtimes/react/components/LiveProvider.d.ts +3 -0
- package/dist/types/runtimes/react/components/LiveProvider.d.ts.map +1 -0
- package/dist/types/runtimes/react/components/PreviewProvider.d.ts +5 -0
- package/dist/types/runtimes/react/components/PreviewProvider.d.ts.map +1 -0
- package/dist/types/runtimes/react/components/hooks/use-builder-connection-ping.d.ts +4 -0
- package/dist/types/runtimes/react/components/hooks/use-builder-connection-ping.d.ts.map +1 -0
- package/dist/types/runtimes/react/hooks/use-is-preview.d.ts +2 -0
- package/dist/types/runtimes/react/hooks/use-is-preview.d.ts.map +1 -0
- package/dist/types/state/__tests__/react-page.test.d.ts +2 -0
- package/dist/types/state/__tests__/react-page.test.d.ts.map +1 -0
- package/dist/types/state/actions/internal.d.ts +181 -0
- package/dist/types/state/actions/internal.d.ts.map +1 -0
- package/dist/types/state/mixins/setup-teardown.d.ts +7 -0
- package/dist/types/state/mixins/setup-teardown.d.ts.map +1 -0
- package/dist/types/state/modules/box-models.d.ts +23 -0
- package/dist/types/state/modules/box-models.d.ts.map +1 -0
- package/dist/types/state/modules/element-imperative-handles.d.ts +7 -0
- package/dist/types/state/modules/element-imperative-handles.d.ts.map +1 -0
- package/dist/types/state/modules/is-preview.d.ts +6 -0
- package/dist/types/state/modules/is-preview.d.ts.map +1 -0
- package/dist/types/state/modules/pointer.d.ts +12 -0
- package/dist/types/state/modules/pointer.d.ts.map +1 -0
- package/dist/types/state/modules/read-write-documents.d.ts +14 -0
- package/dist/types/state/modules/read-write-documents.d.ts.map +1 -0
- package/dist/types/state/react-builder-preview.d.ts +108 -0
- package/dist/types/state/react-builder-preview.d.ts.map +1 -0
- package/dist/types/state/react-page.d.ts +149 -0
- package/dist/types/state/react-page.d.ts.map +1 -0
- package/package.json +3 -3
|
@@ -0,0 +1,256 @@
|
|
|
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 react_exports = {};
|
|
30
|
+
__export(react_exports, {
|
|
31
|
+
CacheData: () => CacheData,
|
|
32
|
+
MakeswiftHostApiClient: () => MakeswiftHostApiClient
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(react_exports);
|
|
35
|
+
var MakeswiftApiClient = __toESM(require("../state/makeswift-api-client"));
|
|
36
|
+
var import_types = require("./types");
|
|
37
|
+
var import_client = require("./graphql/client");
|
|
38
|
+
var import_documents = require("./graphql/documents");
|
|
39
|
+
const CacheData = {
|
|
40
|
+
empty() {
|
|
41
|
+
return {
|
|
42
|
+
apiResources: {},
|
|
43
|
+
localizedResourcesMap: {}
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
class MakeswiftHostApiClient {
|
|
48
|
+
graphqlClient;
|
|
49
|
+
makeswiftApiClient;
|
|
50
|
+
subscribe;
|
|
51
|
+
fetch;
|
|
52
|
+
constructor({
|
|
53
|
+
uri,
|
|
54
|
+
fetch,
|
|
55
|
+
cacheData,
|
|
56
|
+
locale
|
|
57
|
+
}) {
|
|
58
|
+
this.graphqlClient = new import_client.GraphQLClient(uri);
|
|
59
|
+
this.makeswiftApiClient = MakeswiftApiClient.configureStore({
|
|
60
|
+
serializedState: cacheData,
|
|
61
|
+
defaultLocale: locale
|
|
62
|
+
});
|
|
63
|
+
this.fetch = fetch;
|
|
64
|
+
this.subscribe = this.makeswiftApiClient.subscribe;
|
|
65
|
+
}
|
|
66
|
+
readSwatch(swatchId) {
|
|
67
|
+
return MakeswiftApiClient.getAPIResource(
|
|
68
|
+
this.makeswiftApiClient.getState(),
|
|
69
|
+
import_types.APIResourceType.Swatch,
|
|
70
|
+
swatchId
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
async fetchSwatch(swatchId) {
|
|
74
|
+
return await this.makeswiftApiClient.dispatch(
|
|
75
|
+
MakeswiftApiClient.fetchAPIResource(import_types.APIResourceType.Swatch, swatchId, this.fetch)
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
resolveSwatch(swatchId) {
|
|
79
|
+
return this.resolveResource(import_types.APIResourceType.Swatch, {
|
|
80
|
+
id: swatchId,
|
|
81
|
+
read: (id) => this.readSwatch(id),
|
|
82
|
+
fetch: (id) => this.fetchSwatch(id)
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
readFile(fileId) {
|
|
86
|
+
return MakeswiftApiClient.getAPIResource(
|
|
87
|
+
this.makeswiftApiClient.getState(),
|
|
88
|
+
import_types.APIResourceType.File,
|
|
89
|
+
fileId
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
async fetchFile(fileId) {
|
|
93
|
+
return await this.makeswiftApiClient.dispatch(
|
|
94
|
+
MakeswiftApiClient.fetchAPIResource(import_types.APIResourceType.File, fileId, this.fetch)
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
resolveFile(fileId) {
|
|
98
|
+
return this.resolveResource(import_types.APIResourceType.File, {
|
|
99
|
+
id: fileId,
|
|
100
|
+
read: (id) => this.readFile(id),
|
|
101
|
+
fetch: (id) => this.fetchFile(id)
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
readTypography(typographyId) {
|
|
105
|
+
return MakeswiftApiClient.getAPIResource(
|
|
106
|
+
this.makeswiftApiClient.getState(),
|
|
107
|
+
import_types.APIResourceType.Typography,
|
|
108
|
+
typographyId
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
async fetchTypography(typographyId) {
|
|
112
|
+
return await this.makeswiftApiClient.dispatch(
|
|
113
|
+
MakeswiftApiClient.fetchAPIResource(import_types.APIResourceType.Typography, typographyId, this.fetch)
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
resolveTypography(typographyId) {
|
|
117
|
+
return this.resolveResource(import_types.APIResourceType.Typography, {
|
|
118
|
+
id: typographyId,
|
|
119
|
+
read: (id) => this.readTypography(id),
|
|
120
|
+
fetch: (id) => this.fetchTypography(id)
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
readGlobalElement(globalElementId) {
|
|
124
|
+
return MakeswiftApiClient.getAPIResource(
|
|
125
|
+
this.makeswiftApiClient.getState(),
|
|
126
|
+
import_types.APIResourceType.GlobalElement,
|
|
127
|
+
globalElementId
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
async fetchGlobalElement(globalElementId) {
|
|
131
|
+
return await this.makeswiftApiClient.dispatch(
|
|
132
|
+
MakeswiftApiClient.fetchAPIResource(
|
|
133
|
+
import_types.APIResourceType.GlobalElement,
|
|
134
|
+
globalElementId,
|
|
135
|
+
this.fetch
|
|
136
|
+
)
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
readLocalizedGlobalElement({
|
|
140
|
+
globalElementId,
|
|
141
|
+
locale
|
|
142
|
+
}) {
|
|
143
|
+
return MakeswiftApiClient.getAPIResource(
|
|
144
|
+
this.makeswiftApiClient.getState(),
|
|
145
|
+
import_types.APIResourceType.LocalizedGlobalElement,
|
|
146
|
+
globalElementId,
|
|
147
|
+
locale
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
async fetchLocalizedGlobalElement({
|
|
151
|
+
globalElementId,
|
|
152
|
+
locale
|
|
153
|
+
}) {
|
|
154
|
+
return await this.makeswiftApiClient.dispatch(
|
|
155
|
+
MakeswiftApiClient.fetchAPIResource(
|
|
156
|
+
import_types.APIResourceType.LocalizedGlobalElement,
|
|
157
|
+
globalElementId,
|
|
158
|
+
this.fetch,
|
|
159
|
+
locale
|
|
160
|
+
)
|
|
161
|
+
);
|
|
162
|
+
}
|
|
163
|
+
readPagePathnameSlice({
|
|
164
|
+
pageId,
|
|
165
|
+
locale
|
|
166
|
+
}) {
|
|
167
|
+
return MakeswiftApiClient.getAPIResource(
|
|
168
|
+
this.makeswiftApiClient.getState(),
|
|
169
|
+
import_types.APIResourceType.PagePathnameSlice,
|
|
170
|
+
pageId,
|
|
171
|
+
locale
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
async fetchPagePathnameSlice({
|
|
175
|
+
pageId,
|
|
176
|
+
locale
|
|
177
|
+
}) {
|
|
178
|
+
return await this.makeswiftApiClient.dispatch(
|
|
179
|
+
MakeswiftApiClient.fetchAPIResource(
|
|
180
|
+
import_types.APIResourceType.PagePathnameSlice,
|
|
181
|
+
pageId,
|
|
182
|
+
this.fetch,
|
|
183
|
+
locale
|
|
184
|
+
)
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
resolvePagePathnameSlice({
|
|
188
|
+
pageId,
|
|
189
|
+
locale
|
|
190
|
+
}) {
|
|
191
|
+
return this.resolveResource(import_types.APIResourceType.PagePathnameSlice, {
|
|
192
|
+
id: pageId,
|
|
193
|
+
read: (id) => this.readPagePathnameSlice({ pageId: id, locale }),
|
|
194
|
+
fetch: (id) => this.fetchPagePathnameSlice({ pageId: id, locale })
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
resolveResource(type, {
|
|
198
|
+
id,
|
|
199
|
+
read,
|
|
200
|
+
fetch
|
|
201
|
+
}) {
|
|
202
|
+
const _read = () => id != null ? read(id) : null;
|
|
203
|
+
let lastValue = null;
|
|
204
|
+
return {
|
|
205
|
+
name: `${type}:${id}`,
|
|
206
|
+
readStable: () => lastValue = _read(),
|
|
207
|
+
subscribe: (onUpdate) => this.subscribe(() => {
|
|
208
|
+
if (_read() !== lastValue)
|
|
209
|
+
onUpdate();
|
|
210
|
+
}),
|
|
211
|
+
fetch: async () => id != null ? fetch(id) : null
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
readTable(tableId) {
|
|
215
|
+
return MakeswiftApiClient.getAPIResource(
|
|
216
|
+
this.makeswiftApiClient.getState(),
|
|
217
|
+
import_types.APIResourceType.Table,
|
|
218
|
+
tableId
|
|
219
|
+
);
|
|
220
|
+
}
|
|
221
|
+
async fetchTable(tableId) {
|
|
222
|
+
return await this.makeswiftApiClient.dispatch(
|
|
223
|
+
MakeswiftApiClient.fetchAPIResource(import_types.APIResourceType.Table, tableId, this.fetch)
|
|
224
|
+
);
|
|
225
|
+
}
|
|
226
|
+
async createTableRecord(tableId, columns) {
|
|
227
|
+
await this.graphqlClient.request(import_documents.CreateTableRecordMutation, { input: { data: { tableId, columns } } });
|
|
228
|
+
}
|
|
229
|
+
readSite(siteId) {
|
|
230
|
+
return MakeswiftApiClient.getAPIResource(
|
|
231
|
+
this.makeswiftApiClient.getState(),
|
|
232
|
+
import_types.APIResourceType.Site,
|
|
233
|
+
siteId
|
|
234
|
+
);
|
|
235
|
+
}
|
|
236
|
+
readPage(pageId) {
|
|
237
|
+
return MakeswiftApiClient.getAPIResource(
|
|
238
|
+
this.makeswiftApiClient.getState(),
|
|
239
|
+
import_types.APIResourceType.Page,
|
|
240
|
+
pageId
|
|
241
|
+
);
|
|
242
|
+
}
|
|
243
|
+
readSnippet(snippetId) {
|
|
244
|
+
return MakeswiftApiClient.getAPIResource(
|
|
245
|
+
this.makeswiftApiClient.getState(),
|
|
246
|
+
import_types.APIResourceType.Snippet,
|
|
247
|
+
snippetId
|
|
248
|
+
);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
252
|
+
0 && (module.exports = {
|
|
253
|
+
CacheData,
|
|
254
|
+
MakeswiftHostApiClient
|
|
255
|
+
});
|
|
256
|
+
//# sourceMappingURL=react.js.map
|
|
@@ -0,0 +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'\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,mBAAmB,eAAe;AAAA,MAC1D,iBAAiB;AAAA,MACjB,eAAe;AAAA,IACjB,CAAC;AACD,SAAK,QAAQ;AACb,SAAK,YAAY,KAAK,mBAAmB;AAAA,EAC3C;AAAA,EAEA,WAAW,UAAiC;AAC1C,WAAO,mBAAmB;AAAA,MACxB,KAAK,mBAAmB,SAAS;AAAA,MACjC,6BAAgB;AAAA,MAChB;AAAA,IACF;AAAA,EACF;AAAA,EAEA,MAAM,YAAY,UAA0C;AAC1D,WAAO,MAAM,KAAK,mBAAmB;AAAA,MACnC,mBAAmB,iBAAiB,6BAAgB,QAAQ,UAAU,KAAK,KAAK;AAAA,IAClF;AAAA,EACF;AAAA,EAEA,cAAc,UAA6D;AACzE,WAAO,KAAK,gBAAgB,6BAAgB,QAAQ;AAAA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BAAgB;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.27.
|
|
31
|
+
version: "0.27.2",
|
|
32
32
|
interactionMode: true,
|
|
33
33
|
clientSideNavigation: false,
|
|
34
34
|
elementFromPoint: false,
|
package/dist/cjs/client/index.js
CHANGED
|
@@ -210,7 +210,7 @@ Received "${apiKey}" instead.`
|
|
|
210
210
|
}
|
|
211
211
|
this.apiKey = apiKey;
|
|
212
212
|
this.graphqlClient = new import_client.GraphQLClient(new URL("graphql", runtime.apiOrigin).href, {
|
|
213
|
-
"makeswift-runtime-version": "0.27.
|
|
213
|
+
"makeswift-runtime-version": "0.27.2"
|
|
214
214
|
});
|
|
215
215
|
this.runtime = runtime;
|
|
216
216
|
}
|
|
@@ -222,7 +222,7 @@ Received "${apiKey}" instead.`
|
|
|
222
222
|
const requestHeaders = new Headers({
|
|
223
223
|
"x-api-key": this.apiKey,
|
|
224
224
|
"makeswift-site-api-key": this.apiKey,
|
|
225
|
-
"makeswift-runtime-version": "0.27.
|
|
225
|
+
"makeswift-runtime-version": "0.27.2"
|
|
226
226
|
});
|
|
227
227
|
if (siteVersion?.token) {
|
|
228
228
|
requestUrl.searchParams.set("version", siteVersion.version);
|
|
@@ -680,7 +680,7 @@ Received "${apiKey}" instead.`
|
|
|
680
680
|
headers: {
|
|
681
681
|
"x-api-key": this.apiKey,
|
|
682
682
|
"makeswift-site-api-key": this.apiKey,
|
|
683
|
-
"makeswift-runtime-version": "0.27.
|
|
683
|
+
"makeswift-runtime-version": "0.27.2",
|
|
684
684
|
"content-type": "application/json"
|
|
685
685
|
},
|
|
686
686
|
body: JSON.stringify({ token }),
|
|
@@ -52,13 +52,22 @@ async function config({
|
|
|
52
52
|
},
|
|
53
53
|
customRoutes: async (route) => {
|
|
54
54
|
if (route === "/redirect-preview") {
|
|
55
|
-
const request = req instanceof import_server.NextRequest ? req :
|
|
55
|
+
const request = req instanceof import_server.NextRequest ? req : requestToNextRequest(req);
|
|
56
56
|
return { res: await (0, import_app_router_redirect_preview.appRouterRedirectPreviewHandler)(request, context, client) };
|
|
57
57
|
}
|
|
58
58
|
return null;
|
|
59
59
|
}
|
|
60
60
|
};
|
|
61
61
|
}
|
|
62
|
+
const requestToNextRequest = (req) => {
|
|
63
|
+
const hasBody = req.method !== "GET" && req.method !== "HEAD";
|
|
64
|
+
return new import_server.NextRequest(req.url, {
|
|
65
|
+
method: req.method,
|
|
66
|
+
headers: req.headers,
|
|
67
|
+
signal: req.signal,
|
|
68
|
+
...hasBody && { body: req.body, duplex: "half" }
|
|
69
|
+
});
|
|
70
|
+
};
|
|
62
71
|
// Annotate the CommonJS export names for ESM import in node:
|
|
63
72
|
0 && (module.exports = {
|
|
64
73
|
argsPattern,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/next/api-handler/config/app-router.ts"],"sourcesContent":["import { P } from 'ts-pattern'\nimport { revalidatePath, revalidateTag } from 'next/cache'\nimport { NextRequest } from 'next/server'\n\nimport { MAKESWIFT_CACHE_TAG } from '../../cache'\nimport { type ApiResponse } from '../../../api-handler/request-response'\n\nimport { appRouterRedirectPreviewHandler } from '../handlers/app-router-redirect-preview'\nimport { MAKESWIFT_SITE_VERSION_COOKIE, PRERENDER_BYPASS_COOKIE } from '../preview'\n\nimport { validateApiRoute, type ApiHandlerConfig } from './base'\nimport { MakeswiftClient } from '../../../client'\n\ntype Params = { [key: string]: string | string[] }\ntype Context = { params: Promise<Params> }\n\n// In older versions of Next (prior to 15.5.0), the inbound request is typed as\n// a `NextRequest`, but requests received at runtime fail the `instanceof\n// NextRequest` check. In newer versions of Next, requests are correctly typed\n// as `NextRequest`. To maintain compatibility across all Next.js versions, we\n// match against both.\nexport type ApiHandlerArgs = [NextRequest | Request, Context]\nexport const argsPattern = [\n P.union(P.instanceOf(Request), P.instanceOf(NextRequest)),\n P.any,\n] as const\n\nexport async function config({\n req,\n context,\n client,\n}: {\n req: NextRequest | Request\n context: Context\n client: MakeswiftClient\n}): Promise<ApiHandlerConfig> {\n return {\n req,\n route: validateApiRoute(await context.params),\n previewCookieNames: [PRERENDER_BYPASS_COOKIE, MAKESWIFT_SITE_VERSION_COOKIE],\n sendResponse: async (res: ApiResponse): Promise<Response | void> => res,\n revalidationHandler: async (path?: string): Promise<void> => {\n if (path != null) {\n revalidatePath(path)\n } else {\n revalidateTag(MAKESWIFT_CACHE_TAG)\n }\n },\n customRoutes: async (route: string) => {\n if (route === '/redirect-preview') {\n // Convert any Request to NextRequest,
|
|
1
|
+
{"version":3,"sources":["../../../../../src/next/api-handler/config/app-router.ts"],"sourcesContent":["import { P } from 'ts-pattern'\nimport { revalidatePath, revalidateTag } from 'next/cache'\nimport { NextRequest } from 'next/server'\n\nimport { MAKESWIFT_CACHE_TAG } from '../../cache'\nimport { type ApiResponse } from '../../../api-handler/request-response'\n\nimport { appRouterRedirectPreviewHandler } from '../handlers/app-router-redirect-preview'\nimport { MAKESWIFT_SITE_VERSION_COOKIE, PRERENDER_BYPASS_COOKIE } from '../preview'\n\nimport { validateApiRoute, type ApiHandlerConfig } from './base'\nimport { MakeswiftClient } from '../../../client'\n\ntype Params = { [key: string]: string | string[] }\ntype Context = { params: Promise<Params> }\n\n// In older versions of Next (prior to 15.5.0), the inbound request is typed as\n// a `NextRequest`, but requests received at runtime fail the `instanceof\n// NextRequest` check. In newer versions of Next, requests are correctly typed\n// as `NextRequest`. To maintain compatibility across all Next.js versions, we\n// match against both.\nexport type ApiHandlerArgs = [NextRequest | Request, Context]\nexport const argsPattern = [\n P.union(P.instanceOf(Request), P.instanceOf(NextRequest)),\n P.any,\n] as const\n\nexport async function config({\n req,\n context,\n client,\n}: {\n req: NextRequest | Request\n context: Context\n client: MakeswiftClient\n}): Promise<ApiHandlerConfig> {\n return {\n req,\n route: validateApiRoute(await context.params),\n previewCookieNames: [PRERENDER_BYPASS_COOKIE, MAKESWIFT_SITE_VERSION_COOKIE],\n sendResponse: async (res: ApiResponse): Promise<Response | void> => res,\n revalidationHandler: async (path?: string): Promise<void> => {\n if (path != null) {\n revalidatePath(path)\n } else {\n revalidateTag(MAKESWIFT_CACHE_TAG)\n }\n },\n customRoutes: async (route: string) => {\n if (route === '/redirect-preview') {\n // Convert any `Request` to `NextRequest` for consumption by the `appRouterRedirectPreviewHandler` call below\n const request = req instanceof NextRequest ? req : requestToNextRequest(req)\n return { res: await appRouterRedirectPreviewHandler(request, context, client) }\n }\n\n return null\n },\n }\n}\n\nconst requestToNextRequest = (req: Request): NextRequest => {\n // Because we're supporting multiple versions of Next.js, we have to account for two issues here:\n //\n // 1. https://github.com/vercel/next.js/issues/52967 for Next prior to v13.4.17 (see\n // https://github.com/vercel/next.js/commit/e1133cf0970e80d8f88e6c3516881780703eb7f5\n // and https://github.com/vercel/next.js/commit/af97755e3c62a6b786b98b98ef8e91bf3d595957),\n // which requires us to pass two arguments to the `NextRequest` constructor in order to\n // fully copy the request\n //\n // 2. https://github.com/better-auth/better-auth/issues/8194#issuecomment-3975332346 for Next 16\n // when running on Node.js 24+, which prevents us from simply passing the original request\n // as the second argument to the `NextRequest` constructor, thus the manual copying of the\n // relevant server-side properties\n\n const hasBody = req.method !== 'GET' && req.method !== 'HEAD'\n\n return new NextRequest(req.url, {\n method: req.method,\n headers: req.headers,\n signal: req.signal,\n ...(hasBody && { body: req.body, duplex: 'half' }),\n })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAAkB;AAClB,mBAA8C;AAC9C,oBAA4B;AAE5B,IAAAA,gBAAoC;AAGpC,yCAAgD;AAChD,qBAAuE;AAEvE,kBAAwD;AAYjD,MAAM,cAAc;AAAA,EACzB,oBAAE,MAAM,oBAAE,WAAW,OAAO,GAAG,oBAAE,WAAW,yBAAW,CAAC;AAAA,EACxD,oBAAE;AACJ;AAEA,eAAsB,OAAO;AAAA,EAC3B;AAAA,EACA;AAAA,EACA;AACF,GAI8B;AAC5B,SAAO;AAAA,IACL;AAAA,IACA,WAAO,8BAAiB,MAAM,QAAQ,MAAM;AAAA,IAC5C,oBAAoB,CAAC,wCAAyB,4CAA6B;AAAA,IAC3E,cAAc,OAAO,QAA+C;AAAA,IACpE,qBAAqB,OAAO,SAAiC;AAC3D,UAAI,QAAQ,MAAM;AAChB,yCAAe,IAAI;AAAA,MACrB,OAAO;AACL,wCAAc,iCAAmB;AAAA,MACnC;AAAA,IACF;AAAA,IACA,cAAc,OAAO,UAAkB;AACrC,UAAI,UAAU,qBAAqB;AAEjC,cAAM,UAAU,eAAe,4BAAc,MAAM,qBAAqB,GAAG;AAC3E,eAAO,EAAE,KAAK,UAAM,oEAAgC,SAAS,SAAS,MAAM,EAAE;AAAA,MAChF;AAEA,aAAO;AAAA,IACT;AAAA,EACF;AACF;AAEA,MAAM,uBAAuB,CAAC,QAA8B;AAc1D,QAAM,UAAU,IAAI,WAAW,SAAS,IAAI,WAAW;AAEvD,SAAO,IAAI,0BAAY,IAAI,KAAK;AAAA,IAC9B,QAAQ,IAAI;AAAA,IACZ,SAAS,IAAI;AAAA,IACb,QAAQ,IAAI;AAAA,IACZ,GAAI,WAAW,EAAE,MAAM,IAAI,MAAM,QAAQ,OAAO;AAAA,EAClD,CAAC;AACH;","names":["import_cache"]}
|
|
@@ -0,0 +1,50 @@
|
|
|
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 LiveProvider_exports = {};
|
|
30
|
+
__export(LiveProvider_exports, {
|
|
31
|
+
default: () => LiveProvider
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(LiveProvider_exports);
|
|
34
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
35
|
+
var import_react = require("react");
|
|
36
|
+
var ReactPage = __toESM(require("../../../state/react-page"));
|
|
37
|
+
var import_use_react_runtime = require("../hooks/use-react-runtime");
|
|
38
|
+
var import_use_store = require("../hooks/use-store");
|
|
39
|
+
function LiveProvider({ children }) {
|
|
40
|
+
const runtime = (0, import_use_react_runtime.useReactRuntime)();
|
|
41
|
+
const store = (0, import_react.useMemo)(
|
|
42
|
+
() => ReactPage.configureStore({
|
|
43
|
+
name: "Host store",
|
|
44
|
+
preloadedState: runtime.store.getState()
|
|
45
|
+
}),
|
|
46
|
+
[runtime]
|
|
47
|
+
);
|
|
48
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_use_store.StoreContext.Provider, { value: store, children });
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=LiveProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/runtimes/react/components/LiveProvider.tsx"],"sourcesContent":["import { type PropsWithChildren, useMemo, ReactNode } from 'react'\n\nimport * as ReactPage from '../../../state/react-page'\n\nimport { useReactRuntime } from '../hooks/use-react-runtime'\nimport { StoreContext } from '../hooks/use-store'\n\nexport default function LiveProvider({ children }: PropsWithChildren): ReactNode {\n const runtime = useReactRuntime()\n const store = useMemo(\n () =>\n ReactPage.configureStore({\n name: 'Host store',\n preloadedState: runtime.store.getState(),\n }),\n [runtime],\n )\n\n return <StoreContext.Provider value={store}>{children}</StoreContext.Provider>\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAkBS;AAlBT,mBAA2D;AAE3D,gBAA2B;AAE3B,+BAAgC;AAChC,uBAA6B;AAEd,SAAR,aAA8B,EAAE,SAAS,GAAiC;AAC/E,QAAM,cAAU,0CAAgB;AAChC,QAAM,YAAQ;AAAA,IACZ,MACE,UAAU,eAAe;AAAA,MACvB,MAAM;AAAA,MACN,gBAAgB,QAAQ,MAAM,SAAS;AAAA,IACzC,CAAC;AAAA,IACH,CAAC,OAAO;AAAA,EACV;AAEA,SAAO,4CAAC,8BAAa,UAAb,EAAsB,OAAO,OAAQ,UAAS;AACxD;","names":[]}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use client";
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from))
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
+
mod
|
|
28
|
+
));
|
|
29
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
+
var PreviewProvider_exports = {};
|
|
31
|
+
__export(PreviewProvider_exports, {
|
|
32
|
+
default: () => PreviewProvider
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(PreviewProvider_exports);
|
|
35
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
36
|
+
var import_react = require("react");
|
|
37
|
+
var ReactBuilderPreview = __toESM(require("../../../state/react-builder-preview"));
|
|
38
|
+
var import_proxy = require("../../../state/builder-api/proxy");
|
|
39
|
+
var import_use_react_runtime = require("../hooks/use-react-runtime");
|
|
40
|
+
var import_use_store = require("../hooks/use-store");
|
|
41
|
+
var import_host_api_client = require("../host-api-client");
|
|
42
|
+
function PreviewProvider({
|
|
43
|
+
appOrigin,
|
|
44
|
+
children
|
|
45
|
+
}) {
|
|
46
|
+
const runtime = (0, import_use_react_runtime.useReactRuntime)();
|
|
47
|
+
const client = (0, import_host_api_client.useMakeswiftHostApiClient)();
|
|
48
|
+
const builderProxy = (0, import_react.useMemo)(() => new import_proxy.BuilderAPIProxy({ appOrigin }), [appOrigin]);
|
|
49
|
+
const store = (0, import_react.useMemo)(
|
|
50
|
+
() => ReactBuilderPreview.configureStore({
|
|
51
|
+
preloadedState: runtime.store.getState(),
|
|
52
|
+
client,
|
|
53
|
+
builderProxy
|
|
54
|
+
}),
|
|
55
|
+
[runtime, client, builderProxy]
|
|
56
|
+
);
|
|
57
|
+
(0, import_react.useEffect)(() => {
|
|
58
|
+
store.setup();
|
|
59
|
+
return () => store.teardown();
|
|
60
|
+
}, [store]);
|
|
61
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_use_store.StoreContext.Provider, { value: store, children });
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=PreviewProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/runtimes/react/components/PreviewProvider.tsx"],"sourcesContent":["'use client'\n\nimport { type PropsWithChildren, useEffect, useMemo, ReactNode } from 'react'\n\nimport * as ReactBuilderPreview from '../../../state/react-builder-preview'\nimport { BuilderAPIProxy } from '../../../state/builder-api/proxy'\n\nimport { useReactRuntime } from '../hooks/use-react-runtime'\nimport { StoreContext } from '../hooks/use-store'\nimport { useMakeswiftHostApiClient } from '../host-api-client'\n\nexport default function PreviewProvider({\n appOrigin,\n children,\n}: PropsWithChildren<{ appOrigin: string }>): ReactNode {\n const runtime = useReactRuntime()\n const client = useMakeswiftHostApiClient()\n const builderProxy = useMemo(() => new BuilderAPIProxy({ appOrigin }), [appOrigin])\n\n const store = useMemo(\n () =>\n ReactBuilderPreview.configureStore({\n preloadedState: runtime.store.getState(),\n client,\n builderProxy,\n }),\n [runtime, client, builderProxy],\n )\n\n useEffect(() => {\n store.setup()\n return () => store.teardown()\n }, [store])\n\n return <StoreContext.Provider value={store}>{children}</StoreContext.Provider>\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAkCS;AAhCT,mBAAsE;AAEtE,0BAAqC;AACrC,mBAAgC;AAEhC,+BAAgC;AAChC,uBAA6B;AAC7B,6BAA0C;AAE3B,SAAR,gBAAiC;AAAA,EACtC;AAAA,EACA;AACF,GAAwD;AACtD,QAAM,cAAU,0CAAgB;AAChC,QAAM,aAAS,kDAA0B;AACzC,QAAM,mBAAe,sBAAQ,MAAM,IAAI,6BAAgB,EAAE,UAAU,CAAC,GAAG,CAAC,SAAS,CAAC;AAElF,QAAM,YAAQ;AAAA,IACZ,MACE,oBAAoB,eAAe;AAAA,MACjC,gBAAgB,QAAQ,MAAM,SAAS;AAAA,MACvC;AAAA,MACA;AAAA,IACF,CAAC;AAAA,IACH,CAAC,SAAS,QAAQ,YAAY;AAAA,EAChC;AAEA,8BAAU,MAAM;AACd,UAAM,MAAM;AACZ,WAAO,MAAM,MAAM,SAAS;AAAA,EAC9B,GAAG,CAAC,KAAK,CAAC;AAEV,SAAO,4CAAC,8BAAa,UAAb,EAAsB,OAAO,OAAQ,UAAS;AACxD;","names":[]}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
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 use_builder_connection_ping_exports = {};
|
|
20
|
+
__export(use_builder_connection_ping_exports, {
|
|
21
|
+
useBuilderConnectionPing: () => useBuilderConnectionPing
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(use_builder_connection_ping_exports);
|
|
24
|
+
var import_react = require("react");
|
|
25
|
+
var import_actions = require("../../../../state/builder-api/actions");
|
|
26
|
+
var import_shared_api = require("../../../../state/shared-api");
|
|
27
|
+
const CONNECTION_PING_INTERVAL_MS = 20;
|
|
28
|
+
function useBuilderConnectionPing({ appOrigin }) {
|
|
29
|
+
(0, import_react.useEffect)(() => {
|
|
30
|
+
let connectionInterval;
|
|
31
|
+
if (window.parent !== window) {
|
|
32
|
+
window.addEventListener("message", messageHandler);
|
|
33
|
+
window.parent.postMessage((0, import_shared_api.makeswiftConnectionInit)(), { targetOrigin: appOrigin });
|
|
34
|
+
}
|
|
35
|
+
return () => {
|
|
36
|
+
window.removeEventListener("message", messageHandler);
|
|
37
|
+
if (connectionInterval != null) {
|
|
38
|
+
window.clearInterval(connectionInterval);
|
|
39
|
+
connectionInterval = null;
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
function messageHandler(event) {
|
|
43
|
+
if (event.origin === appOrigin && event.data.type === import_shared_api.SharedActionTypes.MAKESWIFT_CONNECTION_INIT) {
|
|
44
|
+
if (connectionInterval != null) {
|
|
45
|
+
window.clearInterval(connectionInterval);
|
|
46
|
+
connectionInterval = null;
|
|
47
|
+
}
|
|
48
|
+
connectionInterval = window.setInterval(() => {
|
|
49
|
+
window.parent.postMessage(
|
|
50
|
+
(0, import_actions.makeswiftConnectionCheck)({ currentUrl: window.location.href }),
|
|
51
|
+
{ targetOrigin: appOrigin }
|
|
52
|
+
);
|
|
53
|
+
}, CONNECTION_PING_INTERVAL_MS);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}, [appOrigin]);
|
|
57
|
+
}
|
|
58
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
59
|
+
0 && (module.exports = {
|
|
60
|
+
useBuilderConnectionPing
|
|
61
|
+
});
|
|
62
|
+
//# sourceMappingURL=use-builder-connection-ping.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../../src/runtimes/react/components/hooks/use-builder-connection-ping.ts"],"sourcesContent":["import { useEffect } from 'react'\nimport { makeswiftConnectionCheck } from '../../../../state/builder-api/actions'\nimport { SharedActionTypes, makeswiftConnectionInit } from '../../../../state/shared-api'\n\nconst CONNECTION_PING_INTERVAL_MS = 20\n\nexport function useBuilderConnectionPing({ appOrigin }: { appOrigin: string }) {\n useEffect(() => {\n let connectionInterval: number | null\n\n if (window.parent !== window) {\n window.addEventListener('message', messageHandler)\n window.parent.postMessage(makeswiftConnectionInit(), { targetOrigin: appOrigin })\n }\n\n return () => {\n window.removeEventListener('message', messageHandler)\n if (connectionInterval != null) {\n window.clearInterval(connectionInterval)\n connectionInterval = null\n }\n }\n\n function messageHandler(event: MessageEvent): void {\n if (\n event.origin === appOrigin &&\n event.data.type === SharedActionTypes.MAKESWIFT_CONNECTION_INIT\n ) {\n if (connectionInterval != null) {\n window.clearInterval(connectionInterval)\n connectionInterval = null\n }\n\n connectionInterval = window.setInterval(() => {\n window.parent.postMessage(\n makeswiftConnectionCheck({ currentUrl: window.location.href }),\n { targetOrigin: appOrigin },\n )\n }, CONNECTION_PING_INTERVAL_MS)\n }\n }\n }, [appOrigin])\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAA0B;AAC1B,qBAAyC;AACzC,wBAA2D;AAE3D,MAAM,8BAA8B;AAE7B,SAAS,yBAAyB,EAAE,UAAU,GAA0B;AAC7E,8BAAU,MAAM;AACd,QAAI;AAEJ,QAAI,OAAO,WAAW,QAAQ;AAC5B,aAAO,iBAAiB,WAAW,cAAc;AACjD,aAAO,OAAO,gBAAY,2CAAwB,GAAG,EAAE,cAAc,UAAU,CAAC;AAAA,IAClF;AAEA,WAAO,MAAM;AACX,aAAO,oBAAoB,WAAW,cAAc;AACpD,UAAI,sBAAsB,MAAM;AAC9B,eAAO,cAAc,kBAAkB;AACvC,6BAAqB;AAAA,MACvB;AAAA,IACF;AAEA,aAAS,eAAe,OAA2B;AACjD,UACE,MAAM,WAAW,aACjB,MAAM,KAAK,SAAS,oCAAkB,2BACtC;AACA,YAAI,sBAAsB,MAAM;AAC9B,iBAAO,cAAc,kBAAkB;AACvC,+BAAqB;AAAA,QACvB;AAEA,6BAAqB,OAAO,YAAY,MAAM;AAC5C,iBAAO,OAAO;AAAA,gBACZ,yCAAyB,EAAE,YAAY,OAAO,SAAS,KAAK,CAAC;AAAA,YAC7D,EAAE,cAAc,UAAU;AAAA,UAC5B;AAAA,QACF,GAAG,2BAA2B;AAAA,MAChC;AAAA,IACF;AAAA,EACF,GAAG,CAAC,SAAS,CAAC;AAChB;","names":[]}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
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 use_is_preview_exports = {};
|
|
20
|
+
__export(use_is_preview_exports, {
|
|
21
|
+
useIsPreview: () => useIsPreview
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(use_is_preview_exports);
|
|
24
|
+
var import_react_page = require("../../../state/react-page");
|
|
25
|
+
var import_use_selector = require("./use-selector");
|
|
26
|
+
function useIsPreview() {
|
|
27
|
+
return (0, import_use_selector.useSelector)((state) => (0, import_react_page.getIsPreview)(state));
|
|
28
|
+
}
|
|
29
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
30
|
+
0 && (module.exports = {
|
|
31
|
+
useIsPreview
|
|
32
|
+
});
|
|
33
|
+
//# sourceMappingURL=use-is-preview.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/runtimes/react/hooks/use-is-preview.ts"],"sourcesContent":["import { getIsPreview } from '../../../state/react-page'\nimport { useSelector } from './use-selector'\n\nexport function useIsPreview(): boolean {\n return useSelector(state => getIsPreview(state))\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAA6B;AAC7B,0BAA4B;AAErB,SAAS,eAAwB;AACtC,aAAO,iCAAY,eAAS,gCAAa,KAAK,CAAC;AACjD;","names":[]}
|