@backmatter/next 0.0.43 → 0.0.45
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/package.json +3 -3
- package/src/cms-proxy.ts +15 -2
- package/src/preview-refresh.tsx +12 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@backmatter/next",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.45",
|
|
4
4
|
"description": "Experimental Next.js adapter for Backmatter. APIs will break. Not ready for production.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"publishConfig": {
|
|
@@ -47,10 +47,10 @@
|
|
|
47
47
|
"test": "bun test"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@backmatter/core": "^0.0.
|
|
50
|
+
"@backmatter/core": "^0.0.38",
|
|
51
51
|
"@mdx-js/mdx": "^3.1.1",
|
|
52
52
|
"remark-gfm": "^4.0.1",
|
|
53
|
-
"@backmatter/studio": "^0.0.
|
|
53
|
+
"@backmatter/studio": "^0.0.22"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
56
|
"next": ">=16.3.0",
|
package/src/cms-proxy.ts
CHANGED
|
@@ -43,10 +43,20 @@ const ALLOWED: Array<{ method: string; pattern: RegExp }> = [
|
|
|
43
43
|
{ method: "POST", pattern: new RegExp(`^${WS}/ai/threads/[^/]+/messages$`) },
|
|
44
44
|
{ method: "POST", pattern: new RegExp(`^${WS}/ai/threads/[^/]+/messages/[^/]+/changes/(keep-all|undo-all)$`) },
|
|
45
45
|
{ method: "POST", pattern: new RegExp(`^${WS}/ai/changes/[^/]+/(keep|undo)$`) },
|
|
46
|
+
{ method: "POST", pattern: new RegExp(`^${WS}/ai/chat-files$`) },
|
|
47
|
+
{ method: "GET", pattern: new RegExp(`^${WS}/ai/chat-files/[^/]+$`) },
|
|
48
|
+
{ method: "GET", pattern: new RegExp(`^${WS}/ai/threads/[^/]+/files$`) },
|
|
46
49
|
{ method: "GET", pattern: /^\/preview\/session$/ },
|
|
47
50
|
{ method: "POST", pattern: /^\/preview\/session\/renew$/ },
|
|
48
51
|
];
|
|
49
52
|
|
|
53
|
+
const PASSED_RESPONSE_HEADERS = [
|
|
54
|
+
"content-type",
|
|
55
|
+
"content-disposition",
|
|
56
|
+
"content-security-policy",
|
|
57
|
+
"x-content-type-options",
|
|
58
|
+
];
|
|
59
|
+
|
|
50
60
|
export function cmsProxyAllowed(method: string, path: string): boolean {
|
|
51
61
|
return ALLOWED.some((rule) => rule.method === method && rule.pattern.test(path));
|
|
52
62
|
}
|
|
@@ -158,8 +168,11 @@ export function createCmsProxy(
|
|
|
158
168
|
body: hasBody ? await req.arrayBuffer() : undefined,
|
|
159
169
|
});
|
|
160
170
|
const responseHeaders = new Headers();
|
|
161
|
-
|
|
162
|
-
|
|
171
|
+
// A chat file is served on the site's origin, so its sandboxing must survive.
|
|
172
|
+
for (const name of PASSED_RESPONSE_HEADERS) {
|
|
173
|
+
const value = res.headers.get(name);
|
|
174
|
+
if (value) responseHeaders.set(name, value);
|
|
175
|
+
}
|
|
163
176
|
responseHeaders.set("Cache-Control", "no-store");
|
|
164
177
|
return new Response(res.body, { status: res.status, headers: responseHeaders });
|
|
165
178
|
};
|
package/src/preview-refresh.tsx
CHANGED
|
@@ -193,7 +193,19 @@ export function PreviewClient({
|
|
|
193
193
|
if (target.closest("[data-backmatter-panel]")) return true;
|
|
194
194
|
return target.closest("iframe") !== null;
|
|
195
195
|
},
|
|
196
|
+
// A click outside a marked block still reaches the editor as a
|
|
197
|
+
// document-level pointer with its text.
|
|
198
|
+
includeUnmarked: true,
|
|
196
199
|
onEditorGrab: (grab) => session.grab(grab),
|
|
200
|
+
onUnmarkedGrab: (grab) =>
|
|
201
|
+
session.grab({
|
|
202
|
+
blockId: null,
|
|
203
|
+
blockType: null,
|
|
204
|
+
blockIndex: null,
|
|
205
|
+
quote: grab.quote,
|
|
206
|
+
shift: grab.shift,
|
|
207
|
+
...(grab.field ? { field: grab.field } : {}),
|
|
208
|
+
}),
|
|
197
209
|
onDevbarGrab: (grab) => {
|
|
198
210
|
window.dispatchEvent(new CustomEvent("backmatter:devbar-grab", { detail: grab }));
|
|
199
211
|
},
|