@alpaca-headless/alpaca-headless-nextjs 0.0.4 → 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/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 +40 -4
- 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 +15 -0
- package/dist/cjs/loadRouteData.js +98 -40
- package/dist/cjs/mediaProtection.js +56 -0
- package/dist/editor.css +120 -0
- 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 +38 -5
- 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 +2 -0
- package/dist/esm/loadRouteData.js +97 -39
- package/dist/esm/mediaProtection.js +49 -0
- package/package.json +16 -4
- package/types/alpacaContext.d.ts +11 -0
- 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 +2 -0
- package/types/layoutData.d.ts +56 -1
- package/types/loadRouteData.d.ts +30 -1
- package/types/mediaProtection.d.ts +2 -0
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
13
|
+
import { hashImageUrl } from "../mediaProtection";
|
|
14
|
+
import { useAlpacaContext } from "..";
|
|
15
|
+
import { PictureEditor } from "./PictureEditor";
|
|
16
|
+
// const addClassName = (otherAttrs: { [key: string]: unknown }): void => {
|
|
17
|
+
// if (otherAttrs.class) {
|
|
18
|
+
// // if any classes are defined properly already
|
|
19
|
+
// if (otherAttrs.className) {
|
|
20
|
+
// let className: string = otherAttrs.className as string;
|
|
21
|
+
// className += ` ${otherAttrs.class}`;
|
|
22
|
+
// otherAttrs.className = className;
|
|
23
|
+
// } else {
|
|
24
|
+
// otherAttrs.className = otherAttrs.class;
|
|
25
|
+
// }
|
|
26
|
+
// delete otherAttrs.class;
|
|
27
|
+
// }
|
|
28
|
+
// };
|
|
29
|
+
export const Picture = (_a) => {
|
|
30
|
+
var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
31
|
+
var { field, imageParams, sources, defaultVariant, renderJsonLinkedData } = _a, otherProps = __rest(_a, ["field", "imageParams", "sources", "defaultVariant", "renderJsonLinkedData"]);
|
|
32
|
+
if (!field)
|
|
33
|
+
return null;
|
|
34
|
+
if ((_b = useAlpacaContext().pageContext) === null || _b === void 0 ? void 0 : _b.pageEditing)
|
|
35
|
+
return _jsx(PictureEditor, Object.assign({ field: field }, otherProps));
|
|
36
|
+
const variants = (_c = field.value) === null || _c === void 0 ? void 0 : _c.variants;
|
|
37
|
+
const img = (_e = (_d = field.value) === null || _d === void 0 ? void 0 : _d.variants.find((x) => x.name.toUpperCase() == (defaultVariant === null || defaultVariant === void 0 ? void 0 : defaultVariant.toUpperCase()))) !== null && _e !== void 0 ? _e : (_f = field.value) === null || _f === void 0 ? void 0 : _f.variants[0];
|
|
38
|
+
const attrs = Object.assign({ src: img === null || img === void 0 ? void 0 : img.src }, otherProps);
|
|
39
|
+
const video = img === null || img === void 0 ? void 0 : img.videoUrl;
|
|
40
|
+
const videoAttr = Object.assign({ src: video }, otherProps);
|
|
41
|
+
if (!(sources === null || sources === void 0 ? void 0 : sources.length)) {
|
|
42
|
+
return _jsx("img", Object.assign({}, attrs, { alt: (_g = field.value) === null || _g === void 0 ? void 0 : _g.alt }));
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
return (_jsxs(_Fragment, { children: [_jsxs("picture", { children: [sources === null || sources === void 0 ? void 0 : sources.map((source) => {
|
|
46
|
+
const variant = variants === null || variants === void 0 ? void 0 : variants.find((v) => v.name.toLowerCase() == source.variant.toLowerCase());
|
|
47
|
+
if (!(variant === null || variant === void 0 ? void 0 : variant.src))
|
|
48
|
+
return;
|
|
49
|
+
let srcSet = hashImageUrl(variant.src);
|
|
50
|
+
const getScaledImage = (variant, width) => {
|
|
51
|
+
if (width > variant.width)
|
|
52
|
+
return { src: variant.src, width: 0 };
|
|
53
|
+
else
|
|
54
|
+
return {
|
|
55
|
+
src: variant.src +
|
|
56
|
+
`${variant.src.includes("?") ? "&" : "?"}mw=` +
|
|
57
|
+
width,
|
|
58
|
+
width: width,
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
if (source.widths && source.widths.length) {
|
|
62
|
+
let scaledImages = source.widths.map((x) => getScaledImage(variant, x));
|
|
63
|
+
srcSet = "";
|
|
64
|
+
for (let w = 0; w < scaledImages.length; w++) {
|
|
65
|
+
if (srcSet.length)
|
|
66
|
+
srcSet = srcSet + ", ";
|
|
67
|
+
srcSet +=
|
|
68
|
+
hashImageUrl(scaledImages[w].src) +
|
|
69
|
+
" " +
|
|
70
|
+
source.widths[w] +
|
|
71
|
+
"w";
|
|
72
|
+
if (scaledImages[w].width === 0)
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
if (source.width) {
|
|
78
|
+
srcSet = hashImageUrl(getScaledImage(variant, source.width).src);
|
|
79
|
+
if (source.scales) {
|
|
80
|
+
let scaledImages = source.scales.map((x) => { var _a; return getScaledImage(variant, ((_a = source.width) !== null && _a !== void 0 ? _a : 0) * x); });
|
|
81
|
+
srcSet = "";
|
|
82
|
+
for (let w = 0; w < scaledImages.length; w++) {
|
|
83
|
+
if (srcSet.length)
|
|
84
|
+
srcSet = srcSet + ", ";
|
|
85
|
+
srcSet +=
|
|
86
|
+
hashImageUrl(scaledImages[w].src) +
|
|
87
|
+
" " +
|
|
88
|
+
source.scales[w] +
|
|
89
|
+
"x";
|
|
90
|
+
if (scaledImages[w].width === 0)
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return (_jsx("source", { srcSet: srcSet, media: source.media }, source.variant + source.media));
|
|
97
|
+
}), _jsx("img", Object.assign({}, attrs, { alt: (_h = field.value) === null || _h === void 0 ? void 0 : _h.alt }))] }), renderJsonLinkedData && !video ? (_jsx("script", { type: "application/ld+json", dangerouslySetInnerHTML: {
|
|
98
|
+
__html: JSON.stringify({
|
|
99
|
+
"@context": "http://schema.org",
|
|
100
|
+
"@type": "ImageObject",
|
|
101
|
+
image: img === null || img === void 0 ? void 0 : img.src,
|
|
102
|
+
description: (_j = field.value) === null || _j === void 0 ? void 0 : _j.alt,
|
|
103
|
+
name: (_k = field.value) === null || _k === void 0 ? void 0 : _k.name,
|
|
104
|
+
}),
|
|
105
|
+
} })) : null, video && _jsx("video", Object.assign({}, videoAttr)), renderJsonLinkedData && video ? (_jsx("script", { type: "application/ld+json", dangerouslySetInnerHTML: {
|
|
106
|
+
__html: JSON.stringify({
|
|
107
|
+
"@context": "http://schema.org",
|
|
108
|
+
"@type": "VideoObject",
|
|
109
|
+
contentUrl: img === null || img === void 0 ? void 0 : img.src,
|
|
110
|
+
description: (_l = field.value) === null || _l === void 0 ? void 0 : _l.alt,
|
|
111
|
+
name: (_m = field.value) === null || _m === void 0 ? void 0 : _m.name,
|
|
112
|
+
}),
|
|
113
|
+
} })) : null] }));
|
|
114
|
+
}
|
|
115
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
14
|
+
import { useState } from "react";
|
|
15
|
+
import { Picture } from "./Picture";
|
|
16
|
+
import { useEditContext } from "..";
|
|
17
|
+
import { MediaSelector } from "../editor/MediaSelector";
|
|
18
|
+
import { Dialog } from "primereact/dialog";
|
|
19
|
+
export const PictureEditor = (_a) => {
|
|
20
|
+
var _b, _c;
|
|
21
|
+
var { field, imageParams, sources, defaultVariant, renderJsonLinkedData } = _a, otherProps = __rest(_a, ["field", "imageParams", "sources", "defaultVariant", "renderJsonLinkedData"]);
|
|
22
|
+
function selectImage() {
|
|
23
|
+
setMediaSelectorVisible(true);
|
|
24
|
+
}
|
|
25
|
+
const editContext = useEditContext();
|
|
26
|
+
const [mediaSelectorVisible, setMediaSelectorVisible] = useState(false);
|
|
27
|
+
const [editorVisible, setEditorVisible] = useState(false);
|
|
28
|
+
if (!editContext)
|
|
29
|
+
return;
|
|
30
|
+
function imageSelected(imageId) {
|
|
31
|
+
const value = (field === null || field === void 0 ? void 0 : field.value) || {};
|
|
32
|
+
//value.variants[0].mediaId = imageId;
|
|
33
|
+
console.log(imageId);
|
|
34
|
+
if (field)
|
|
35
|
+
editContext === null || editContext === void 0 ? void 0 : editContext.editField(field, JSON.stringify(value), false);
|
|
36
|
+
}
|
|
37
|
+
console.log(JSON.stringify(field));
|
|
38
|
+
return (_jsxs(_Fragment, { children: [_jsx(MediaSelector, { visible: mediaSelectorVisible, onHide: () => setMediaSelectorVisible(false), onMediaSelected: imageSelected }), _jsxs(Dialog, { header: "Header", visible: editorVisible, style: { width: "50vw" }, onHide: () => setEditorVisible(false), children: [_jsx("div", { className: "flex gap-1", children: (_c = (_b = field === null || field === void 0 ? void 0 : field.value) === null || _b === void 0 ? void 0 : _b.variants) === null || _c === void 0 ? void 0 : _c.map((variant) => (_jsxs("div", { children: [_jsx("div", { className: "h-24 w-24 border", children: variant.src && _jsx("img", { src: variant.src }) }), _jsx("div", { children: variant.name }), _jsx("div", { children: variant.aspectRatioText })] }))) }), _jsx("div", { onClick: selectImage, children: "Select image" })] }), _jsxs("span", Object.assign({}, otherProps, { onClick: () => setEditorVisible(true), children: ["PICTURE", _jsx(Picture, { field: field, imageParams: imageParams, sources: sources })] }))] }));
|
|
39
|
+
};
|
|
@@ -7,12 +7,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
10
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
11
|
+
import { EditFrame } from "../editor/EditFrame";
|
|
11
12
|
import { useAlpacaContext, } from "..";
|
|
13
|
+
import { PlaceholderDropZoneHost } from "../editor/PlaceholderDropZoneHost";
|
|
14
|
+
import Slot from "./Slot";
|
|
12
15
|
export function Placeholder({ name, content, }) {
|
|
13
16
|
return __awaiter(this, void 0, void 0, function* () {
|
|
14
17
|
const data = yield content;
|
|
15
|
-
if (data
|
|
18
|
+
if (!data || !("placeholders" in data))
|
|
16
19
|
return;
|
|
17
20
|
const placeholderData = data.placeholders.find((x) => x.name == name);
|
|
18
21
|
if (!placeholderData)
|
|
@@ -20,10 +23,40 @@ export function Placeholder({ name, content, }) {
|
|
|
20
23
|
const context = useAlpacaContext();
|
|
21
24
|
const loader = context.componentModuleLoader;
|
|
22
25
|
const promises = placeholderData === null || placeholderData === void 0 ? void 0 : placeholderData.components.map((component) => __awaiter(this, void 0, void 0, function* () {
|
|
23
|
-
|
|
24
|
-
|
|
26
|
+
if (component.componentType == "Slot")
|
|
27
|
+
return { Component: Slot, data: component, parent: data };
|
|
28
|
+
let module = null;
|
|
29
|
+
try {
|
|
30
|
+
module = yield loader(component.componentType);
|
|
31
|
+
}
|
|
32
|
+
catch (e) {
|
|
33
|
+
console.log(e);
|
|
34
|
+
}
|
|
35
|
+
if (!module) {
|
|
36
|
+
console.log("Could not find module " + component.componentType);
|
|
37
|
+
return {
|
|
38
|
+
data: { name: component.componentType, id: "0" },
|
|
39
|
+
Component: ComponentNotFound,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
return { parent: data, data: component, Component: module.default };
|
|
25
43
|
}));
|
|
26
44
|
const components = yield Promise.all(promises);
|
|
27
|
-
|
|
45
|
+
if (context.pageContext.pageEditing) {
|
|
46
|
+
return (_jsxs(_Fragment, { children: [components.map(({ Component, data, parent }, index) => {
|
|
47
|
+
return (_jsxs(_Fragment, { children: [_jsx(PlaceholderDropZoneHost, { parentName: parent === null || parent === void 0 ? void 0 : parent.name, placeholder: placeholderData, index: index + 1 }), _jsx(EditFrame, { componentId: data.id, children: _jsx(Component, { component: data }) }, data.id)] }));
|
|
48
|
+
}), _jsx(PlaceholderDropZoneHost, { parentName: data === null || data === void 0 ? void 0 : data.name, placeholder: placeholderData, index: components.length + 1 })] }));
|
|
49
|
+
}
|
|
50
|
+
else
|
|
51
|
+
return (_jsx(_Fragment, { children: components.map(({ Component, data }) => (_jsx(_Fragment, { children: _jsx(Component, { component: data }) }))) }));
|
|
28
52
|
});
|
|
29
53
|
}
|
|
54
|
+
function ComponentNotFound({ component }) {
|
|
55
|
+
return (_jsxs("div", { style: {
|
|
56
|
+
backgroundColor: "orange",
|
|
57
|
+
color: "red",
|
|
58
|
+
fontSize: 18,
|
|
59
|
+
padding: 10,
|
|
60
|
+
border: "3px solid red",
|
|
61
|
+
}, children: ["Component not found: ", component.name, " "] }));
|
|
62
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
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
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
11
|
+
var t = {};
|
|
12
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
13
|
+
t[p] = s[p];
|
|
14
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
15
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
16
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
17
|
+
t[p[i]] = s[p[i]];
|
|
18
|
+
}
|
|
19
|
+
return t;
|
|
20
|
+
};
|
|
21
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
22
|
+
import React from "react";
|
|
23
|
+
import { RichTextEditor } from "./RichTextEditor";
|
|
24
|
+
import { useAlpacaContext } from "..";
|
|
25
|
+
export function RichText(_a) {
|
|
26
|
+
var { field, tag, editable } = _a, props = __rest(_a, ["field", "tag", "editable"]);
|
|
27
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
28
|
+
if (!field)
|
|
29
|
+
return;
|
|
30
|
+
const internalProps = Object.assign(Object.assign({}, props), { dangerouslySetInnerHTML: {
|
|
31
|
+
__html: field.value,
|
|
32
|
+
}, editable: editable, contentEditable: true, "data-test": "test", placeholder: '[' + field.name + ']' });
|
|
33
|
+
if (useAlpacaContext().pageContext.pageEditing)
|
|
34
|
+
return _jsx(RichTextEditor, Object.assign({ field: field, tag: tag }, props));
|
|
35
|
+
return React.createElement(tag || "div", Object.assign(props, internalProps));
|
|
36
|
+
});
|
|
37
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
import React, { useEffect, useState, useMemo, useCallback } from "react";
|
|
14
|
+
import { useEditContext } from "../editor/editContext";
|
|
15
|
+
export function RichTextEditor(_a) {
|
|
16
|
+
var { field, tag } = _a, props = __rest(_a, ["field", "tag"]);
|
|
17
|
+
const editContext = useEditContext();
|
|
18
|
+
const [value, setValue] = useState("");
|
|
19
|
+
const [editedValue, setEditedValue] = useState();
|
|
20
|
+
if (!editContext)
|
|
21
|
+
return;
|
|
22
|
+
const { updateContentEditingFields } = editContext;
|
|
23
|
+
const component = editContext.getComponentById(field.itemId);
|
|
24
|
+
if (!component)
|
|
25
|
+
return;
|
|
26
|
+
const liveField = Object.values(component.fields).find((f) => f.id == field.id);
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
if (editedValue != liveField.value &&
|
|
29
|
+
"<p>" + editedValue + "</p>" != liveField.value) {
|
|
30
|
+
// console.log(
|
|
31
|
+
// "editedValue:" + editedValue + " liveField.value " + liveField.value
|
|
32
|
+
// );
|
|
33
|
+
setValue(liveField.value);
|
|
34
|
+
}
|
|
35
|
+
}, [liveField.value]);
|
|
36
|
+
useEffect(() => {
|
|
37
|
+
setValue(liveField.value); // Otherwise react would not update the field after the refresh
|
|
38
|
+
}, [updateContentEditingFields]);
|
|
39
|
+
const setFieldValue = (val) => {
|
|
40
|
+
if (val != editedValue) {
|
|
41
|
+
setEditedValue(val);
|
|
42
|
+
if (editContext)
|
|
43
|
+
editContext.editField(field, val, true);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
const eventHandler = useCallback((e) => {
|
|
47
|
+
setFieldValue(e.currentTarget.innerHTML);
|
|
48
|
+
}, [editContext.editField]);
|
|
49
|
+
return useMemo(() => {
|
|
50
|
+
const properies = Object.assign(Object.assign({}, props), { contentEditable: true, suppressContentEditableWarning: true, onInput: eventHandler, placeholder: "[" + field.name + "]", dangerouslySetInnerHTML: {
|
|
51
|
+
__html: value,
|
|
52
|
+
} });
|
|
53
|
+
return React.createElement(tag || "div", properies);
|
|
54
|
+
}, [value]);
|
|
55
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { Placeholder } from "..";
|
|
3
|
+
export default function Section({ component }) {
|
|
4
|
+
return (_jsx(_Fragment, { children: _jsx(Placeholder, { name: "ph-slot-content", content: component }) }));
|
|
5
|
+
}
|
|
@@ -7,12 +7,32 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
11
|
+
var t = {};
|
|
12
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
13
|
+
t[p] = s[p];
|
|
14
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
15
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
16
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
17
|
+
t[p[i]] = s[p[i]];
|
|
18
|
+
}
|
|
19
|
+
return t;
|
|
20
|
+
};
|
|
21
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
10
22
|
import React from "react";
|
|
11
|
-
|
|
23
|
+
import { TextEditor } from "./TextEditor";
|
|
24
|
+
import { useAlpacaContext } from "..";
|
|
25
|
+
export function Text(_a) {
|
|
26
|
+
var { field, tag, editable } = _a, props = __rest(_a, ["field", "tag", "editable"]);
|
|
12
27
|
return __awaiter(this, void 0, void 0, function* () {
|
|
13
|
-
if (
|
|
14
|
-
return
|
|
28
|
+
if (!field)
|
|
29
|
+
return;
|
|
30
|
+
if (field.jsonValue) {
|
|
31
|
+
field = field.jsonValue;
|
|
32
|
+
}
|
|
33
|
+
if (useAlpacaContext().pageContext.pageEditing)
|
|
34
|
+
return _jsx(TextEditor, Object.assign({ field: field, tag: tag }, props));
|
|
15
35
|
else
|
|
16
|
-
return React.createElement(tag || "div",
|
|
36
|
+
return React.createElement(tag || "div", props, field.value);
|
|
17
37
|
});
|
|
18
38
|
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
import React, { useEffect, useState } from "react";
|
|
14
|
+
import { useEditContext } from "../editor/editContext";
|
|
15
|
+
export function TextEditor(_a) {
|
|
16
|
+
var { field, tag } = _a, props = __rest(_a, ["field", "tag"]);
|
|
17
|
+
const editContext = useEditContext();
|
|
18
|
+
const [value, setValue] = useState("");
|
|
19
|
+
const [editedValue, setEditedValue] = useState();
|
|
20
|
+
if (!editContext)
|
|
21
|
+
return;
|
|
22
|
+
const { updateContentEditingFields } = editContext;
|
|
23
|
+
const component = editContext.getComponentById(field.itemId);
|
|
24
|
+
if (!component)
|
|
25
|
+
return;
|
|
26
|
+
const liveField = Object.values(component.fields).find((f) => f.id == field.id);
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
if (editedValue != liveField.value)
|
|
29
|
+
setValue(liveField.value);
|
|
30
|
+
}, [liveField.value]);
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
setValue(liveField.value); // Otherwise react would not update the field after the refresh
|
|
33
|
+
}, [updateContentEditingFields]);
|
|
34
|
+
const properies = Object.assign(Object.assign({}, props), { contentEditable: true, suppressContentEditableWarning: true, onInput: (e) => setFieldValue(e.currentTarget.textContent), placeholder: "[" + field.name + "]" });
|
|
35
|
+
const setFieldValue = (val) => {
|
|
36
|
+
setEditedValue(val);
|
|
37
|
+
if (editContext)
|
|
38
|
+
editContext.editField(field, val, true);
|
|
39
|
+
};
|
|
40
|
+
return React.createElement(tag || "div", properies, value);
|
|
41
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useAlpacaContext } from "..";
|
|
3
|
+
import { TranslateEditor } from "../editor/TranslateEditor";
|
|
4
|
+
export function Translate({ text }) {
|
|
5
|
+
const context = useAlpacaContext();
|
|
6
|
+
const dictionary = context.dictionary;
|
|
7
|
+
if (context.pageContext.pageEditing)
|
|
8
|
+
return _jsx(TranslateEditor, { text: text });
|
|
9
|
+
return dictionary[text] || text;
|
|
10
|
+
}
|
|
@@ -0,0 +1,146 @@
|
|
|
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 { useEffect, useRef, useState } from 'react';
|
|
13
|
+
import { TerminalService } from 'primereact/terminalservice';
|
|
14
|
+
import { useRouter, useSearchParams } from "next/navigation";
|
|
15
|
+
import { Terminal } from './Terminal';
|
|
16
|
+
export function AiTerminal({ requestRefresh, selection }) {
|
|
17
|
+
const searchParams = useSearchParams();
|
|
18
|
+
const [messages, setMessages] = useState([]);
|
|
19
|
+
const [tokens, setTokens] = useState({ in: 0, out: 0 });
|
|
20
|
+
const selectionRef = useRef(selection);
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
selectionRef.current = selection;
|
|
23
|
+
}, [selection]);
|
|
24
|
+
const messagesRef = useRef(messages);
|
|
25
|
+
useEffect(() => {
|
|
26
|
+
messagesRef.current = messages;
|
|
27
|
+
}, [messages]);
|
|
28
|
+
const router = useRouter();
|
|
29
|
+
function commandHandler(text, callback) {
|
|
30
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
+
const newMessages = [...messagesRef.current, { content: text, 'role': 'user', 'name': 'user' }];
|
|
32
|
+
let lastRefresh = new Date().getTime();
|
|
33
|
+
const response = yield prompt(newMessages, selectionRef.current, searchParams.get("session"), searchParams.get("itemid"), searchParams.get("language"), searchParams.get("version"), (response) => {
|
|
34
|
+
console.log(response);
|
|
35
|
+
setTokens({ in: response.numInputTokens, out: response.numOutputTokens });
|
|
36
|
+
handleResponse(response, callback, false);
|
|
37
|
+
if (response.editOperations.length) {
|
|
38
|
+
if (new Date().getTime() - lastRefresh > 500) {
|
|
39
|
+
requestRefresh(false);
|
|
40
|
+
router.refresh();
|
|
41
|
+
lastRefresh = new Date().getTime();
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
if (response) {
|
|
46
|
+
handleResponse(response, callback, true);
|
|
47
|
+
setTokens({ in: response.numInputTokens, out: response.numOutputTokens });
|
|
48
|
+
router.refresh();
|
|
49
|
+
}
|
|
50
|
+
// if (response) {
|
|
51
|
+
// messages.push({content: text, 'role': 'assistant', 'name': 'assistant'});
|
|
52
|
+
// if(response.editOperations) {
|
|
53
|
+
// const newEditOperations = [...editOperationsRef.current, {
|
|
54
|
+
// type:'composite',
|
|
55
|
+
// name: 'ghostwriter',
|
|
56
|
+
// date: new Date(),
|
|
57
|
+
// operations: response.editOperations
|
|
58
|
+
// }];
|
|
59
|
+
// setEditOperations(newEditOperations);
|
|
60
|
+
// }
|
|
61
|
+
if (response === null || response === void 0 ? void 0 : response.responseText)
|
|
62
|
+
newMessages.push({ content: response.responseText, 'role': 'assistant', 'name': 'assistant' });
|
|
63
|
+
// TerminalService.emit('response', response.responseText);
|
|
64
|
+
// }
|
|
65
|
+
// // else
|
|
66
|
+
// // TerminalService.emit('clear');
|
|
67
|
+
setMessages(newMessages);
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
;
|
|
71
|
+
useEffect(() => {
|
|
72
|
+
TerminalService.on('command', commandHandler);
|
|
73
|
+
return () => {
|
|
74
|
+
TerminalService.off('command', commandHandler);
|
|
75
|
+
};
|
|
76
|
+
}, []);
|
|
77
|
+
return (_jsxs("div", { className: 'h-full flex flex-col relative', children: [_jsx("div", { className: 'flex-1 relative', children: _jsx("div", { className: 'inset-0 absolute', children: _jsx(Terminal, { onReset: () => setMessages([]), commandHandler: (v, callback) => {
|
|
78
|
+
commandHandler(v, callback);
|
|
79
|
+
} }) }) }), _jsxs("div", { className: 'text-xs', children: ["Tokens in: ", tokens.in, " out: ", tokens.out] })] }));
|
|
80
|
+
}
|
|
81
|
+
function prompt(messages, selection, session, itemid, language, version, callback) {
|
|
82
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
83
|
+
const response = yield fetch("/alpaca/headless/ai/prompt", {
|
|
84
|
+
method: "POST",
|
|
85
|
+
body: JSON.stringify({ messages,
|
|
86
|
+
itemid,
|
|
87
|
+
language,
|
|
88
|
+
version,
|
|
89
|
+
selection,
|
|
90
|
+
sessionId: session }),
|
|
91
|
+
credentials: 'omit',
|
|
92
|
+
headers: {
|
|
93
|
+
"Content-Type": "application/json",
|
|
94
|
+
//Cookie: 'test'// new Cookies().getAll(),
|
|
95
|
+
},
|
|
96
|
+
next: {
|
|
97
|
+
revalidate: 0,
|
|
98
|
+
},
|
|
99
|
+
});
|
|
100
|
+
if (!(response === null || response === void 0 ? void 0 : response.body))
|
|
101
|
+
return null;
|
|
102
|
+
const reader = response.body.getReader();
|
|
103
|
+
const decoder = new TextDecoder();
|
|
104
|
+
let buffer = '';
|
|
105
|
+
let result = null;
|
|
106
|
+
while (true) {
|
|
107
|
+
const { done, value } = yield reader.read();
|
|
108
|
+
if (done) {
|
|
109
|
+
break;
|
|
110
|
+
}
|
|
111
|
+
buffer += decoder.decode(value, { stream: true }); // 'stream: true' ensures that any incomplete multi-byte characters aren't malformed.
|
|
112
|
+
// Split the buffer by newline and keep the last partial line for the next iteration.
|
|
113
|
+
const lines = buffer.split('\n');
|
|
114
|
+
if (lines.length > 0) {
|
|
115
|
+
buffer = lines.pop() || ""; // Incomplete line (if any) is kept for the next iteration.
|
|
116
|
+
for (let line of lines) {
|
|
117
|
+
if (line.trim() === '')
|
|
118
|
+
continue; // Skip empty lines if any.
|
|
119
|
+
try {
|
|
120
|
+
const jsonData = JSON.parse(line);
|
|
121
|
+
callback(jsonData);
|
|
122
|
+
result = jsonData;
|
|
123
|
+
}
|
|
124
|
+
catch (e) {
|
|
125
|
+
console.error('Error parsing line:' + line, e);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
// If there's any remaining content in the buffer after processing all chunks, try to process it.
|
|
131
|
+
if (buffer.trim() !== '') {
|
|
132
|
+
try {
|
|
133
|
+
const jsonData = JSON.parse(buffer);
|
|
134
|
+
result = jsonData;
|
|
135
|
+
}
|
|
136
|
+
catch (e) {
|
|
137
|
+
console.error('Error parsing the final buffer content:', e);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return result;
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
function handleResponse(response, terminalCallback, isFinished) {
|
|
144
|
+
console.log(response.responseText);
|
|
145
|
+
terminalCallback(response.responseText, isFinished);
|
|
146
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
export function ComponentInfo({ component, }) {
|
|
4
|
+
var _a;
|
|
5
|
+
if (!(component === null || component === void 0 ? void 0 : component.fields))
|
|
6
|
+
return;
|
|
7
|
+
const hostingPageItem = component.hostingPageItem ? (_jsx("div", { children: _jsxs("div", { className: "text-xs", children: ["Source: ", component.hostingPageItem.path, "( ID:", " ", component.hostingPageItem.id, ")"] }) })) : null;
|
|
8
|
+
const linkedComponent = component.linkedComponentItem ? (_jsx("div", { children: _jsxs("div", { className: "text-xs", children: ["Source: ", component.linkedComponentItem.path] }) })) : null;
|
|
9
|
+
return (_jsxs("div", { className: "p-1", children: [_jsx("h2", { className: "text-xl font-bold my-2", children: component.name }), _jsxs("div", { className: "text-xs", children: ["ID: ", component.id] }), _jsxs("div", { className: "text-xs", children: ["Languages: ", (_a = component.translations) === null || _a === void 0 ? void 0 : _a.join(", ")] }), hostingPageItem, linkedComponent] }));
|
|
10
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useEditContext } from "..";
|
|
3
|
+
import ContentTree from "./ContentTree";
|
|
4
|
+
export function ComponentPalette({ selection, page, dragStart, dragEnd, }) {
|
|
5
|
+
const editContext = useEditContext();
|
|
6
|
+
if (!editContext)
|
|
7
|
+
return;
|
|
8
|
+
const insertingPlaceholderKeys = selection
|
|
9
|
+
.map((x) => editContext.getComponentById(x))
|
|
10
|
+
.filter((x) => x)
|
|
11
|
+
.reduce((a, x) => a.concat(x.placeholders.map((y) => y.key)), []);
|
|
12
|
+
const selectedPlaceholderKeys = [
|
|
13
|
+
...selection.filter((x) => x.indexOf("_") > 0),
|
|
14
|
+
...insertingPlaceholderKeys,
|
|
15
|
+
];
|
|
16
|
+
const insertOptions = collectInsertOptions(page, selectedPlaceholderKeys);
|
|
17
|
+
// function directInsert() {
|
|
18
|
+
// if (editContext!.selectedForInsertion.indexOf("_") > 0) {
|
|
19
|
+
// var lastUnderscoreIndex =
|
|
20
|
+
// editContext!.selectedForInsertion.lastIndexOf("_");
|
|
21
|
+
// const index = editContext!.selectedForInsertion.substring(
|
|
22
|
+
// lastUnderscoreIndex + 1
|
|
23
|
+
// );
|
|
24
|
+
// const key = editContext!.selectedForInsertion.substring(
|
|
25
|
+
// 0,
|
|
26
|
+
// lastUnderscoreIndex
|
|
27
|
+
// );
|
|
28
|
+
// editContext!.droppedInPlaceholder(key, parseInt(index));
|
|
29
|
+
// }
|
|
30
|
+
// }
|
|
31
|
+
return (_jsxs(_Fragment, { children: [_jsx("h2", { className: "text-xl font-bold mb-8", children: "New" }), _jsx("div", { className: "grid grid-cols-4 gap-1", children: insertOptions.map((option) => {
|
|
32
|
+
function handleDragStart(event) {
|
|
33
|
+
dragStart({ type: "template", templateId: option.id });
|
|
34
|
+
event.stopPropagation();
|
|
35
|
+
}
|
|
36
|
+
function handleDragEnd() {
|
|
37
|
+
dragEnd();
|
|
38
|
+
}
|
|
39
|
+
return (_jsxs("div", {
|
|
40
|
+
// onClick={directInsert}
|
|
41
|
+
draggable: true, onDragStart: handleDragStart, onDragEnd: handleDragEnd, className: "p-3 shadow-md flex items-center flex-col gap-1 cursor-grab", children: [_jsx("img", { src: option.icon, width: "32", height: "32" }), option.name] }, option.id));
|
|
42
|
+
}) }), _jsx("h2", { className: "text-xl font-bold my-8", children: "Existing" }), _jsx(ContentTree, { rootItemId: "0DE95AE4-41AB-4D01-9EB0-67441B7C2450", dragStart: (itemNode) => {
|
|
43
|
+
dragStart({
|
|
44
|
+
type: "link-component",
|
|
45
|
+
templateId: itemNode.templateId,
|
|
46
|
+
componentId: itemNode.id,
|
|
47
|
+
});
|
|
48
|
+
}, expandIdPath: page.idPath, dragEnd: dragEnd, isDraggable: (x) => x.isComponent &&
|
|
49
|
+
(insertOptions === null || insertOptions === void 0 ? void 0 : insertOptions.find((insertOption) => insertOption.id == x.templateId)) != undefined })] }));
|
|
50
|
+
}
|
|
51
|
+
function collectInsertOptions(page, placeholderKeys) {
|
|
52
|
+
const insertOptionsMap = new Map();
|
|
53
|
+
function traverse(placeholders) {
|
|
54
|
+
for (const placeholder of placeholders) {
|
|
55
|
+
if (placeholder.insertOptions &&
|
|
56
|
+
(placeholderKeys.length === 0 ||
|
|
57
|
+
placeholderKeys.includes(placeholder.key))) {
|
|
58
|
+
for (const option of placeholder.insertOptions) {
|
|
59
|
+
insertOptionsMap.set(option.id, option);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
for (const component of placeholder.components) {
|
|
63
|
+
traverse(component.placeholders);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
traverse(page.placeholders);
|
|
68
|
+
// Convert the map back into an array of objects
|
|
69
|
+
const insertOptionsArray = Array.from(insertOptionsMap.values());
|
|
70
|
+
return insertOptionsArray;
|
|
71
|
+
}
|