@alpaca-headless/alpaca-headless-nextjs 0.0.3 → 0.1.0
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-env.d.ts +5 -5
- package/next.config.mjs +4 -0
- package/package.json +61 -39
- 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 -11
- package/dist/cjs/components/Placeholder.js +0 -31
- package/dist/cjs/components/Text.js +0 -25
- package/dist/cjs/components/index.js +0 -18
- package/dist/cjs/fieldTypes.js +0 -2
- package/dist/cjs/index.js +0 -19
- package/dist/cjs/layoutData.js +0 -2
- package/dist/cjs/loadRouteData.js +0 -63
- package/dist/esm/alpacaContext.js +0 -6
- package/dist/esm/components/Placeholder.js +0 -27
- package/dist/esm/components/Text.js +0 -18
- package/dist/esm/components/index.js +0 -2
- package/dist/esm/fieldTypes.js +0 -1
- package/dist/esm/index.js +0 -3
- package/dist/esm/layoutData.js +0 -1
- package/dist/esm/loadRouteData.js +0 -59
- package/next.config.js +0 -6
- package/types/AlpacaHeadless.d.ts +0 -37
- package/types/alpacaContext.d.ts +0 -12
- package/types/components/Placeholder.d.ts +0 -5
- package/types/components/Text.d.ts +0 -7
- package/types/components/index.d.ts +0 -2
- package/types/fieldTypes.d.ts +0 -3
- package/types/index.d.ts +0 -3
- package/types/layoutData.d.ts +0 -11
- package/types/loadRouteData.d.ts +0 -24
|
@@ -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
|
+
};
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { ComponentData } from "@alpaca-headless/alpaca-headless";
|
|
3
|
+
|
|
4
|
+
import React, {
|
|
5
|
+
useState,
|
|
6
|
+
ReactElement,
|
|
7
|
+
ReactNode,
|
|
8
|
+
useEffect,
|
|
9
|
+
Fragment,
|
|
10
|
+
useCallback,
|
|
11
|
+
} from "react";
|
|
12
|
+
|
|
13
|
+
interface MultiComponentEditorProps {
|
|
14
|
+
children: ReactNode;
|
|
15
|
+
component: ComponentData;
|
|
16
|
+
placeholderName: string;
|
|
17
|
+
thumbZoom?: number;
|
|
18
|
+
thumbWidth?: string;
|
|
19
|
+
thumbHeight?: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function MultiComponentEditor({
|
|
23
|
+
children,
|
|
24
|
+
component,
|
|
25
|
+
placeholderName,
|
|
26
|
+
thumbZoom,
|
|
27
|
+
thumbWidth = "200px",
|
|
28
|
+
thumbHeight = "112px",
|
|
29
|
+
}: MultiComponentEditorProps) {
|
|
30
|
+
const [selectedId, setSelectedId] = useState<string | null>(null);
|
|
31
|
+
const placeholder = component.placeholders.find(
|
|
32
|
+
(x) => x.name === placeholderName
|
|
33
|
+
);
|
|
34
|
+
if (!placeholder) return;
|
|
35
|
+
const components = placeholder.components;
|
|
36
|
+
if (!components) return;
|
|
37
|
+
|
|
38
|
+
const handleMessage = useCallback(
|
|
39
|
+
(event: MessageEvent) => {
|
|
40
|
+
if (event.data.type === "componentsSelected") {
|
|
41
|
+
setSelectedId(event.data.componentIds[0]);
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
[components]
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
useEffect(() => {
|
|
48
|
+
window.addEventListener("message", handleMessage);
|
|
49
|
+
|
|
50
|
+
return () => {
|
|
51
|
+
window.removeEventListener("message", handleMessage);
|
|
52
|
+
};
|
|
53
|
+
}, []);
|
|
54
|
+
|
|
55
|
+
const selectedIndex = components.findIndex(
|
|
56
|
+
(x: ComponentData) => x.id === selectedId
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
const childrenArray = React.Children.toArray(children) as ReactElement[];
|
|
60
|
+
|
|
61
|
+
const filteredChildren = childrenArray.filter(
|
|
62
|
+
(child) => child.type !== "script"
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
return (
|
|
66
|
+
<>
|
|
67
|
+
{filteredChildren[selectedIndex < 0 ? 0 : selectedIndex]}
|
|
68
|
+
<div className="a-editor-mce">
|
|
69
|
+
<script
|
|
70
|
+
data-placeholder-start={placeholder.key}
|
|
71
|
+
data-orientation="horizontal"
|
|
72
|
+
/>
|
|
73
|
+
{filteredChildren.map((x, index) => thumbnail(x, index))}
|
|
74
|
+
<script data-placeholder-end={placeholder.key} />
|
|
75
|
+
</div>
|
|
76
|
+
</>
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
function thumbnail(x: React.ReactNode, index: number) {
|
|
80
|
+
const style: {
|
|
81
|
+
height?: string;
|
|
82
|
+
width?: string;
|
|
83
|
+
zoom?: number;
|
|
84
|
+
transform?: string;
|
|
85
|
+
} = {};
|
|
86
|
+
|
|
87
|
+
if (thumbHeight) {
|
|
88
|
+
style.height = thumbHeight;
|
|
89
|
+
}
|
|
90
|
+
if (thumbWidth) {
|
|
91
|
+
style.width = thumbWidth;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const componentArray = (x as any).props?.children;
|
|
95
|
+
|
|
96
|
+
const component = components![index];
|
|
97
|
+
|
|
98
|
+
return (
|
|
99
|
+
<Fragment key={index}>
|
|
100
|
+
<div
|
|
101
|
+
className={
|
|
102
|
+
"a-editor-mce-thumbnail" +
|
|
103
|
+
(index === selectedIndex ? " a-editor-mce-thumbnail--selected" : "")
|
|
104
|
+
}
|
|
105
|
+
style={style}
|
|
106
|
+
onClick={() => {
|
|
107
|
+
selectComponents([components![index].id]);
|
|
108
|
+
}}
|
|
109
|
+
>
|
|
110
|
+
<script
|
|
111
|
+
data-component-start={component.id}
|
|
112
|
+
data-itemid={
|
|
113
|
+
component._editor?.linkedComponentItem?.id || component.id
|
|
114
|
+
}
|
|
115
|
+
data-layoutid={component._editor?.hostingPageItem?.id}
|
|
116
|
+
/>
|
|
117
|
+
<div style={{ pointerEvents: "none", zoom: thumbZoom || 0.25 }}>
|
|
118
|
+
{componentArray.slice(1, -1)}
|
|
119
|
+
</div>
|
|
120
|
+
<script data-component-end={component.id} />
|
|
121
|
+
</div>
|
|
122
|
+
<div data-dropzone={components[index].id}></div>
|
|
123
|
+
</Fragment>
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function selectComponents(componentIds: string[]) {
|
|
129
|
+
window.top?.window.postMessage(
|
|
130
|
+
{ componentIds, type: "componentsSelected" },
|
|
131
|
+
"*"
|
|
132
|
+
);
|
|
133
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ApiConfig,
|
|
3
|
+
RenderOptions,
|
|
4
|
+
resolveRoute,
|
|
5
|
+
} from "@alpaca-headless/alpaca-headless";
|
|
6
|
+
import { NextRequest } from "next/server";
|
|
7
|
+
import { getApiHeaders } from ".";
|
|
8
|
+
|
|
9
|
+
export async function handleBasicAuthRoute({
|
|
10
|
+
request,
|
|
11
|
+
mapHost,
|
|
12
|
+
renderOptions,
|
|
13
|
+
apiConfig,
|
|
14
|
+
}: {
|
|
15
|
+
request: NextRequest;
|
|
16
|
+
mapHost: (host: string) => string;
|
|
17
|
+
renderOptions: RenderOptions;
|
|
18
|
+
apiConfig?: ApiConfig;
|
|
19
|
+
}) {
|
|
20
|
+
const urlSearchParams = new URLSearchParams(request.nextUrl.search);
|
|
21
|
+
const nextSearchParams: any = {};
|
|
22
|
+
for (const [key, value] of urlSearchParams.entries()) {
|
|
23
|
+
nextSearchParams[key] = value;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const config = apiConfig || {};
|
|
27
|
+
if (!config.headers) {
|
|
28
|
+
config.headers = getApiHeaders();
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const routeData = await resolveRoute({
|
|
32
|
+
path: request.nextUrl.pathname,
|
|
33
|
+
searchParams: nextSearchParams,
|
|
34
|
+
host: mapHost(request.headers.get("host") || ""),
|
|
35
|
+
renderOptions,
|
|
36
|
+
renderings: {},
|
|
37
|
+
apiConfig: config,
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
if (routeData.result.type === "redirect") {
|
|
41
|
+
return new Response(null, {
|
|
42
|
+
status: routeData.result.redirectType === "permanent" ? 301 : 302,
|
|
43
|
+
headers: {
|
|
44
|
+
Location: routeData.result.location,
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (routeData.result.type === "unauthorized") {
|
|
50
|
+
if (routeData.result.auth)
|
|
51
|
+
return new Response(null, {
|
|
52
|
+
status: 401,
|
|
53
|
+
headers: {
|
|
54
|
+
"WWW-Authenticate": routeData.result.auth.replace(", Bearer", ""),
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
else
|
|
58
|
+
return new Response(null, {
|
|
59
|
+
status: 401,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { headers } from "next/headers";
|
|
2
|
+
|
|
3
|
+
export { EditorIntegration } from "./EditorIntegration";
|
|
4
|
+
|
|
5
|
+
export function getApiHeaders() {
|
|
6
|
+
const requestHeaders = headers();
|
|
7
|
+
const apiHeaders = new Headers();
|
|
8
|
+
apiHeaders.set("Cookie", requestHeaders.get("Cookie") || "");
|
|
9
|
+
apiHeaders.set("Authorization", requestHeaders.get("Authorization") || "");
|
|
10
|
+
return apiHeaders;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export { handleRequest } from "./middleware/handleRequest";
|
|
14
|
+
|
|
15
|
+
export { proxy } from "./proxy";
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ApiConfig,
|
|
3
|
+
RenderOptions,
|
|
4
|
+
resolveRoute,
|
|
5
|
+
} from "@alpaca-headless/alpaca-headless";
|
|
6
|
+
import { NextRequest } from "next/server";
|
|
7
|
+
import { getApiHeaders } from "..";
|
|
8
|
+
|
|
9
|
+
export async function handleRequest({
|
|
10
|
+
request,
|
|
11
|
+
mapHost,
|
|
12
|
+
renderOptions,
|
|
13
|
+
apiConfig,
|
|
14
|
+
}: {
|
|
15
|
+
request: NextRequest;
|
|
16
|
+
mapHost: (host: string) => string;
|
|
17
|
+
renderOptions: RenderOptions;
|
|
18
|
+
apiConfig?: ApiConfig;
|
|
19
|
+
}) {
|
|
20
|
+
const urlSearchParams = new URLSearchParams(request.nextUrl.search);
|
|
21
|
+
const nextSearchParams: any = {};
|
|
22
|
+
for (const [key, value] of urlSearchParams.entries()) {
|
|
23
|
+
nextSearchParams[key] = value;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const config = apiConfig || {};
|
|
27
|
+
if (!config.headers) {
|
|
28
|
+
config.headers = getApiHeaders();
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const routeData = await resolveRoute({
|
|
32
|
+
path: request.nextUrl.pathname,
|
|
33
|
+
searchParams: nextSearchParams,
|
|
34
|
+
host: mapHost(request.headers.get("host") || ""),
|
|
35
|
+
renderOptions,
|
|
36
|
+
renderings: {},
|
|
37
|
+
apiConfig: config,
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
if (routeData.result.type === "redirect") {
|
|
41
|
+
return new Response(null, {
|
|
42
|
+
status: routeData.result.redirectType === "permanent" ? 301 : 302,
|
|
43
|
+
headers: {
|
|
44
|
+
Location: routeData.result.location,
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (routeData.result.type === "unauthorized") {
|
|
50
|
+
if (routeData.result.auth)
|
|
51
|
+
return new Response(null, {
|
|
52
|
+
status: 401,
|
|
53
|
+
headers: {
|
|
54
|
+
"WWW-Authenticate": routeData.result.auth.replace(", Bearer", ""),
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
else
|
|
58
|
+
return new Response(null, {
|
|
59
|
+
status: 401,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./handleRequest";
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import axios from "axios";
|
|
2
|
+
// import { HttpsProxyAgent } from "https-proxy-agent";
|
|
3
|
+
import { NextResponse } from "next/server";
|
|
4
|
+
|
|
5
|
+
async function GET(
|
|
6
|
+
req: Request,
|
|
7
|
+
target: string
|
|
8
|
+
//{ proxy }: { proxy?: string }
|
|
9
|
+
) {
|
|
10
|
+
const reqUrl = new URL(req.url);
|
|
11
|
+
|
|
12
|
+
const url: string =
|
|
13
|
+
target + reqUrl.pathname + "?" + reqUrl.searchParams.toString();
|
|
14
|
+
|
|
15
|
+
const headers: { [key: string]: string } = {
|
|
16
|
+
Authorization: req.headers.get("Authorization") || "",
|
|
17
|
+
Cookie: req.headers.get("Cookie") || "",
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
// const agent = proxy ? new HttpsProxyAgent(proxy) : undefined;
|
|
21
|
+
|
|
22
|
+
const externalResponse = await axios.get(url, {
|
|
23
|
+
headers: headers,
|
|
24
|
+
// httpAgent: agent,
|
|
25
|
+
// httpsAgent: agent,
|
|
26
|
+
responseType: "stream",
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
return new NextResponse(nodeReadableToReadableStream(externalResponse.data), {
|
|
30
|
+
status: externalResponse.status,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async function POST(
|
|
35
|
+
req: Request
|
|
36
|
+
//{ proxy }: { proxy?: string }
|
|
37
|
+
) {
|
|
38
|
+
const reqUrl = new URL(req.url);
|
|
39
|
+
const body = await req.text();
|
|
40
|
+
|
|
41
|
+
const url: string =
|
|
42
|
+
process.env.EDITOR_SERVICE_URL +
|
|
43
|
+
reqUrl.pathname +
|
|
44
|
+
"?" +
|
|
45
|
+
reqUrl.searchParams.toString();
|
|
46
|
+
|
|
47
|
+
const headers: { [key: string]: string } = {
|
|
48
|
+
"Content-Type": req.headers.get("Content-Type") || "",
|
|
49
|
+
Authorization: req.headers.get("Authorization") || "",
|
|
50
|
+
Cookie: req.headers.get("Cookie") || "",
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
// const agent = proxy ? new HttpsProxyAgent(proxy) : undefined;
|
|
54
|
+
|
|
55
|
+
const externalResponse = await axios.post(url, body, {
|
|
56
|
+
headers: headers,
|
|
57
|
+
// httpAgent: agent,
|
|
58
|
+
// httpsAgent: agent,
|
|
59
|
+
responseType: "stream",
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
const responseHeaders = getResponseHeaders(externalResponse);
|
|
63
|
+
|
|
64
|
+
return new NextResponse(nodeReadableToReadableStream(externalResponse.data), {
|
|
65
|
+
status: externalResponse.status,
|
|
66
|
+
headers: responseHeaders,
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const getResponseHeaders = (externalResponse: any) => {
|
|
71
|
+
const responseHeaders = new Headers();
|
|
72
|
+
responseHeaders.set(
|
|
73
|
+
"Content-Type",
|
|
74
|
+
externalResponse.headers["content-type"] || ""
|
|
75
|
+
);
|
|
76
|
+
responseHeaders.set(
|
|
77
|
+
"Set-Cookie",
|
|
78
|
+
externalResponse.headers["set-cookie"] || ""
|
|
79
|
+
);
|
|
80
|
+
return responseHeaders;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
function nodeReadableToReadableStream(
|
|
84
|
+
nodeStream: NodeJS.ReadableStream
|
|
85
|
+
): ReadableStream<Uint8Array> {
|
|
86
|
+
return new ReadableStream<Uint8Array>({
|
|
87
|
+
start(controller) {
|
|
88
|
+
nodeStream.on("data", (chunk: Buffer) => {
|
|
89
|
+
controller.enqueue(new Uint8Array(chunk));
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
nodeStream.on("end", () => {
|
|
93
|
+
controller.close();
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
nodeStream.on("error", (err: Error) => {
|
|
97
|
+
controller.error(err);
|
|
98
|
+
});
|
|
99
|
+
},
|
|
100
|
+
pull() {},
|
|
101
|
+
cancel() {},
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export const proxy = {
|
|
106
|
+
POST,
|
|
107
|
+
GET,
|
|
108
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { useRouter, useSearchParams } from "next/navigation";
|
|
2
|
+
import { useEffect, useState } from "react";
|
|
3
|
+
import uuid from "react-uuid";
|
|
4
|
+
|
|
5
|
+
declare global {
|
|
6
|
+
interface Window {
|
|
7
|
+
requestRefresh?: (newUri?: string) => boolean;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const useExposeRefreshFunction = () => {
|
|
12
|
+
const router = useRouter();
|
|
13
|
+
const searchParams = useSearchParams();
|
|
14
|
+
const [refreshStart, setRefreshStart] = useState<number>();
|
|
15
|
+
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
// Expose the refresh function to the parent window
|
|
18
|
+
window.requestRefresh = (newUri?: string) => {
|
|
19
|
+
console.log("refresh requested", newUri);
|
|
20
|
+
if (!newUri) {
|
|
21
|
+
const uri = new URL(window.location.href);
|
|
22
|
+
uri.searchParams.set("edit_rev", uuid().toString());
|
|
23
|
+
newUri = uri.toString();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
router.replace(newUri, { scroll: false });
|
|
27
|
+
setRefreshStart(performance.now());
|
|
28
|
+
return true; // Indicate the function executed successfully
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
// Optionally clean up when the component unmounts
|
|
32
|
+
return () => {
|
|
33
|
+
delete window.requestRefresh;
|
|
34
|
+
};
|
|
35
|
+
}, [router]);
|
|
36
|
+
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
if (refreshStart)
|
|
39
|
+
console.log("Refresh complete", performance.now() - refreshStart!);
|
|
40
|
+
}, [searchParams]);
|
|
41
|
+
|
|
42
|
+
return null; // This hook doesn't render anything
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export default useExposeRefreshFunction;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
var config = {
|
|
2
|
+
content: [
|
|
3
|
+
"./src/pages/**/*.{js,ts,jsx,tsx,mdx}",
|
|
4
|
+
"./src/components/**/*.{js,ts,jsx,tsx,mdx}",
|
|
5
|
+
"./src/app/**/*.{js,ts,jsx,tsx,mdx}",
|
|
6
|
+
],
|
|
7
|
+
theme: {
|
|
8
|
+
extend: {
|
|
9
|
+
backgroundImage: {
|
|
10
|
+
"gradient-radial": "radial-gradient(var(--tw-gradient-stops))",
|
|
11
|
+
"gradient-conic": "conic-gradient(from 180deg at 50% 50%, var(--tw-gradient-stops))",
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
plugins: [],
|
|
16
|
+
};
|
|
17
|
+
export default config;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Config } from "tailwindcss";
|
|
2
|
+
|
|
3
|
+
const config: Config = {
|
|
4
|
+
content: [
|
|
5
|
+
"./src/pages/**/*.{js,ts,jsx,tsx,mdx}",
|
|
6
|
+
"./src/components/**/*.{js,ts,jsx,tsx,mdx}",
|
|
7
|
+
"./src/app/**/*.{js,ts,jsx,tsx,mdx}",
|
|
8
|
+
],
|
|
9
|
+
theme: {
|
|
10
|
+
extend: {
|
|
11
|
+
backgroundImage: {
|
|
12
|
+
"gradient-radial": "radial-gradient(var(--tw-gradient-stops))",
|
|
13
|
+
"gradient-conic":
|
|
14
|
+
"conic-gradient(from 180deg at 50% 50%, var(--tw-gradient-stops))",
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
plugins: [],
|
|
19
|
+
};
|
|
20
|
+
export default config;
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2017",
|
|
4
|
+
"module": "esnext",
|
|
5
|
+
"moduleResolution": "bundler",
|
|
6
|
+
"jsx": "react-jsx",
|
|
7
|
+
"declaration": true,
|
|
8
|
+
"outDir": "./dist",
|
|
9
|
+
"strict": true,
|
|
10
|
+
"lib": ["dom", "dom.iterable", "es2021"],
|
|
11
|
+
"esModuleInterop": true,
|
|
12
|
+
"skipLibCheck": true,
|
|
13
|
+
"forceConsistentCasingInFileNames": true,
|
|
14
|
+
"resolveJsonModule": true,
|
|
15
|
+
"isolatedModules": true,
|
|
16
|
+
"emitDecoratorMetadata": true,
|
|
17
|
+
"experimentalDecorators": true,
|
|
18
|
+
"allowSyntheticDefaultImports": true,
|
|
19
|
+
"noImplicitThis": true,
|
|
20
|
+
"noImplicitAny": true,
|
|
21
|
+
"noUnusedLocals": true,
|
|
22
|
+
"noUnusedParameters": true
|
|
23
|
+
},
|
|
24
|
+
"include": ["src/**/*"],
|
|
25
|
+
"exclude": ["node_modules", "**/*.spec.ts"]
|
|
26
|
+
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.setAlpacaContext = exports.useAlpacaContext = void 0;
|
|
4
|
-
function useAlpacaContext() {
|
|
5
|
-
return globalThis.alpacaContext;
|
|
6
|
-
}
|
|
7
|
-
exports.useAlpacaContext = useAlpacaContext;
|
|
8
|
-
function setAlpacaContext(context) {
|
|
9
|
-
globalThis.alpacaContext = context;
|
|
10
|
-
}
|
|
11
|
-
exports.setAlpacaContext = setAlpacaContext;
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.Placeholder = void 0;
|
|
13
|
-
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
14
|
-
function Placeholder({ name, content, }) {
|
|
15
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
-
const data = yield content;
|
|
17
|
-
if (data.type !== "page" && data.type !== "component")
|
|
18
|
-
return;
|
|
19
|
-
const placeholderData = data.placeholders.find((x) => x.name == name);
|
|
20
|
-
if (!placeholderData)
|
|
21
|
-
return;
|
|
22
|
-
const loader = globalThis.moduleLoader;
|
|
23
|
-
const promises = placeholderData === null || placeholderData === void 0 ? void 0 : placeholderData.components.map((component) => __awaiter(this, void 0, void 0, function* () {
|
|
24
|
-
const module = yield loader(component.componentType);
|
|
25
|
-
return { data: component, Component: module.default };
|
|
26
|
-
}));
|
|
27
|
-
const components = yield Promise.all(promises);
|
|
28
|
-
return ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: components.map(({ Component, data }) => ((0, jsx_runtime_1.jsx)(Component, { component: data }))) }));
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
exports.Placeholder = Placeholder;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.Text = void 0;
|
|
16
|
-
const react_1 = __importDefault(require("react"));
|
|
17
|
-
function Text({ field, tag, editable, }) {
|
|
18
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
19
|
-
if (editable)
|
|
20
|
-
return react_1.default.createElement(tag || "div", null, field.value);
|
|
21
|
-
else
|
|
22
|
-
return react_1.default.createElement(tag || "div", null, field.value);
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
exports.Text = Text;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./Placeholder"), exports);
|
|
18
|
-
__exportStar(require("./Text"), exports);
|
package/dist/cjs/fieldTypes.js
DELETED