@alpaca-headless/alpaca-headless-nextjs 1.0.4458 → 1.0.4459
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/client-components/MultiComponentEditor.d.ts +5 -1
- package/dist/client-components/MultiComponentEditor.js +19 -4
- package/dist/proxy/index.js +13 -2
- package/package.json +13 -11
- package/src/client-components/MultiComponentEditor.tsx +26 -5
- package/src/proxy/index.ts +14 -1
- package/tsconfig.json +0 -1
- package/tsconfig.tsbuildinfo +0 -1
|
@@ -7,6 +7,10 @@ interface MultiComponentEditorProps {
|
|
|
7
7
|
thumbZoom?: number;
|
|
8
8
|
thumbWidth?: string;
|
|
9
9
|
thumbHeight?: string;
|
|
10
|
+
onSelectedComponentChange?: (payload: {
|
|
11
|
+
selectedId: string | null;
|
|
12
|
+
selectedIndex: number;
|
|
13
|
+
}) => void;
|
|
10
14
|
}
|
|
11
|
-
export declare function MultiComponentEditor({ children, component, placeholderName, thumbZoom, thumbWidth, thumbHeight, }: MultiComponentEditorProps): import("react/jsx-runtime").JSX.Element | undefined;
|
|
15
|
+
export declare function MultiComponentEditor({ children, component, placeholderName, thumbZoom, thumbWidth, thumbHeight, onSelectedComponentChange, }: MultiComponentEditorProps): import("react/jsx-runtime").JSX.Element | undefined;
|
|
12
16
|
export {};
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
-
import React, {
|
|
4
|
-
export function MultiComponentEditor({ children, component, placeholderName, thumbZoom, thumbWidth, thumbHeight, }) {
|
|
3
|
+
import React, { Fragment, useCallback, useEffect, useState, } from "react";
|
|
4
|
+
export function MultiComponentEditor({ children, component, placeholderName, thumbZoom, thumbWidth, thumbHeight, onSelectedComponentChange, }) {
|
|
5
|
+
var _a, _b;
|
|
5
6
|
const [selectedId, setSelectedId] = useState(null);
|
|
6
7
|
const placeholder = component.placeholders.find((x) => x.name === placeholderName);
|
|
7
8
|
if (!placeholder)
|
|
@@ -21,9 +22,23 @@ export function MultiComponentEditor({ children, component, placeholderName, thu
|
|
|
21
22
|
};
|
|
22
23
|
}, []);
|
|
23
24
|
const selectedIndex = components.findIndex((x) => x.id === selectedId);
|
|
25
|
+
const resolvedIndex = selectedIndex < 0 ? 0 : selectedIndex;
|
|
26
|
+
const resolvedComponent = (_a = components[resolvedIndex]) !== null && _a !== void 0 ? _a : null;
|
|
27
|
+
const resolvedId = (_b = resolvedComponent === null || resolvedComponent === void 0 ? void 0 : resolvedComponent.id) !== null && _b !== void 0 ? _b : null;
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
if (resolvedId !== null && selectedId !== resolvedId) {
|
|
30
|
+
setSelectedId(resolvedId);
|
|
31
|
+
}
|
|
32
|
+
}, [resolvedId, selectedId]);
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
onSelectedComponentChange === null || onSelectedComponentChange === void 0 ? void 0 : onSelectedComponentChange({
|
|
35
|
+
selectedId: resolvedId,
|
|
36
|
+
selectedIndex: resolvedIndex,
|
|
37
|
+
});
|
|
38
|
+
}, [resolvedId, resolvedIndex, onSelectedComponentChange]);
|
|
24
39
|
const childrenArray = React.Children.toArray(children);
|
|
25
40
|
const filteredChildren = childrenArray.filter((child) => child.type !== "script");
|
|
26
|
-
return (_jsxs(_Fragment, { children: [filteredChildren[
|
|
41
|
+
return (_jsxs(_Fragment, { children: [filteredChildren[resolvedIndex], _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
42
|
function thumbnail(x, index) {
|
|
28
43
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
29
44
|
const style = {};
|
|
@@ -36,7 +51,7 @@ export function MultiComponentEditor({ children, component, placeholderName, thu
|
|
|
36
51
|
const componentArray = (_c = (_b = (_a = x.props) === null || _a === void 0 ? void 0 : _a.children) === null || _b === void 0 ? void 0 : _b.props) === null || _c === void 0 ? void 0 : _c.children;
|
|
37
52
|
const component = components[index];
|
|
38
53
|
return (_jsxs(Fragment, { children: [_jsxs("div", { className: "a-editor-mce-thumbnail" +
|
|
39
|
-
(index ===
|
|
54
|
+
(index === resolvedIndex ? " a-editor-mce-thumbnail--selected" : ""), style: style, onClick: () => {
|
|
40
55
|
selectComponents([components[index].id]);
|
|
41
56
|
}, children: [_jsx("script", { "data-component-start": component.id, "data-itemid": ((_e = (_d = component._editor) === null || _d === void 0 ? void 0 : _d.linkedComponentItem) === null || _e === void 0 ? void 0 : _e.id) || component.id, "data-layoutid": (_g = (_f = component._editor) === null || _f === void 0 ? void 0 : _f.hostingPageItem) === null || _g === void 0 ? void 0 : _g.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
57
|
}
|
package/dist/proxy/index.js
CHANGED
|
@@ -1,21 +1,29 @@
|
|
|
1
1
|
import axios from "axios";
|
|
2
|
+
// import { HttpsProxyAgent } from "https-proxy-agent";
|
|
2
3
|
import { NextResponse } from "next/server";
|
|
3
|
-
async function GET(req, target
|
|
4
|
+
async function GET(req, target
|
|
5
|
+
//{ proxy }: { proxy?: string }
|
|
6
|
+
) {
|
|
4
7
|
const reqUrl = new URL(req.url);
|
|
5
8
|
const url = target + reqUrl.pathname + "?" + reqUrl.searchParams.toString();
|
|
6
9
|
const headers = {
|
|
7
10
|
Authorization: req.headers.get("Authorization") || "",
|
|
8
11
|
Cookie: req.headers.get("Cookie") || "",
|
|
9
12
|
};
|
|
13
|
+
// const agent = proxy ? new HttpsProxyAgent(proxy) : undefined;
|
|
10
14
|
const externalResponse = await axios.get(url, {
|
|
11
15
|
headers: headers,
|
|
16
|
+
// httpAgent: agent,
|
|
17
|
+
// httpsAgent: agent,
|
|
12
18
|
responseType: "stream",
|
|
13
19
|
});
|
|
14
20
|
return new NextResponse(nodeReadableToReadableStream(externalResponse.data), {
|
|
15
21
|
status: externalResponse.status,
|
|
16
22
|
});
|
|
17
23
|
}
|
|
18
|
-
async function POST(req
|
|
24
|
+
async function POST(req
|
|
25
|
+
//{ proxy }: { proxy?: string }
|
|
26
|
+
) {
|
|
19
27
|
const reqUrl = new URL(req.url);
|
|
20
28
|
const body = await req.text();
|
|
21
29
|
const url = process.env.EDITOR_SERVICE_URL +
|
|
@@ -27,8 +35,11 @@ async function POST(req) {
|
|
|
27
35
|
Authorization: req.headers.get("Authorization") || "",
|
|
28
36
|
Cookie: req.headers.get("Cookie") || "",
|
|
29
37
|
};
|
|
38
|
+
// const agent = proxy ? new HttpsProxyAgent(proxy) : undefined;
|
|
30
39
|
const externalResponse = await axios.post(url, body, {
|
|
31
40
|
headers: headers,
|
|
41
|
+
// httpAgent: agent,
|
|
42
|
+
// httpsAgent: agent,
|
|
32
43
|
responseType: "stream",
|
|
33
44
|
});
|
|
34
45
|
const responseHeaders = getResponseHeaders(externalResponse);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alpaca-headless/alpaca-headless-nextjs",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4459",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Alpaca Headless",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -44,18 +44,20 @@
|
|
|
44
44
|
},
|
|
45
45
|
"homepage": "https://github.com/yourusername/your-module-name#readme",
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"@types/node": "^
|
|
48
|
-
"@types/react": "19.2.
|
|
49
|
-
"
|
|
50
|
-
"eslint
|
|
51
|
-
"
|
|
47
|
+
"@types/node": "^20.14.2",
|
|
48
|
+
"@types/react": "19.2.2",
|
|
49
|
+
"@types/react-dom": "19.2.2",
|
|
50
|
+
"eslint": "^9.22.0",
|
|
51
|
+
"eslint-config-next": "16.0.10",
|
|
52
|
+
"typescript": "^5"
|
|
52
53
|
},
|
|
53
54
|
"dependencies": {
|
|
54
|
-
"@alpaca-headless/alpaca-headless": "^1.0.
|
|
55
|
-
"axios": "^1.
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
"react
|
|
55
|
+
"@alpaca-headless/alpaca-headless": "^1.0.4459",
|
|
56
|
+
"axios": "^1.8.1",
|
|
57
|
+
"https-proxy-agent": "^7.0.4",
|
|
58
|
+
"next": "16.0.10",
|
|
59
|
+
"react": "19.2.3",
|
|
60
|
+
"react-dom": "19.2.3",
|
|
59
61
|
"react-uuid": "^2.0.0"
|
|
60
62
|
}
|
|
61
63
|
}
|
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
import { ComponentData } from "@alpaca-headless/alpaca-headless";
|
|
3
3
|
|
|
4
4
|
import React, {
|
|
5
|
-
|
|
5
|
+
Fragment,
|
|
6
6
|
ReactElement,
|
|
7
7
|
ReactNode,
|
|
8
|
-
useEffect,
|
|
9
|
-
Fragment,
|
|
10
8
|
useCallback,
|
|
9
|
+
useEffect,
|
|
10
|
+
useState,
|
|
11
11
|
} from "react";
|
|
12
12
|
|
|
13
13
|
interface MultiComponentEditorProps {
|
|
@@ -17,6 +17,10 @@ interface MultiComponentEditorProps {
|
|
|
17
17
|
thumbZoom?: number;
|
|
18
18
|
thumbWidth?: string;
|
|
19
19
|
thumbHeight?: string;
|
|
20
|
+
onSelectedComponentChange?: (payload: {
|
|
21
|
+
selectedId: string | null;
|
|
22
|
+
selectedIndex: number;
|
|
23
|
+
}) => void;
|
|
20
24
|
}
|
|
21
25
|
|
|
22
26
|
export function MultiComponentEditor({
|
|
@@ -26,6 +30,7 @@ export function MultiComponentEditor({
|
|
|
26
30
|
thumbZoom,
|
|
27
31
|
thumbWidth,
|
|
28
32
|
thumbHeight,
|
|
33
|
+
onSelectedComponentChange,
|
|
29
34
|
}: MultiComponentEditorProps) {
|
|
30
35
|
const [selectedId, setSelectedId] = useState<string | null>(null);
|
|
31
36
|
const placeholder = component.placeholders.find(
|
|
@@ -55,6 +60,22 @@ export function MultiComponentEditor({
|
|
|
55
60
|
const selectedIndex = components.findIndex(
|
|
56
61
|
(x: ComponentData) => x.id === selectedId
|
|
57
62
|
);
|
|
63
|
+
const resolvedIndex = selectedIndex < 0 ? 0 : selectedIndex;
|
|
64
|
+
const resolvedComponent = components[resolvedIndex] ?? null;
|
|
65
|
+
const resolvedId = resolvedComponent?.id ?? null;
|
|
66
|
+
|
|
67
|
+
useEffect(() => {
|
|
68
|
+
if (resolvedId !== null && selectedId !== resolvedId) {
|
|
69
|
+
setSelectedId(resolvedId);
|
|
70
|
+
}
|
|
71
|
+
}, [resolvedId, selectedId]);
|
|
72
|
+
|
|
73
|
+
useEffect(() => {
|
|
74
|
+
onSelectedComponentChange?.({
|
|
75
|
+
selectedId: resolvedId,
|
|
76
|
+
selectedIndex: resolvedIndex,
|
|
77
|
+
});
|
|
78
|
+
}, [resolvedId, resolvedIndex, onSelectedComponentChange]);
|
|
58
79
|
|
|
59
80
|
const childrenArray = React.Children.toArray(children) as ReactElement[];
|
|
60
81
|
|
|
@@ -64,7 +85,7 @@ export function MultiComponentEditor({
|
|
|
64
85
|
|
|
65
86
|
return (
|
|
66
87
|
<>
|
|
67
|
-
{filteredChildren[
|
|
88
|
+
{filteredChildren[resolvedIndex]}
|
|
68
89
|
<div className="a-editor-mce">
|
|
69
90
|
<script
|
|
70
91
|
data-placeholder-start={placeholder.key}
|
|
@@ -100,7 +121,7 @@ export function MultiComponentEditor({
|
|
|
100
121
|
<div
|
|
101
122
|
className={
|
|
102
123
|
"a-editor-mce-thumbnail" +
|
|
103
|
-
(index ===
|
|
124
|
+
(index === resolvedIndex ? " a-editor-mce-thumbnail--selected" : "")
|
|
104
125
|
}
|
|
105
126
|
style={style}
|
|
106
127
|
onClick={() => {
|
package/src/proxy/index.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import axios from "axios";
|
|
2
|
+
// import { HttpsProxyAgent } from "https-proxy-agent";
|
|
2
3
|
import { NextResponse } from "next/server";
|
|
3
4
|
|
|
4
5
|
async function GET(
|
|
5
6
|
req: Request,
|
|
6
7
|
target: string
|
|
8
|
+
//{ proxy }: { proxy?: string }
|
|
7
9
|
) {
|
|
8
10
|
const reqUrl = new URL(req.url);
|
|
9
11
|
|
|
@@ -15,8 +17,12 @@ async function GET(
|
|
|
15
17
|
Cookie: req.headers.get("Cookie") || "",
|
|
16
18
|
};
|
|
17
19
|
|
|
20
|
+
// const agent = proxy ? new HttpsProxyAgent(proxy) : undefined;
|
|
21
|
+
|
|
18
22
|
const externalResponse = await axios.get(url, {
|
|
19
23
|
headers: headers,
|
|
24
|
+
// httpAgent: agent,
|
|
25
|
+
// httpsAgent: agent,
|
|
20
26
|
responseType: "stream",
|
|
21
27
|
});
|
|
22
28
|
|
|
@@ -25,7 +31,10 @@ async function GET(
|
|
|
25
31
|
});
|
|
26
32
|
}
|
|
27
33
|
|
|
28
|
-
async function POST(
|
|
34
|
+
async function POST(
|
|
35
|
+
req: Request
|
|
36
|
+
//{ proxy }: { proxy?: string }
|
|
37
|
+
) {
|
|
29
38
|
const reqUrl = new URL(req.url);
|
|
30
39
|
const body = await req.text();
|
|
31
40
|
|
|
@@ -41,8 +50,12 @@ async function POST(req: Request) {
|
|
|
41
50
|
Cookie: req.headers.get("Cookie") || "",
|
|
42
51
|
};
|
|
43
52
|
|
|
53
|
+
// const agent = proxy ? new HttpsProxyAgent(proxy) : undefined;
|
|
54
|
+
|
|
44
55
|
const externalResponse = await axios.post(url, body, {
|
|
45
56
|
headers: headers,
|
|
57
|
+
// httpAgent: agent,
|
|
58
|
+
// httpsAgent: agent,
|
|
46
59
|
responseType: "stream",
|
|
47
60
|
});
|
|
48
61
|
|
package/tsconfig.json
CHANGED
package/tsconfig.tsbuildinfo
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"root":["./src/editorintegration.tsx","./src/editorintegrationclient.tsx","./src/handlebasicauthroute.ts","./src/index.ts","./src/useexposerefreshfunction.ts","./src/client-components/multicomponenteditor.tsx","./src/client-components/index.ts","./src/middleware/handlerequest.ts","./src/middleware/index.ts","./src/proxy/index.ts"],"version":"5.9.3"}
|