@alpaca-headless/alpaca-headless-nextjs 1.0.3390 → 1.0.3398
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/.eslintrc.json +3 -0
- package/README.md +36 -0
- package/dist/EditorIntegration.d.ts +6 -0
- package/dist/EditorIntegration.js +5 -0
- package/dist/EditorIntegrationClient.d.ts +9 -0
- package/dist/EditorIntegrationClient.js +54 -0
- package/dist/client-components/MultiComponentEditor.d.ts +12 -0
- package/dist/client-components/MultiComponentEditor.js +47 -0
- package/dist/client-components/index.d.ts +1 -0
- package/dist/client-components/index.js +2 -0
- package/dist/handleBasicAuthRoute.d.ts +8 -0
- package/dist/handleBasicAuthRoute.js +42 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +11 -0
- package/dist/middleware/handleRequest.d.ts +8 -0
- package/dist/middleware/handleRequest.js +42 -0
- package/dist/middleware/index.d.ts +1 -0
- package/dist/middleware/index.js +1 -0
- package/dist/proxy/index.d.ts +8 -0
- package/dist/proxy/index.js +77 -0
- package/dist/useExposeRefreshFunction.d.ts +7 -0
- package/dist/useExposeRefreshFunction.js +32 -0
- package/next.config.mjs +4 -0
- package/package.json +51 -29
- package/postcss.config.js +6 -0
- package/src/EditorIntegration.tsx +11 -0
- package/src/EditorIntegrationClient.tsx +74 -0
- package/src/client-components/MultiComponentEditor.tsx +133 -0
- package/src/client-components/index.ts +3 -0
- package/src/handleBasicAuthRoute.ts +62 -0
- package/src/index.ts +15 -0
- package/src/middleware/handleRequest.ts +62 -0
- package/src/middleware/index.ts +1 -0
- package/src/proxy/index.ts +108 -0
- package/src/useExposeRefreshFunction.ts +45 -0
- package/tailwind.config.js +17 -0
- package/tailwind.config.ts +20 -0
- package/tsconfig.json +26 -0
- package/dist/cjs/alpacaContext.js +0 -12
- package/dist/cjs/components/Image.js +0 -36
- package/dist/cjs/components/Link.js +0 -22
- package/dist/cjs/components/Picture.js +0 -116
- package/dist/cjs/components/Placeholder.js +0 -55
- package/dist/cjs/components/RichText.js +0 -42
- package/dist/cjs/components/Text.js +0 -39
- package/dist/cjs/components/index.js +0 -22
- package/dist/cjs/fieldTypes.js +0 -2
- package/dist/cjs/graphQLTypes.js +0 -2
- package/dist/cjs/index.js +0 -36
- package/dist/cjs/layoutData.js +0 -2
- package/dist/cjs/loadRouteData.js +0 -114
- package/dist/cjs/mediaProtection.js +0 -56
- package/dist/esm/alpacaContext.js +0 -8
- package/dist/esm/components/Image.js +0 -32
- package/dist/esm/components/Link.js +0 -18
- package/dist/esm/components/Picture.js +0 -112
- package/dist/esm/components/Placeholder.js +0 -51
- package/dist/esm/components/RichText.js +0 -35
- package/dist/esm/components/Text.js +0 -32
- package/dist/esm/components/index.js +0 -6
- package/dist/esm/fieldTypes.js +0 -1
- package/dist/esm/graphQLTypes.js +0 -1
- package/dist/esm/index.js +0 -7
- package/dist/esm/layoutData.js +0 -1
- package/dist/esm/loadRouteData.js +0 -110
- package/dist/esm/mediaProtection.js +0 -49
- package/next.config.js +0 -6
- package/types/alpacaContext.d.ts +0 -19
- package/types/components/Image.d.ts +0 -10
- package/types/components/Link.d.ts +0 -6
- package/types/components/Picture.d.ts +0 -20
- package/types/components/Placeholder.d.ts +0 -5
- package/types/components/RichText.d.ts +0 -282
- package/types/components/Text.d.ts +0 -278
- package/types/components/index.d.ts +0 -6
- package/types/fieldTypes.d.ts +0 -62
- package/types/graphQLTypes.d.ts +0 -26
- package/types/index.d.ts +0 -7
- package/types/layoutData.d.ts +0 -11
- package/types/loadRouteData.d.ts +0 -36
- package/types/mediaProtection.d.ts +0 -2
package/.eslintrc.json
ADDED
package/README.md
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).
|
|
2
|
+
|
|
3
|
+
## Getting Started
|
|
4
|
+
|
|
5
|
+
First, run the development server:
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm run dev
|
|
9
|
+
# or
|
|
10
|
+
yarn dev
|
|
11
|
+
# or
|
|
12
|
+
pnpm dev
|
|
13
|
+
# or
|
|
14
|
+
bun dev
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
|
|
18
|
+
|
|
19
|
+
You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.
|
|
20
|
+
|
|
21
|
+
This project uses [`next/font`](https://nextjs.org/docs/basic-features/font-optimization) to automatically optimize and load Inter, a custom Google Font.
|
|
22
|
+
|
|
23
|
+
## Learn More
|
|
24
|
+
|
|
25
|
+
To learn more about Next.js, take a look at the following resources:
|
|
26
|
+
|
|
27
|
+
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
|
|
28
|
+
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
|
|
29
|
+
|
|
30
|
+
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!
|
|
31
|
+
|
|
32
|
+
## Deploy on Vercel
|
|
33
|
+
|
|
34
|
+
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
|
|
35
|
+
|
|
36
|
+
Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
import { useEffect } from "react";
|
|
4
|
+
import useExposeRefreshFunction from "./useExposeRefreshFunction";
|
|
5
|
+
export function EditorIntegrationClient({ timings, }) {
|
|
6
|
+
useExposeRefreshFunction();
|
|
7
|
+
useEffect(() => {
|
|
8
|
+
const handleKeyDown = (event) => {
|
|
9
|
+
if (event.ctrlKey && event.key === "F11") {
|
|
10
|
+
event.preventDefault();
|
|
11
|
+
window.parent.postMessage({ type: "editor-exitFullscreen" }, "*");
|
|
12
|
+
}
|
|
13
|
+
if (event.key === "F2") {
|
|
14
|
+
event.preventDefault();
|
|
15
|
+
window.parent.postMessage({ type: "editor-keyDown", key: "F2" }, "*");
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
window.addEventListener("keydown", handleKeyDown);
|
|
19
|
+
window.parent.postMessage({ type: "editor-timings", timings }, "*");
|
|
20
|
+
return () => {
|
|
21
|
+
window.removeEventListener("keydown", handleKeyDown);
|
|
22
|
+
};
|
|
23
|
+
}, []);
|
|
24
|
+
return (_jsx(_Fragment, { children: _jsx("style", { children: `
|
|
25
|
+
.a-editor-mce {
|
|
26
|
+
display:flex;
|
|
27
|
+
gap: 10px;
|
|
28
|
+
padding: 30px;
|
|
29
|
+
background-color: #f5f5f5;
|
|
30
|
+
flex-wrap: wrap;
|
|
31
|
+
align-items: center;
|
|
32
|
+
}
|
|
33
|
+
.a-editor-mce-thumbnail {
|
|
34
|
+
display:grid;
|
|
35
|
+
padding: 10px;
|
|
36
|
+
place-items: center;
|
|
37
|
+
overflow: hidden;
|
|
38
|
+
}
|
|
39
|
+
.a-editor-mce-thumbnail--selected {
|
|
40
|
+
box-shadow: 0 0 3px 3px rgb(75 89 255 / 50%);
|
|
41
|
+
}
|
|
42
|
+
.a-editor-mce-thumbnail:hover {
|
|
43
|
+
box-shadow: 0 0 10px 5px rgba(0, 0, 0, 0.5);
|
|
44
|
+
}
|
|
45
|
+
[contentEditable]:empty:before {
|
|
46
|
+
content: attr(placeholder);
|
|
47
|
+
opacity: 0.6;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
[contenteditable] {
|
|
51
|
+
outline: 0px solid transparent;
|
|
52
|
+
}
|
|
53
|
+
` }) }));
|
|
54
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ComponentData } from "@alpaca-headless/alpaca-headless";
|
|
2
|
+
import { ReactNode } from "react";
|
|
3
|
+
interface MultiComponentEditorProps {
|
|
4
|
+
children: ReactNode;
|
|
5
|
+
component: ComponentData;
|
|
6
|
+
placeholderName: string;
|
|
7
|
+
thumbZoom?: number;
|
|
8
|
+
thumbWidth?: string;
|
|
9
|
+
thumbHeight?: string;
|
|
10
|
+
}
|
|
11
|
+
export declare function MultiComponentEditor({ children, component, placeholderName, thumbZoom, thumbWidth, thumbHeight, }: MultiComponentEditorProps): import("react/jsx-runtime").JSX.Element | undefined;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
import React, { useState, useEffect, Fragment, useCallback, } from "react";
|
|
4
|
+
export function MultiComponentEditor({ children, component, placeholderName, thumbZoom, thumbWidth = "200px", thumbHeight = "112px", }) {
|
|
5
|
+
const [selectedId, setSelectedId] = useState(null);
|
|
6
|
+
const placeholder = component.placeholders.find((x) => x.name === placeholderName);
|
|
7
|
+
if (!placeholder)
|
|
8
|
+
return;
|
|
9
|
+
const components = placeholder.components;
|
|
10
|
+
if (!components)
|
|
11
|
+
return;
|
|
12
|
+
const handleMessage = useCallback((event) => {
|
|
13
|
+
if (event.data.type === "componentsSelected") {
|
|
14
|
+
setSelectedId(event.data.componentIds[0]);
|
|
15
|
+
}
|
|
16
|
+
}, [components]);
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
window.addEventListener("message", handleMessage);
|
|
19
|
+
return () => {
|
|
20
|
+
window.removeEventListener("message", handleMessage);
|
|
21
|
+
};
|
|
22
|
+
}, []);
|
|
23
|
+
const selectedIndex = components.findIndex((x) => x.id === selectedId);
|
|
24
|
+
const childrenArray = React.Children.toArray(children);
|
|
25
|
+
const filteredChildren = childrenArray.filter((child) => child.type !== "script");
|
|
26
|
+
return (_jsxs(_Fragment, { children: [filteredChildren[selectedIndex < 0 ? 0 : selectedIndex], _jsxs("div", { className: "a-editor-mce", children: [_jsx("script", { "data-placeholder-start": placeholder.key, "data-orientation": "horizontal" }), filteredChildren.map((x, index) => thumbnail(x, index)), _jsx("script", { "data-placeholder-end": placeholder.key })] })] }));
|
|
27
|
+
function thumbnail(x, index) {
|
|
28
|
+
var _a, _b, _c, _d, _e;
|
|
29
|
+
const style = {};
|
|
30
|
+
if (thumbHeight) {
|
|
31
|
+
style.height = thumbHeight;
|
|
32
|
+
}
|
|
33
|
+
if (thumbWidth) {
|
|
34
|
+
style.width = thumbWidth;
|
|
35
|
+
}
|
|
36
|
+
const componentArray = (_a = x.props) === null || _a === void 0 ? void 0 : _a.children;
|
|
37
|
+
const component = components[index];
|
|
38
|
+
return (_jsxs(Fragment, { children: [_jsxs("div", { className: "a-editor-mce-thumbnail" +
|
|
39
|
+
(index === selectedIndex ? " a-editor-mce-thumbnail--selected" : ""), style: style, onClick: () => {
|
|
40
|
+
selectComponents([components[index].id]);
|
|
41
|
+
}, children: [_jsx("script", { "data-component-start": component.id, "data-itemid": ((_c = (_b = component._editor) === null || _b === void 0 ? void 0 : _b.linkedComponentItem) === null || _c === void 0 ? void 0 : _c.id) || component.id, "data-layoutid": (_e = (_d = component._editor) === null || _d === void 0 ? void 0 : _d.hostingPageItem) === null || _e === void 0 ? void 0 : _e.id }), _jsx("div", { style: { pointerEvents: "none", zoom: thumbZoom || 0.25 }, children: componentArray.slice(1, -1) }), _jsx("script", { "data-component-end": component.id })] }), _jsx("div", { "data-dropzone": components[index].id })] }, index));
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
function selectComponents(componentIds) {
|
|
45
|
+
var _a;
|
|
46
|
+
(_a = window.top) === null || _a === void 0 ? void 0 : _a.window.postMessage({ componentIds, type: "componentsSelected" }, "*");
|
|
47
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { MultiComponentEditor } from "./MultiComponentEditor";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ApiConfig, RenderOptions } from "@alpaca-headless/alpaca-headless";
|
|
2
|
+
import { NextRequest } from "next/server";
|
|
3
|
+
export declare function handleBasicAuthRoute({ request, mapHost, renderOptions, apiConfig, }: {
|
|
4
|
+
request: NextRequest;
|
|
5
|
+
mapHost: (host: string) => string;
|
|
6
|
+
renderOptions: RenderOptions;
|
|
7
|
+
apiConfig?: ApiConfig;
|
|
8
|
+
}): Promise<Response | undefined>;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { resolveRoute, } from "@alpaca-headless/alpaca-headless";
|
|
2
|
+
import { getApiHeaders } from ".";
|
|
3
|
+
export async function handleBasicAuthRoute({ request, mapHost, renderOptions, apiConfig, }) {
|
|
4
|
+
const urlSearchParams = new URLSearchParams(request.nextUrl.search);
|
|
5
|
+
const nextSearchParams = {};
|
|
6
|
+
for (const [key, value] of urlSearchParams.entries()) {
|
|
7
|
+
nextSearchParams[key] = value;
|
|
8
|
+
}
|
|
9
|
+
const config = apiConfig || {};
|
|
10
|
+
if (!config.headers) {
|
|
11
|
+
config.headers = getApiHeaders();
|
|
12
|
+
}
|
|
13
|
+
const routeData = await resolveRoute({
|
|
14
|
+
path: request.nextUrl.pathname,
|
|
15
|
+
searchParams: nextSearchParams,
|
|
16
|
+
host: mapHost(request.headers.get("host") || ""),
|
|
17
|
+
renderOptions,
|
|
18
|
+
renderings: {},
|
|
19
|
+
apiConfig: config,
|
|
20
|
+
});
|
|
21
|
+
if (routeData.result.type === "redirect") {
|
|
22
|
+
return new Response(null, {
|
|
23
|
+
status: routeData.result.redirectType === "permanent" ? 301 : 302,
|
|
24
|
+
headers: {
|
|
25
|
+
Location: routeData.result.location,
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
if (routeData.result.type === "unauthorized") {
|
|
30
|
+
if (routeData.result.auth)
|
|
31
|
+
return new Response(null, {
|
|
32
|
+
status: 401,
|
|
33
|
+
headers: {
|
|
34
|
+
"WWW-Authenticate": routeData.result.auth.replace(", Bearer", ""),
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
else
|
|
38
|
+
return new Response(null, {
|
|
39
|
+
status: 401,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { headers } from "next/headers";
|
|
2
|
+
export { EditorIntegration } from "./EditorIntegration";
|
|
3
|
+
export function getApiHeaders() {
|
|
4
|
+
const requestHeaders = headers();
|
|
5
|
+
const apiHeaders = new Headers();
|
|
6
|
+
apiHeaders.set("Cookie", requestHeaders.get("Cookie") || "");
|
|
7
|
+
apiHeaders.set("Authorization", requestHeaders.get("Authorization") || "");
|
|
8
|
+
return apiHeaders;
|
|
9
|
+
}
|
|
10
|
+
export { handleRequest } from "./middleware/handleRequest";
|
|
11
|
+
export { proxy } from "./proxy";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ApiConfig, RenderOptions } from "@alpaca-headless/alpaca-headless";
|
|
2
|
+
import { NextRequest } from "next/server";
|
|
3
|
+
export declare function handleRequest({ request, mapHost, renderOptions, apiConfig, }: {
|
|
4
|
+
request: NextRequest;
|
|
5
|
+
mapHost: (host: string) => string;
|
|
6
|
+
renderOptions: RenderOptions;
|
|
7
|
+
apiConfig?: ApiConfig;
|
|
8
|
+
}): Promise<Response | undefined>;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { resolveRoute, } from "@alpaca-headless/alpaca-headless";
|
|
2
|
+
import { getApiHeaders } from "..";
|
|
3
|
+
export async function handleRequest({ request, mapHost, renderOptions, apiConfig, }) {
|
|
4
|
+
const urlSearchParams = new URLSearchParams(request.nextUrl.search);
|
|
5
|
+
const nextSearchParams = {};
|
|
6
|
+
for (const [key, value] of urlSearchParams.entries()) {
|
|
7
|
+
nextSearchParams[key] = value;
|
|
8
|
+
}
|
|
9
|
+
const config = apiConfig || {};
|
|
10
|
+
if (!config.headers) {
|
|
11
|
+
config.headers = getApiHeaders();
|
|
12
|
+
}
|
|
13
|
+
const routeData = await resolveRoute({
|
|
14
|
+
path: request.nextUrl.pathname,
|
|
15
|
+
searchParams: nextSearchParams,
|
|
16
|
+
host: mapHost(request.headers.get("host") || ""),
|
|
17
|
+
renderOptions,
|
|
18
|
+
renderings: {},
|
|
19
|
+
apiConfig: config,
|
|
20
|
+
});
|
|
21
|
+
if (routeData.result.type === "redirect") {
|
|
22
|
+
return new Response(null, {
|
|
23
|
+
status: routeData.result.redirectType === "permanent" ? 301 : 302,
|
|
24
|
+
headers: {
|
|
25
|
+
Location: routeData.result.location,
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
if (routeData.result.type === "unauthorized") {
|
|
30
|
+
if (routeData.result.auth)
|
|
31
|
+
return new Response(null, {
|
|
32
|
+
status: 401,
|
|
33
|
+
headers: {
|
|
34
|
+
"WWW-Authenticate": routeData.result.auth.replace(", Bearer", ""),
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
else
|
|
38
|
+
return new Response(null, {
|
|
39
|
+
status: 401,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./handleRequest";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./handleRequest";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { NextResponse } from "next/server";
|
|
2
|
+
declare function GET(req: Request, target: string): Promise<NextResponse<unknown>>;
|
|
3
|
+
declare function POST(req: Request): Promise<NextResponse<unknown>>;
|
|
4
|
+
export declare const proxy: {
|
|
5
|
+
POST: typeof POST;
|
|
6
|
+
GET: typeof GET;
|
|
7
|
+
};
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
// import { HttpsProxyAgent } from "https-proxy-agent";
|
|
3
|
+
import { NextResponse } from "next/server";
|
|
4
|
+
async function GET(req, target
|
|
5
|
+
//{ proxy }: { proxy?: string }
|
|
6
|
+
) {
|
|
7
|
+
const reqUrl = new URL(req.url);
|
|
8
|
+
const url = target + reqUrl.pathname + "?" + reqUrl.searchParams.toString();
|
|
9
|
+
const headers = {
|
|
10
|
+
Authorization: req.headers.get("Authorization") || "",
|
|
11
|
+
Cookie: req.headers.get("Cookie") || "",
|
|
12
|
+
};
|
|
13
|
+
// const agent = proxy ? new HttpsProxyAgent(proxy) : undefined;
|
|
14
|
+
const externalResponse = await axios.get(url, {
|
|
15
|
+
headers: headers,
|
|
16
|
+
// httpAgent: agent,
|
|
17
|
+
// httpsAgent: agent,
|
|
18
|
+
responseType: "stream",
|
|
19
|
+
});
|
|
20
|
+
return new NextResponse(nodeReadableToReadableStream(externalResponse.data), {
|
|
21
|
+
status: externalResponse.status,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
async function POST(req
|
|
25
|
+
//{ proxy }: { proxy?: string }
|
|
26
|
+
) {
|
|
27
|
+
const reqUrl = new URL(req.url);
|
|
28
|
+
const body = await req.text();
|
|
29
|
+
const url = process.env.EDITOR_SERVICE_URL +
|
|
30
|
+
reqUrl.pathname +
|
|
31
|
+
"?" +
|
|
32
|
+
reqUrl.searchParams.toString();
|
|
33
|
+
const headers = {
|
|
34
|
+
"Content-Type": req.headers.get("Content-Type") || "",
|
|
35
|
+
Authorization: req.headers.get("Authorization") || "",
|
|
36
|
+
Cookie: req.headers.get("Cookie") || "",
|
|
37
|
+
};
|
|
38
|
+
// const agent = proxy ? new HttpsProxyAgent(proxy) : undefined;
|
|
39
|
+
const externalResponse = await axios.post(url, body, {
|
|
40
|
+
headers: headers,
|
|
41
|
+
// httpAgent: agent,
|
|
42
|
+
// httpsAgent: agent,
|
|
43
|
+
responseType: "stream",
|
|
44
|
+
});
|
|
45
|
+
const responseHeaders = getResponseHeaders(externalResponse);
|
|
46
|
+
return new NextResponse(nodeReadableToReadableStream(externalResponse.data), {
|
|
47
|
+
status: externalResponse.status,
|
|
48
|
+
headers: responseHeaders,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
const getResponseHeaders = (externalResponse) => {
|
|
52
|
+
const responseHeaders = new Headers();
|
|
53
|
+
responseHeaders.set("Content-Type", externalResponse.headers["content-type"] || "");
|
|
54
|
+
responseHeaders.set("Set-Cookie", externalResponse.headers["set-cookie"] || "");
|
|
55
|
+
return responseHeaders;
|
|
56
|
+
};
|
|
57
|
+
function nodeReadableToReadableStream(nodeStream) {
|
|
58
|
+
return new ReadableStream({
|
|
59
|
+
start(controller) {
|
|
60
|
+
nodeStream.on("data", (chunk) => {
|
|
61
|
+
controller.enqueue(new Uint8Array(chunk));
|
|
62
|
+
});
|
|
63
|
+
nodeStream.on("end", () => {
|
|
64
|
+
controller.close();
|
|
65
|
+
});
|
|
66
|
+
nodeStream.on("error", (err) => {
|
|
67
|
+
controller.error(err);
|
|
68
|
+
});
|
|
69
|
+
},
|
|
70
|
+
pull() { },
|
|
71
|
+
cancel() { },
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
export const proxy = {
|
|
75
|
+
POST,
|
|
76
|
+
GET,
|
|
77
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { useRouter, useSearchParams } from "next/navigation";
|
|
2
|
+
import { useEffect, useState } from "react";
|
|
3
|
+
import uuid from "react-uuid";
|
|
4
|
+
const useExposeRefreshFunction = () => {
|
|
5
|
+
const router = useRouter();
|
|
6
|
+
const searchParams = useSearchParams();
|
|
7
|
+
const [refreshStart, setRefreshStart] = useState();
|
|
8
|
+
useEffect(() => {
|
|
9
|
+
// Expose the refresh function to the parent window
|
|
10
|
+
window.requestRefresh = (newUri) => {
|
|
11
|
+
console.log("refresh requested", newUri);
|
|
12
|
+
if (!newUri) {
|
|
13
|
+
const uri = new URL(window.location.href);
|
|
14
|
+
uri.searchParams.set("edit_rev", uuid().toString());
|
|
15
|
+
newUri = uri.toString();
|
|
16
|
+
}
|
|
17
|
+
router.replace(newUri, { scroll: false });
|
|
18
|
+
setRefreshStart(performance.now());
|
|
19
|
+
return true; // Indicate the function executed successfully
|
|
20
|
+
};
|
|
21
|
+
// Optionally clean up when the component unmounts
|
|
22
|
+
return () => {
|
|
23
|
+
delete window.requestRefresh;
|
|
24
|
+
};
|
|
25
|
+
}, [router]);
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
if (refreshStart)
|
|
28
|
+
console.log("Refresh complete", performance.now() - refreshStart);
|
|
29
|
+
}, [searchParams]);
|
|
30
|
+
return null; // This hook doesn't render anything
|
|
31
|
+
};
|
|
32
|
+
export default useExposeRefreshFunction;
|
package/next.config.mjs
ADDED
package/package.json
CHANGED
|
@@ -1,39 +1,61 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alpaca-headless/alpaca-headless-nextjs",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
|
|
9
|
-
"dist",
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
|
|
13
|
-
|
|
3
|
+
"version": "1.0.3398",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Alpaca Headless",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": "./dist/index.js",
|
|
9
|
+
"./client-components": "./dist/client-components",
|
|
10
|
+
"./middleware": "./dist/middleware",
|
|
11
|
+
"./internals": "./dist/internals"
|
|
12
|
+
},
|
|
13
|
+
"typesVersions": {
|
|
14
|
+
"*": {
|
|
15
|
+
"client-components": [
|
|
16
|
+
"./dist/client-components/index.d.ts"
|
|
17
|
+
],
|
|
18
|
+
"middleware": [
|
|
19
|
+
"./dist/middleware/index.d.ts"
|
|
20
|
+
],
|
|
21
|
+
"internals": [
|
|
22
|
+
"./dist/internals/index.d.ts"
|
|
23
|
+
]
|
|
24
|
+
}
|
|
25
|
+
},
|
|
14
26
|
"scripts": {
|
|
15
|
-
"build": "
|
|
16
|
-
"
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
"
|
|
27
|
+
"build": "tsc -b",
|
|
28
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
29
|
+
},
|
|
30
|
+
"repository": {
|
|
31
|
+
"type": "git",
|
|
32
|
+
"url": "git+https://github.com/yourusername/your-module-name.git"
|
|
20
33
|
},
|
|
34
|
+
"keywords": [
|
|
35
|
+
"esm",
|
|
36
|
+
"module"
|
|
37
|
+
],
|
|
21
38
|
"author": "Canvas REPLY DE GmbH",
|
|
22
39
|
"license": "MIT",
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"next": "13.4.12",
|
|
26
|
-
"node-cleanup": "^2.1.2",
|
|
27
|
-
"react": "18.2.0",
|
|
28
|
-
"react-dom": "18.2.0",
|
|
29
|
-
"server-only": "^0.0.1"
|
|
40
|
+
"bugs": {
|
|
41
|
+
"url": "https://github.com/yourusername/your-module-name/issues"
|
|
30
42
|
},
|
|
43
|
+
"homepage": "https://github.com/yourusername/your-module-name#readme",
|
|
31
44
|
"devDependencies": {
|
|
32
|
-
"@types/node": "20.
|
|
33
|
-
"@types/react": "18.
|
|
34
|
-
"@types/react-dom": "18.
|
|
35
|
-
"eslint": "8
|
|
36
|
-
"eslint-config-next": "
|
|
37
|
-
"typescript": "5
|
|
45
|
+
"@types/node": "^20.14.2",
|
|
46
|
+
"@types/react": "18.3.3",
|
|
47
|
+
"@types/react-dom": "18.3.0",
|
|
48
|
+
"eslint": "^8",
|
|
49
|
+
"eslint-config-next": "14.2.10",
|
|
50
|
+
"typescript": "^5"
|
|
51
|
+
},
|
|
52
|
+
"dependencies": {
|
|
53
|
+
"@alpaca-headless/alpaca-headless": "^1.0.3398",
|
|
54
|
+
"axios": "^1.7.2",
|
|
55
|
+
"https-proxy-agent": "^7.0.4",
|
|
56
|
+
"next": "^14.2.4",
|
|
57
|
+
"react": "^18.3.1",
|
|
58
|
+
"react-dom": "^18.3.1",
|
|
59
|
+
"react-uuid": "^2.0.0"
|
|
38
60
|
}
|
|
39
61
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { EditorIntegrationClient } from "./EditorIntegrationClient";
|
|
2
|
+
|
|
3
|
+
export type EditorIntegrationProps = {
|
|
4
|
+
timings?: {
|
|
5
|
+
[key: string]: number;
|
|
6
|
+
};
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export function EditorIntegration(props: EditorIntegrationProps) {
|
|
10
|
+
return <EditorIntegrationClient {...props} />;
|
|
11
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useEffect } from "react";
|
|
4
|
+
import useExposeRefreshFunction from "./useExposeRefreshFunction";
|
|
5
|
+
|
|
6
|
+
export function EditorIntegrationClient({
|
|
7
|
+
timings,
|
|
8
|
+
}: {
|
|
9
|
+
timings?: {
|
|
10
|
+
[key: string]: number;
|
|
11
|
+
};
|
|
12
|
+
}) {
|
|
13
|
+
useExposeRefreshFunction();
|
|
14
|
+
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
const handleKeyDown = (event: KeyboardEvent) => {
|
|
17
|
+
if (event.ctrlKey && event.key === "F11") {
|
|
18
|
+
event.preventDefault();
|
|
19
|
+
window.parent.postMessage({ type: "editor-exitFullscreen" }, "*");
|
|
20
|
+
}
|
|
21
|
+
if (event.key === "F2") {
|
|
22
|
+
event.preventDefault();
|
|
23
|
+
window.parent.postMessage({ type: "editor-keyDown", key: "F2" }, "*");
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
window.addEventListener("keydown", handleKeyDown);
|
|
28
|
+
window.parent.postMessage({ type: "editor-timings", timings }, "*");
|
|
29
|
+
|
|
30
|
+
return () => {
|
|
31
|
+
window.removeEventListener("keydown", handleKeyDown);
|
|
32
|
+
};
|
|
33
|
+
}, []);
|
|
34
|
+
|
|
35
|
+
return (
|
|
36
|
+
<>
|
|
37
|
+
<style>{`
|
|
38
|
+
.a-editor-mce {
|
|
39
|
+
display:flex;
|
|
40
|
+
gap: 10px;
|
|
41
|
+
padding: 30px;
|
|
42
|
+
background-color: #f5f5f5;
|
|
43
|
+
flex-wrap: wrap;
|
|
44
|
+
align-items: center;
|
|
45
|
+
}
|
|
46
|
+
.a-editor-mce-thumbnail {
|
|
47
|
+
display:grid;
|
|
48
|
+
padding: 10px;
|
|
49
|
+
place-items: center;
|
|
50
|
+
overflow: hidden;
|
|
51
|
+
}
|
|
52
|
+
.a-editor-mce-thumbnail--selected {
|
|
53
|
+
box-shadow: 0 0 3px 3px rgb(75 89 255 / 50%);
|
|
54
|
+
}
|
|
55
|
+
.a-editor-mce-thumbnail:hover {
|
|
56
|
+
box-shadow: 0 0 10px 5px rgba(0, 0, 0, 0.5);
|
|
57
|
+
}
|
|
58
|
+
[contentEditable]:empty:before {
|
|
59
|
+
content: attr(placeholder);
|
|
60
|
+
opacity: 0.6;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
[contenteditable] {
|
|
64
|
+
outline: 0px solid transparent;
|
|
65
|
+
}
|
|
66
|
+
`}</style>
|
|
67
|
+
</>
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export type ComponentSelectedEvent = {
|
|
72
|
+
type: "componentSelected";
|
|
73
|
+
componentIds: string[];
|
|
74
|
+
};
|