@alpaca-headless/alpaca-headless-nextjs 0.0.3 → 1.0.13
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/cjs/alpacaContext.js +7 -6
- package/dist/cjs/components/Image.js +36 -0
- package/dist/cjs/components/Link.js +22 -0
- package/dist/cjs/components/Picture.js +119 -0
- package/dist/cjs/components/PictureEditor.js +43 -0
- package/dist/cjs/components/Placeholder.js +43 -5
- package/dist/cjs/components/RichText.js +44 -0
- package/dist/cjs/components/RichTextEditor.js +82 -0
- package/dist/cjs/components/Slot.js +8 -0
- package/dist/cjs/components/Text.js +24 -4
- package/dist/cjs/components/TextEditor.js +68 -0
- package/dist/cjs/components/Translate.js +14 -0
- package/dist/cjs/components/index.js +5 -0
- package/dist/cjs/editor/AiTerminal.js +150 -0
- package/dist/cjs/editor/ComponentInfo.js +14 -0
- package/dist/cjs/editor/ComponentPalette.js +78 -0
- package/dist/cjs/editor/ComponentTree.js +200 -0
- package/dist/cjs/editor/ContentTree.js +120 -0
- package/dist/cjs/editor/Debug.js +16 -0
- package/dist/cjs/editor/DictionaryEditor.js +35 -0
- package/dist/cjs/editor/EditFrame.js +61 -0
- package/dist/cjs/editor/EditHistory.js +30 -0
- package/dist/cjs/editor/Editor.js +27 -0
- package/dist/cjs/editor/EditorClient.js +457 -0
- package/dist/cjs/editor/EditorClientHost.js +37 -0
- package/dist/cjs/editor/FieldList.js +59 -0
- package/dist/cjs/editor/GraphQL.js +90 -0
- package/dist/cjs/editor/LanguageSelector.js +21 -0
- package/dist/cjs/editor/MediaSelector.js +61 -0
- package/dist/cjs/editor/PageInfo.js +12 -0
- package/dist/cjs/editor/PlaceholderDropZone.js +54 -0
- package/dist/cjs/editor/PlaceholderDropZoneHost.js +37 -0
- package/dist/cjs/editor/Terminal.js +51 -0
- package/dist/cjs/editor/TranslateEditor.js +25 -0
- package/dist/cjs/editor/VersionSelector.js +21 -0
- package/dist/cjs/editor/componentTreeHelper.js +18 -0
- package/dist/cjs/editor/contentService.js +38 -0
- package/dist/cjs/editor/editContext.js +35 -0
- package/dist/cjs/editor/editService.js +150 -0
- package/dist/cjs/editor/fieldTypes/RichTextEditor.js +19 -0
- package/dist/cjs/editor/fieldTypes/SingleLineText.js +17 -0
- package/dist/cjs/editor/index.js +18 -0
- package/dist/cjs/graphQLTypes.js +2 -0
- package/dist/cjs/index.js +17 -0
- package/dist/cjs/loadRouteData.js +102 -38
- package/dist/cjs/mediaProtection.js +56 -0
- package/dist/editor.css +120 -0
- package/dist/esm/alpacaContext.js +6 -4
- package/dist/esm/components/Image.js +32 -0
- package/dist/esm/components/Link.js +18 -0
- package/dist/esm/components/Picture.js +115 -0
- package/dist/esm/components/PictureEditor.js +39 -0
- package/dist/esm/components/Placeholder.js +41 -6
- package/dist/esm/components/RichText.js +37 -0
- package/dist/esm/components/RichTextEditor.js +55 -0
- package/dist/esm/components/Slot.js +5 -0
- package/dist/esm/components/Text.js +24 -4
- package/dist/esm/components/TextEditor.js +41 -0
- package/dist/esm/components/Translate.js +10 -0
- package/dist/esm/components/index.js +5 -0
- package/dist/esm/editor/AiTerminal.js +146 -0
- package/dist/esm/editor/ComponentInfo.js +10 -0
- package/dist/esm/editor/ComponentPalette.js +71 -0
- package/dist/esm/editor/ComponentTree.js +196 -0
- package/dist/esm/editor/ContentTree.js +117 -0
- package/dist/esm/editor/Debug.js +9 -0
- package/dist/esm/editor/DictionaryEditor.js +31 -0
- package/dist/esm/editor/EditFrame.js +57 -0
- package/dist/esm/editor/EditHistory.js +26 -0
- package/dist/esm/editor/Editor.js +23 -0
- package/dist/esm/editor/EditorClient.js +450 -0
- package/dist/esm/editor/EditorClientHost.js +7 -0
- package/dist/esm/editor/FieldList.js +55 -0
- package/dist/esm/editor/GraphQL.js +83 -0
- package/dist/esm/editor/LanguageSelector.js +17 -0
- package/dist/esm/editor/MediaSelector.js +54 -0
- package/dist/esm/editor/PageInfo.js +8 -0
- package/dist/esm/editor/PlaceholderDropZone.js +50 -0
- package/dist/esm/editor/PlaceholderDropZoneHost.js +7 -0
- package/dist/esm/editor/Terminal.js +47 -0
- package/dist/esm/editor/TranslateEditor.js +21 -0
- package/dist/esm/editor/VersionSelector.js +17 -0
- package/dist/esm/editor/componentTreeHelper.js +14 -0
- package/dist/esm/editor/contentService.js +31 -0
- package/dist/esm/editor/editContext.js +5 -0
- package/dist/esm/editor/editService.js +139 -0
- package/dist/esm/editor/fieldTypes/RichTextEditor.js +15 -0
- package/dist/esm/editor/fieldTypes/SingleLineText.js +13 -0
- package/dist/esm/editor/index.js +2 -0
- package/dist/esm/graphQLTypes.js +1 -0
- package/dist/esm/index.js +4 -0
- package/dist/esm/loadRouteData.js +102 -38
- package/dist/esm/mediaProtection.js +49 -0
- package/next-env.d.ts +5 -5
- package/package.json +51 -39
- package/types/alpacaContext.d.ts +20 -7
- package/types/components/Image.d.ts +10 -0
- package/types/components/Link.d.ts +6 -0
- package/types/components/Picture.d.ts +20 -0
- package/types/components/PictureEditor.d.ts +3 -0
- package/types/components/RichText.d.ts +7 -0
- package/types/components/RichTextEditor.d.ts +296 -0
- package/types/components/Slot.d.ts +4 -0
- package/types/components/Text.d.ts +3 -2
- package/types/components/TextEditor.d.ts +296 -0
- package/types/components/Translate.d.ts +3 -0
- package/types/components/index.d.ts +5 -0
- package/types/editor/AiTerminal.d.ts +4 -0
- package/types/editor/ComponentInfo.d.ts +4 -0
- package/types/editor/ComponentPalette.d.ts +7 -0
- package/types/editor/ComponentTree.d.ts +5 -0
- package/types/editor/ContentTree.d.ts +13 -0
- package/types/editor/Debug.d.ts +6 -0
- package/types/editor/DictionaryEditor.d.ts +3 -0
- package/types/editor/EditFrame.d.ts +6 -0
- package/types/editor/EditHistory.d.ts +4 -0
- package/types/editor/Editor.d.ts +6 -0
- package/types/editor/EditorClient.d.ts +9 -0
- package/types/editor/EditorClientHost.d.ts +8 -0
- package/types/editor/FieldList.d.ts +4 -0
- package/types/editor/GraphQL.d.ts +5 -0
- package/types/editor/LanguageSelector.d.ts +5 -0
- package/types/editor/MediaSelector.d.ts +5 -0
- package/types/editor/PageInfo.d.ts +4 -0
- package/types/editor/PlaceholderDropZone.d.ts +6 -0
- package/types/editor/PlaceholderDropZoneHost.d.ts +6 -0
- package/types/editor/Terminal.d.ts +4 -0
- package/types/editor/TranslateEditor.d.ts +3 -0
- package/types/editor/VersionSelector.d.ts +5 -0
- package/types/editor/componentTreeHelper.d.ts +2 -0
- package/types/editor/contentService.d.ts +14 -0
- package/types/editor/editContext.d.ts +81 -0
- package/types/editor/editService.d.ts +12 -0
- package/types/editor/fieldTypes/RichTextEditor.d.ts +4 -0
- package/types/editor/fieldTypes/SingleLineText.d.ts +4 -0
- package/types/editor/index.d.ts +2 -0
- package/types/fieldTypes.d.ts +63 -1
- package/types/graphQLTypes.d.ts +24 -0
- package/types/index.d.ts +4 -0
- package/types/layoutData.d.ts +56 -1
- package/types/loadRouteData.d.ts +34 -2
- package/types/mediaProtection.d.ts +2 -0
- package/types/AlpacaHeadless.d.ts +0 -37
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useEditContext } from "..";
|
|
4
|
+
import { Tree, } from "primereact/tree";
|
|
5
|
+
import { useEffect, useRef, useState } from "react";
|
|
6
|
+
import { Tag } from "primereact/tag";
|
|
7
|
+
import { ContextMenu } from "primereact/contextmenu";
|
|
8
|
+
import { confirmDialog } from "primereact/confirmdialog";
|
|
9
|
+
function mapPlaceholderNode(p, parent) {
|
|
10
|
+
const node = {
|
|
11
|
+
key: p.key,
|
|
12
|
+
componentId: p.key,
|
|
13
|
+
label: p.name,
|
|
14
|
+
data: p,
|
|
15
|
+
icon: "pi pi-folder",
|
|
16
|
+
parent: parent,
|
|
17
|
+
droppable: true,
|
|
18
|
+
};
|
|
19
|
+
node.children = p.components.map((c) => mapComponentNode(c, node));
|
|
20
|
+
return node;
|
|
21
|
+
}
|
|
22
|
+
function mapPlaceholders(c, parent) {
|
|
23
|
+
if (c.placeholders.length > 1)
|
|
24
|
+
return c.placeholders.map((x) => mapPlaceholderNode(x, parent));
|
|
25
|
+
else if (c.placeholders.length > 0)
|
|
26
|
+
return c.placeholders[0].components.map((c) => mapComponentNode(c, parent));
|
|
27
|
+
return [];
|
|
28
|
+
}
|
|
29
|
+
function mapComponentNode(c, parent) {
|
|
30
|
+
const node = {
|
|
31
|
+
key: c.linkItemId + "_" + c.id || c.id,
|
|
32
|
+
componentId: c.id,
|
|
33
|
+
label: c.name,
|
|
34
|
+
icon: "pi pi-stop",
|
|
35
|
+
data: c,
|
|
36
|
+
parent: parent,
|
|
37
|
+
tags: [],
|
|
38
|
+
droppable: true,
|
|
39
|
+
};
|
|
40
|
+
if (c.translations && c.translations.length > 1)
|
|
41
|
+
node.tags.push({
|
|
42
|
+
severity: "info",
|
|
43
|
+
value: c.translations.length + " Languages",
|
|
44
|
+
icon: "pi pi-flag",
|
|
45
|
+
});
|
|
46
|
+
if (c.hostingPageItem) {
|
|
47
|
+
node.tags.push({
|
|
48
|
+
severity: "warning",
|
|
49
|
+
value: "Layout",
|
|
50
|
+
icon: "",
|
|
51
|
+
color: "rgb(192 132 252)",
|
|
52
|
+
onClick: () => {
|
|
53
|
+
var _a;
|
|
54
|
+
confirmDialog({
|
|
55
|
+
header: "Edit layout",
|
|
56
|
+
message: "Edit layout " + ((_a = c.hostingPageItem) === null || _a === void 0 ? void 0 : _a.path) + "?",
|
|
57
|
+
accept: () => window.open(c.hostingPageItem.editUrl, "_blank"),
|
|
58
|
+
});
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
node.children = mapPlaceholders(c, node);
|
|
63
|
+
return node;
|
|
64
|
+
}
|
|
65
|
+
// function selectTreeNode(event: TreeSelectionEvent): void {
|
|
66
|
+
// editContext.setSelection(event.value.keys());
|
|
67
|
+
// }
|
|
68
|
+
export function ComponentTree({ page, selection, }) {
|
|
69
|
+
const [expandedKeys, setExpandedKeys] = useState({
|
|
70
|
+
"0": true,
|
|
71
|
+
});
|
|
72
|
+
const [selectedKeys, setSelectedKeys] = useState();
|
|
73
|
+
const cm = useRef(null);
|
|
74
|
+
let editContext = useEditContext();
|
|
75
|
+
useEffect(() => {
|
|
76
|
+
const newSelectedKeys = {};
|
|
77
|
+
selection.forEach((id) => {
|
|
78
|
+
const nodes = findNodesByComponentId(id, nodeDictionary);
|
|
79
|
+
nodes.forEach((nodeId) => {
|
|
80
|
+
newSelectedKeys[nodeId] = true;
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
const newExpandedKeys = Object.assign({}, expandedKeys);
|
|
84
|
+
Object.keys(newSelectedKeys).forEach((id) => {
|
|
85
|
+
const node = nodeDictionary[id];
|
|
86
|
+
if (node)
|
|
87
|
+
expandParents(node.parent, newExpandedKeys);
|
|
88
|
+
});
|
|
89
|
+
if (!hasSameProps(newExpandedKeys, expandedKeys))
|
|
90
|
+
setExpandedKeys(newExpandedKeys);
|
|
91
|
+
setSelectedKeys(newSelectedKeys);
|
|
92
|
+
}, [selection]);
|
|
93
|
+
if (!page)
|
|
94
|
+
return _jsx(_Fragment, {});
|
|
95
|
+
const componentsNode = {
|
|
96
|
+
key: "0",
|
|
97
|
+
componentId: "0",
|
|
98
|
+
label: "Components",
|
|
99
|
+
data: "Components Folder",
|
|
100
|
+
icon: "pi pi-fw pi-list",
|
|
101
|
+
};
|
|
102
|
+
componentsNode.children = mapPlaceholders(page, componentsNode);
|
|
103
|
+
const treeNodes = [componentsNode];
|
|
104
|
+
const nodeDictionary = {};
|
|
105
|
+
createMap(treeNodes, nodeDictionary);
|
|
106
|
+
const nodeTemplate = (node, options) => {
|
|
107
|
+
var _a;
|
|
108
|
+
let label = (_jsxs("span", { "data-key": node.key, className: "flex", children: [node.label, (_a = node.tags) === null || _a === void 0 ? void 0 : _a.map((x) => (_jsx(Tag, { icon: x.icon, value: x.value, severity: x.severity, onClick: x.onClick, style: { backgroundColor: x.color, marginLeft: "8px" } }, x.value)))] }));
|
|
109
|
+
return _jsx("span", { className: options.className, children: label });
|
|
110
|
+
};
|
|
111
|
+
const menu = [
|
|
112
|
+
{
|
|
113
|
+
label: "View Key",
|
|
114
|
+
icon: "pi pi-search",
|
|
115
|
+
command: () => {
|
|
116
|
+
// toast.current.show({ severity: 'success', summary: 'Node Key', detail: selectedNodeKey });
|
|
117
|
+
},
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
label: "Toggle",
|
|
121
|
+
icon: "pi pi-sort",
|
|
122
|
+
command: () => {
|
|
123
|
+
// let _expandedKeys = { ...expandedKeys };
|
|
124
|
+
// if (_expandedKeys[selectedNodeKey]) delete _expandedKeys[selectedNodeKey];
|
|
125
|
+
// else _expandedKeys[selectedNodeKey] = true;
|
|
126
|
+
// setExpandedKeys(_expandedKeys);
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
];
|
|
130
|
+
function findNode(ev) {
|
|
131
|
+
const treeNodeParent = ev.target.closest(".p-treenode");
|
|
132
|
+
if (treeNodeParent) {
|
|
133
|
+
const childWithDataKey = treeNodeParent.querySelector("[data-key]");
|
|
134
|
+
if (childWithDataKey) {
|
|
135
|
+
return childWithDataKey;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return null;
|
|
139
|
+
}
|
|
140
|
+
return (_jsxs("div", { onDragOverCapture: (ev) => {
|
|
141
|
+
var _a;
|
|
142
|
+
if (!findNode(ev))
|
|
143
|
+
ev.dataTransfer.dropEffect = "none";
|
|
144
|
+
ev.dataTransfer.dropEffect =
|
|
145
|
+
((_a = editContext === null || editContext === void 0 ? void 0 : editContext.dragObject) === null || _a === void 0 ? void 0 : _a.type) == "template" ? "copy" : "move";
|
|
146
|
+
ev.preventDefault();
|
|
147
|
+
ev.stopPropagation();
|
|
148
|
+
}, onDropCapture: (ev) => {
|
|
149
|
+
var node = findNode(ev);
|
|
150
|
+
if (node)
|
|
151
|
+
alert(node.getAttribute("data-key"));
|
|
152
|
+
ev.stopPropagation();
|
|
153
|
+
}, children: [_jsx(ContextMenu, { model: menu, ref: cm }), _jsx(Tree, { value: treeNodes, selectionMode: "multiple", selectionKeys: selectedKeys, className: "w-full alpaca-no-border", onToggle: (e) => setExpandedKeys(e.value), expandedKeys: expandedKeys, nodeTemplate: nodeTemplate, dragdropScope: "ignore", onSelectionChange: (ev) => {
|
|
154
|
+
if (ev.value) {
|
|
155
|
+
const selectedKeys = Object.keys(ev.value);
|
|
156
|
+
const selectedComponentIds = selectedKeys
|
|
157
|
+
.filter((key) => nodeDictionary[key])
|
|
158
|
+
.map((key) => nodeDictionary[key].componentId);
|
|
159
|
+
editContext === null || editContext === void 0 ? void 0 : editContext.setSelection(selectedComponentIds);
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
editContext === null || editContext === void 0 ? void 0 : editContext.setSelection([]);
|
|
163
|
+
}
|
|
164
|
+
}, onContextMenu: (e) => { var _a; return (_a = cm.current) === null || _a === void 0 ? void 0 : _a.show(e.originalEvent); } })] }));
|
|
165
|
+
}
|
|
166
|
+
function createMap(treeNodes, nodeDictionary) {
|
|
167
|
+
treeNodes.forEach((n) => {
|
|
168
|
+
if (n.key)
|
|
169
|
+
nodeDictionary[n.key] = n;
|
|
170
|
+
if (n.children)
|
|
171
|
+
createMap(n.children, nodeDictionary);
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
function findNodesByComponentId(id, nodesDictionary) {
|
|
175
|
+
const allNodes = Object.values(nodesDictionary);
|
|
176
|
+
return allNodes
|
|
177
|
+
.filter((x) => x.componentId === id)
|
|
178
|
+
.map((x) => { var _a; return ((_a = x.key) === null || _a === void 0 ? void 0 : _a.toString()) || ""; });
|
|
179
|
+
}
|
|
180
|
+
function expandParents(node, newExpandedKeys) {
|
|
181
|
+
if (!node)
|
|
182
|
+
return;
|
|
183
|
+
if (node.key)
|
|
184
|
+
newExpandedKeys[node.key] = true;
|
|
185
|
+
if (node.parent)
|
|
186
|
+
expandParents(node.parent, newExpandedKeys);
|
|
187
|
+
}
|
|
188
|
+
function hasSameProps(obj1, obj2) {
|
|
189
|
+
var obj1Props = Object.keys(obj1), obj2Props = Object.keys(obj2);
|
|
190
|
+
if (obj1Props.length == obj2Props.length) {
|
|
191
|
+
return obj1Props.every(function (prop) {
|
|
192
|
+
return obj2Props.indexOf(prop) >= 0;
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
return false;
|
|
196
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use client";
|
|
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
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
12
|
+
import { ProgressSpinner } from "primereact/progressspinner";
|
|
13
|
+
import { useEditContext } from "..";
|
|
14
|
+
import { Tree, } from "primereact/tree";
|
|
15
|
+
import { useEffect, useState } from "react";
|
|
16
|
+
import { getChildren } from "./contentService";
|
|
17
|
+
export default function ContentTree({ isDraggable, dragStart, dragEnd, expandIdPath, selectionMode, selectedItemIds, rootItemId, onSelectionChange, filter, templateIds, }) {
|
|
18
|
+
const [treeNodes, setTreeNodes] = useState([]);
|
|
19
|
+
const [expandedKeys, setExpandedKeys] = useState();
|
|
20
|
+
const editContext = useEditContext();
|
|
21
|
+
const loadOnExpand = (event) => __awaiter(this, void 0, void 0, function* () {
|
|
22
|
+
const node = event.node;
|
|
23
|
+
node.loading = true;
|
|
24
|
+
yield loadNodeChildren(node);
|
|
25
|
+
let value = [...treeNodes];
|
|
26
|
+
setTreeNodes(value);
|
|
27
|
+
node.loading = false;
|
|
28
|
+
});
|
|
29
|
+
const loadNodeChildren = (node) => __awaiter(this, void 0, void 0, function* () {
|
|
30
|
+
if (!node.children) {
|
|
31
|
+
if (!node.key || !editContext)
|
|
32
|
+
return node.children || [];
|
|
33
|
+
let children = yield getChildren(node.key, editContext === null || editContext === void 0 ? void 0 : editContext.sessionId, templateIds);
|
|
34
|
+
if (filter)
|
|
35
|
+
children = filter(children);
|
|
36
|
+
node.children = children.map((x) => ({
|
|
37
|
+
key: x.id,
|
|
38
|
+
label: x.name,
|
|
39
|
+
iconUrl: x.icon,
|
|
40
|
+
isDraggable: isDraggable && isDraggable(x),
|
|
41
|
+
data: x,
|
|
42
|
+
leaf: !x.hasChildren,
|
|
43
|
+
}));
|
|
44
|
+
}
|
|
45
|
+
return node.children;
|
|
46
|
+
});
|
|
47
|
+
useEffect(() => {
|
|
48
|
+
const treeNodes = [
|
|
49
|
+
{
|
|
50
|
+
key: rootItemId.toLowerCase(),
|
|
51
|
+
label: "content",
|
|
52
|
+
leaf: false,
|
|
53
|
+
},
|
|
54
|
+
];
|
|
55
|
+
const newExpandedKeys = getExpandedKeys();
|
|
56
|
+
setExpandedKeys(newExpandedKeys);
|
|
57
|
+
preLoadNodes(newExpandedKeys, treeNodes);
|
|
58
|
+
setTreeNodes(treeNodes);
|
|
59
|
+
}, []);
|
|
60
|
+
function getExpandedKeys() {
|
|
61
|
+
const newExpandedKeys = {};
|
|
62
|
+
newExpandedKeys[rootItemId.toLocaleLowerCase()] = true;
|
|
63
|
+
const idPathArray = expandIdPath.split("/");
|
|
64
|
+
idPathArray.forEach((x) => {
|
|
65
|
+
if (x !== "")
|
|
66
|
+
newExpandedKeys[x.substring(1, x.length - 1).toLowerCase()] = true;
|
|
67
|
+
});
|
|
68
|
+
return newExpandedKeys;
|
|
69
|
+
}
|
|
70
|
+
function preLoadNodes(expandedKeys, treeNodes) {
|
|
71
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
72
|
+
yield doPreloadNodes(expandedKeys, treeNodes);
|
|
73
|
+
setExpandedKeys(Object.assign({}, expandedKeys));
|
|
74
|
+
setTreeNodes([...treeNodes]);
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
function doPreloadNodes(expandedKeys, treeNodes) {
|
|
78
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
79
|
+
for (let i = 0; i < treeNodes.length; i++) {
|
|
80
|
+
if (expandedKeys[treeNodes[i].key]) {
|
|
81
|
+
const children = yield loadNodeChildren(treeNodes[i]);
|
|
82
|
+
yield doPreloadNodes(expandedKeys, children);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
const nodeTemplate = (node, options) => {
|
|
88
|
+
let label = _jsx("b", { children: node.label });
|
|
89
|
+
if (node.url) {
|
|
90
|
+
label = (_jsx("a", { onDragStart: (e) => e.preventDefault(), href: node.url, className: "text-primary hover:underline font-semibold", children: node.label }));
|
|
91
|
+
}
|
|
92
|
+
return (_jsxs("span", { onDragStart: (event) => {
|
|
93
|
+
handleDragStart(event, node.data);
|
|
94
|
+
}, onDragEnd: handleDragEnd, draggable: node.isDraggable, className: `flex gap-2 ${node.isDraggable ? "cursor-grab" : ""} ${options.className}`, children: [_jsx("img", { src: node.iconUrl, style: { height: "20px" }, width: "20", height: "20", onDragStart: (e) => e.preventDefault() }), label, node.loading && (_jsx(ProgressSpinner, { style: { width: "20px", height: "20px" } }))] }));
|
|
95
|
+
};
|
|
96
|
+
function handleDragStart(event, item) {
|
|
97
|
+
if (dragStart)
|
|
98
|
+
dragStart(item);
|
|
99
|
+
event.stopPropagation();
|
|
100
|
+
}
|
|
101
|
+
function handleDragEnd() {
|
|
102
|
+
if (dragEnd)
|
|
103
|
+
dragEnd();
|
|
104
|
+
}
|
|
105
|
+
const newSelectedKeys = {};
|
|
106
|
+
selectedItemIds === null || selectedItemIds === void 0 ? void 0 : selectedItemIds.forEach((x) => {
|
|
107
|
+
newSelectedKeys[x] = true;
|
|
108
|
+
});
|
|
109
|
+
return (_jsx("div", { onDragEnterCapture: (ev) => ev.stopPropagation(), onDragOverCapture: (ev) => ev.stopPropagation(), onDragLeaveCapture: (ev) => ev.stopPropagation(), children: _jsx(Tree, { value: treeNodes, expandedKeys: expandedKeys, onToggle: (e) => setExpandedKeys(e.value), nodeTemplate: nodeTemplate,
|
|
110
|
+
//dragdropScope={isDraggable ? "alpaca" : undefined}
|
|
111
|
+
className: "w-full alpaca-no-border p-0", onExpand: loadOnExpand, selectionMode: selectionMode, onSelectionChange: (ev) => {
|
|
112
|
+
if (onSelectionChange && selectionMode == "multiple")
|
|
113
|
+
onSelectionChange(Object.keys(ev.value || {}));
|
|
114
|
+
if (onSelectionChange && selectionMode == "single")
|
|
115
|
+
onSelectionChange([ev.value]);
|
|
116
|
+
}, selectionKeys: newSelectedKeys }) }));
|
|
117
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import JSONPretty from "react-json-pretty";
|
|
3
|
+
import "react-json-pretty/themes/monikai.css";
|
|
4
|
+
import { TabView, TabPanel } from "primereact/tabview";
|
|
5
|
+
export function Debug({ component, page }) {
|
|
6
|
+
if (!component && !page)
|
|
7
|
+
return;
|
|
8
|
+
return (_jsxs(TabView, { children: [component && _jsx(TabPanel, { header: "Component", children: _jsx(JSONPretty, { data: component }) }), _jsx(TabPanel, { header: "Page", children: _jsx(JSONPretty, { data: page }) })] }));
|
|
9
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
import { DataTable } from "primereact/datatable";
|
|
4
|
+
import { Column } from "primereact/column";
|
|
5
|
+
import { InputText } from "primereact/inputtext";
|
|
6
|
+
import { useEditContext } from "..";
|
|
7
|
+
export function DictionaryEditor({ dictionary }) {
|
|
8
|
+
if (!dictionary)
|
|
9
|
+
return;
|
|
10
|
+
const context = useEditContext();
|
|
11
|
+
if (!context) {
|
|
12
|
+
console.log("Context is undefined!");
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
let entries = Object.keys(dictionary).map((k) => ({
|
|
16
|
+
key: k,
|
|
17
|
+
translation: dictionary[k],
|
|
18
|
+
}));
|
|
19
|
+
entries = [...entries, ...context === null || context === void 0 ? void 0 : context.unresolvedDictionaryKeys.map(x => ({
|
|
20
|
+
key: x,
|
|
21
|
+
translation: "[undefined]"
|
|
22
|
+
}))];
|
|
23
|
+
entries.sort((a, b) => (a.key > b.key ? -1 : 1));
|
|
24
|
+
const textEditor = (options) => {
|
|
25
|
+
if (options.value != "[undefined]")
|
|
26
|
+
return _jsx(InputText, { type: "text", value: options.value, onChange: (e) => options.editorCallback(e.target.value) });
|
|
27
|
+
else
|
|
28
|
+
return null;
|
|
29
|
+
};
|
|
30
|
+
return (_jsx(_Fragment, { children: _jsxs(DataTable, { value: entries, children: [_jsx(Column, { field: "key", header: "Key" }), _jsx(Column, { field: "translation", header: "Translation", editor: (options) => textEditor(options) })] }) }));
|
|
31
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useState } from "react";
|
|
4
|
+
import { useEditContext } from "..";
|
|
5
|
+
export function EditFrame({ componentId, children, }) {
|
|
6
|
+
var _a, _b;
|
|
7
|
+
const editContext = useEditContext();
|
|
8
|
+
if (!editContext)
|
|
9
|
+
return children;
|
|
10
|
+
const { getComponentById, selection, setSelection } = editContext;
|
|
11
|
+
const [isRemoved, setIsRemoved] = useState(false);
|
|
12
|
+
const clientComponent = getComponentById(componentId);
|
|
13
|
+
if (!clientComponent) {
|
|
14
|
+
return children;
|
|
15
|
+
}
|
|
16
|
+
function select(e) {
|
|
17
|
+
e.stopPropagation();
|
|
18
|
+
if (clientComponent)
|
|
19
|
+
setSelection([clientComponent.id]);
|
|
20
|
+
}
|
|
21
|
+
let classNames = "ap-editframe";
|
|
22
|
+
let color = clientComponent.linkItemId ? "orange-400" : "sky-400";
|
|
23
|
+
if (clientComponent.hostingPageItem)
|
|
24
|
+
color = "purple-400";
|
|
25
|
+
const isSelected = selection && selection.indexOf(clientComponent.id) >= 0;
|
|
26
|
+
if (isSelected)
|
|
27
|
+
classNames = `ap-editframe relative ring-2 ring-${color}`;
|
|
28
|
+
function handleDragStart(event) {
|
|
29
|
+
if (!clientComponent)
|
|
30
|
+
return;
|
|
31
|
+
event.dataTransfer.setData("text/plain", clientComponent.id);
|
|
32
|
+
event.dataTransfer.setData("alpaca", clientComponent.id);
|
|
33
|
+
setTimeout(() => {
|
|
34
|
+
editContext.dragStart({
|
|
35
|
+
type: "component",
|
|
36
|
+
templateId: clientComponent.templateId,
|
|
37
|
+
componentId: clientComponent.id,
|
|
38
|
+
});
|
|
39
|
+
}, 50);
|
|
40
|
+
event.stopPropagation();
|
|
41
|
+
}
|
|
42
|
+
const isDraggable = isSelected && !clientComponent.hostingPageItem;
|
|
43
|
+
if ((_a = children.props) === null || _a === void 0 ? void 0 : _a.className)
|
|
44
|
+
classNames += " " + ((_b = children === null || children === void 0 ? void 0 : children.props) === null || _b === void 0 ? void 0 : _b.className);
|
|
45
|
+
if (isRemoved)
|
|
46
|
+
classNames += " ap-removed";
|
|
47
|
+
return (_jsxs("div", { className: classNames, onClick: select, draggable: isDraggable, onDragStart: handleDragStart, children: [isSelected && (_jsxs("div", { className: `absolute top-0 right-0 text-white px-3 bg-${color} ${isDraggable ? "cursor-move" : ""}`, children: [clientComponent.name, _jsx("button", { className: "ml-3", onClick: (ev) => {
|
|
48
|
+
ev.preventDefault();
|
|
49
|
+
ev.stopPropagation();
|
|
50
|
+
editContext.removeComponent(clientComponent.linkItemId || clientComponent.id, () => setIsRemoved(true));
|
|
51
|
+
}, children: _jsx("i", { className: "pi pi-trash" }) }), clientComponent.placeholders.length > 0 && (_jsx("button", { className: "ml-3", onClick: (ev) => {
|
|
52
|
+
editContext.setSelectedForInsertion(clientComponent.id);
|
|
53
|
+
editContext.openComponentPalette();
|
|
54
|
+
ev.stopPropagation();
|
|
55
|
+
ev.preventDefault();
|
|
56
|
+
}, children: _jsx("i", { className: "pi pi-plus" }) }))] })), children] }));
|
|
57
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Fragment as _Fragment, jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
export function EditHistory({ operations }) {
|
|
4
|
+
if (!operations)
|
|
5
|
+
return;
|
|
6
|
+
const description = (op) => {
|
|
7
|
+
if (op.type === "add-component")
|
|
8
|
+
return _jsxs(_Fragment, { children: ["Add ", op.itemName] });
|
|
9
|
+
if (op.type === "link-component")
|
|
10
|
+
return _jsxs(_Fragment, { children: ["Insert ", op.itemName] });
|
|
11
|
+
if (op.type === "remove-component")
|
|
12
|
+
return _jsxs(_Fragment, { children: ["Remove ", op.id] });
|
|
13
|
+
if (op.type === "edit-field") {
|
|
14
|
+
const editFieldOp = op;
|
|
15
|
+
return (_jsxs(_Fragment, { children: ["Edit ", editFieldOp.fieldName, _jsxs("span", { className: "text-gray-400 ml-1", children: ["(", editFieldOp.itemName, ", ", editFieldOp.language, ",", " ", editFieldOp.version, ")"] })] }));
|
|
16
|
+
}
|
|
17
|
+
return _jsx("div", { children: op.type });
|
|
18
|
+
};
|
|
19
|
+
return (_jsxs("div", { className: "inset-0 absolute", children: [_jsx("div", { className: "p-2 bg-gray-100 m-1", children: "History" }), _jsx("div", { className: "flex flex-col overflow-y-auto overflow-x-hidden", style: { height: "calc(100% - 45px)" }, children: operations.map((o, i) => singleOperation(i, o)) })] }));
|
|
20
|
+
function singleOperation(i, o) {
|
|
21
|
+
let className = "border-b p-2 flex justify-between";
|
|
22
|
+
if (o.undone)
|
|
23
|
+
className = className + " text-gray-300";
|
|
24
|
+
return (_jsxs("div", { className: className, children: [_jsx("div", { children: _jsx("small", { className: "text-color-secondary", children: description(o) }) }), _jsx("div", { className: "text-xs", children: o.user })] }, i));
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
|
11
|
+
import { useAlpacaContext, } from "..";
|
|
12
|
+
import { EditorClientHost } from "./EditorClientHost";
|
|
13
|
+
export function Editor({ children, content, }) {
|
|
14
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
15
|
+
const data = yield content;
|
|
16
|
+
if (data.type !== "page")
|
|
17
|
+
return;
|
|
18
|
+
if (!data.editing)
|
|
19
|
+
return _jsx(_Fragment, { children: children });
|
|
20
|
+
var alpacaContext = useAlpacaContext();
|
|
21
|
+
return (_jsx(_Fragment, { children: _jsx(EditorClientHost, { content: data, dictionaryObject: alpacaContext.dictionary, edit: alpacaContext.edit, children: children }) }));
|
|
22
|
+
});
|
|
23
|
+
}
|