@alpaca-headless/alpaca-headless-nextjs 1.0.4471 → 1.0.4473
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.
|
@@ -7,10 +7,6 @@ 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;
|
|
14
10
|
}
|
|
15
|
-
export declare function MultiComponentEditor({ children, component, placeholderName, thumbZoom, thumbWidth, thumbHeight,
|
|
11
|
+
export declare function MultiComponentEditor({ children, component, placeholderName, thumbZoom, thumbWidth, thumbHeight, }: MultiComponentEditorProps): import("react/jsx-runtime").JSX.Element | undefined;
|
|
16
12
|
export {};
|
|
@@ -1,8 +1,7 @@
|
|
|
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,
|
|
5
|
-
var _a, _b;
|
|
3
|
+
import React, { useState, useEffect, Fragment, useCallback, } from "react";
|
|
4
|
+
export function MultiComponentEditor({ children, component, placeholderName, thumbZoom, thumbWidth, thumbHeight, }) {
|
|
6
5
|
const [selectedId, setSelectedId] = useState(null);
|
|
7
6
|
const placeholder = component.placeholders.find((x) => x.name === placeholderName);
|
|
8
7
|
if (!placeholder)
|
|
@@ -22,23 +21,9 @@ export function MultiComponentEditor({ children, component, placeholderName, thu
|
|
|
22
21
|
};
|
|
23
22
|
}, []);
|
|
24
23
|
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]);
|
|
39
24
|
const childrenArray = React.Children.toArray(children);
|
|
40
25
|
const filteredChildren = childrenArray.filter((child) => child.type !== "script");
|
|
41
|
-
return (_jsxs(_Fragment, { children: [filteredChildren[
|
|
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 })] })] }));
|
|
42
27
|
function thumbnail(x, index) {
|
|
43
28
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
44
29
|
const style = {};
|
|
@@ -51,7 +36,7 @@ export function MultiComponentEditor({ children, component, placeholderName, thu
|
|
|
51
36
|
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;
|
|
52
37
|
const component = components[index];
|
|
53
38
|
return (_jsxs(Fragment, { children: [_jsxs("div", { className: "a-editor-mce-thumbnail" +
|
|
54
|
-
(index ===
|
|
39
|
+
(index === selectedIndex ? " a-editor-mce-thumbnail--selected" : ""), style: style, onClick: () => {
|
|
55
40
|
selectComponents([components[index].id]);
|
|
56
41
|
}, 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));
|
|
57
42
|
}
|
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.4473",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Alpaca Headless",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"typescript": "5.9.3"
|
|
52
52
|
},
|
|
53
53
|
"dependencies": {
|
|
54
|
-
"@alpaca-headless/alpaca-headless": "^1.0.
|
|
54
|
+
"@alpaca-headless/alpaca-headless": "^1.0.4473",
|
|
55
55
|
"axios": "^1.13.6",
|
|
56
56
|
"next": "16.2.1",
|
|
57
57
|
"react": "19.2.4",
|
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
import { ComponentData } from "@alpaca-headless/alpaca-headless";
|
|
3
3
|
|
|
4
4
|
import React, {
|
|
5
|
-
|
|
5
|
+
useState,
|
|
6
6
|
ReactElement,
|
|
7
7
|
ReactNode,
|
|
8
|
-
useCallback,
|
|
9
8
|
useEffect,
|
|
10
|
-
|
|
9
|
+
Fragment,
|
|
10
|
+
useCallback,
|
|
11
11
|
} from "react";
|
|
12
12
|
|
|
13
13
|
interface MultiComponentEditorProps {
|
|
@@ -17,10 +17,6 @@ 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;
|
|
24
20
|
}
|
|
25
21
|
|
|
26
22
|
export function MultiComponentEditor({
|
|
@@ -30,7 +26,6 @@ export function MultiComponentEditor({
|
|
|
30
26
|
thumbZoom,
|
|
31
27
|
thumbWidth,
|
|
32
28
|
thumbHeight,
|
|
33
|
-
onSelectedComponentChange,
|
|
34
29
|
}: MultiComponentEditorProps) {
|
|
35
30
|
const [selectedId, setSelectedId] = useState<string | null>(null);
|
|
36
31
|
const placeholder = component.placeholders.find(
|
|
@@ -60,22 +55,6 @@ export function MultiComponentEditor({
|
|
|
60
55
|
const selectedIndex = components.findIndex(
|
|
61
56
|
(x: ComponentData) => x.id === selectedId
|
|
62
57
|
);
|
|
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]);
|
|
79
58
|
|
|
80
59
|
const childrenArray = React.Children.toArray(children) as ReactElement[];
|
|
81
60
|
|
|
@@ -85,7 +64,7 @@ export function MultiComponentEditor({
|
|
|
85
64
|
|
|
86
65
|
return (
|
|
87
66
|
<>
|
|
88
|
-
{filteredChildren[
|
|
67
|
+
{filteredChildren[selectedIndex < 0 ? 0 : selectedIndex]}
|
|
89
68
|
<div className="a-editor-mce">
|
|
90
69
|
<script
|
|
91
70
|
data-placeholder-start={placeholder.key}
|
|
@@ -121,7 +100,7 @@ export function MultiComponentEditor({
|
|
|
121
100
|
<div
|
|
122
101
|
className={
|
|
123
102
|
"a-editor-mce-thumbnail" +
|
|
124
|
-
(index ===
|
|
103
|
+
(index === selectedIndex ? " a-editor-mce-thumbnail--selected" : "")
|
|
125
104
|
}
|
|
126
105
|
style={style}
|
|
127
106
|
onClick={() => {
|