@puckeditor/plugin-ai 0.9.0-canary.52479cfe → 0.9.0-canary.53ee4e95
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/index.css +38 -36
- package/dist/index.d.mts +0 -53
- package/dist/index.d.ts +0 -53
- package/dist/index.js +617 -852
- package/dist/index.mjs +544 -779
- package/package.json +9 -9
package/dist/index.js
CHANGED
|
@@ -995,7 +995,7 @@ function useChat({
|
|
|
995
995
|
// src/components/Chat/index.tsx
|
|
996
996
|
var import_core5 = require("@puckeditor/core");
|
|
997
997
|
var import_ai5 = require("ai");
|
|
998
|
-
var
|
|
998
|
+
var import_react27 = require("react");
|
|
999
999
|
var import_ulid = require("ulid");
|
|
1000
1000
|
|
|
1001
1001
|
// ../utils/lib/get-class-name-factory.ts
|
|
@@ -1097,7 +1097,7 @@ init_react_import();
|
|
|
1097
1097
|
|
|
1098
1098
|
// css-module:/home/runner/work/platform/platform/packages/platform-client/components/Modal/Modal.module.css#css-module
|
|
1099
1099
|
init_react_import();
|
|
1100
|
-
var Modal_module_default = { "Modal-background": "_Modal-
|
|
1100
|
+
var Modal_module_default = { "Modal-background": "_Modal-background_mocy5_1", "Modal--visible": "_Modal--visible_mocy5_16", "Modal-modal": "_Modal-modal_mocy5_22" };
|
|
1101
1101
|
|
|
1102
1102
|
// ../platform-client/components/Modal/Modal.tsx
|
|
1103
1103
|
var import_react9 = require("react");
|
|
@@ -1200,12 +1200,13 @@ var Button = ({
|
|
|
1200
1200
|
secondary: variant === "secondary",
|
|
1201
1201
|
danger: variant === "danger",
|
|
1202
1202
|
ghost: variant === "ghost",
|
|
1203
|
-
|
|
1203
|
+
// Disabled while its click is still running, too.
|
|
1204
|
+
disabled: disabled || loading,
|
|
1204
1205
|
fullWidth,
|
|
1205
1206
|
[size]: true
|
|
1206
1207
|
}),
|
|
1207
1208
|
onClick: (e) => {
|
|
1208
|
-
if (disabled) {
|
|
1209
|
+
if (disabled || loading) {
|
|
1209
1210
|
e.preventDefault();
|
|
1210
1211
|
return;
|
|
1211
1212
|
}
|
|
@@ -1593,7 +1594,7 @@ var import_react15 = require("react");
|
|
|
1593
1594
|
|
|
1594
1595
|
// css-module:/home/runner/work/platform/platform/packages/platform-client/components/Menu/styles.module.css#css-module
|
|
1595
1596
|
init_react_import();
|
|
1596
|
-
var styles_module_default4 = { "Menu": "
|
|
1597
|
+
var styles_module_default4 = { "Menu": "_Menu_1jr57_1", "Menu-content": "_Menu-content_1jr57_6", "Menu-sections": "_Menu-sections_1jr57_11", "Menu-action": "_Menu-action_1jr57_22", "Menu-list": "_Menu-list_1jr57_44", "Menu-item": "_Menu-item_1jr57_55", "Menu-item--disabled": "_Menu-item--disabled_1jr57_84" };
|
|
1597
1598
|
|
|
1598
1599
|
// ../platform-client/components/Menu/index.tsx
|
|
1599
1600
|
var import_jsx_runtime17 = require("react/jsx-runtime");
|
|
@@ -1704,7 +1705,7 @@ init_react_import();
|
|
|
1704
1705
|
|
|
1705
1706
|
// css-module:/home/runner/work/platform/platform/packages/platform-client/components/Tag/Tag.module.css#css-module
|
|
1706
1707
|
init_react_import();
|
|
1707
|
-
var Tag_module_default = { "Tag": "
|
|
1708
|
+
var Tag_module_default = { "Tag": "_Tag_162k8_1", "Tag--borderless": "_Tag--borderless_162k8_21", "Tag--colorBlue": "_Tag--colorBlue_162k8_25", "Tag--colorGreen": "_Tag--colorGreen_162k8_30", "Tag--colorRed": "_Tag--colorRed_162k8_34", "Tag--colorMuted": "_Tag--colorMuted_162k8_38", "Tag-sprite": "_Tag-sprite_162k8_42", "Tag--pulse": "_Tag--pulse_162k8_46", "pulse": "_pulse_162k8_1", "Tag-label": "_Tag-label_162k8_80" };
|
|
1708
1709
|
|
|
1709
1710
|
// ../platform-client/components/Tag/Tag.tsx
|
|
1710
1711
|
var import_jsx_runtime22 = require("react/jsx-runtime");
|
|
@@ -1758,19 +1759,13 @@ var styles_module_default6 = { "Viewport": "_Viewport_1vvhm_3", "Viewport--stand
|
|
|
1758
1759
|
var import_jsx_runtime26 = require("react/jsx-runtime");
|
|
1759
1760
|
var cx6 = getClassNameFactory("Viewport", styles_module_default6);
|
|
1760
1761
|
|
|
1761
|
-
// ../platform-client/context/editor.tsx
|
|
1762
|
-
init_react_import();
|
|
1763
|
-
var import_react18 = require("react");
|
|
1764
|
-
var import_jsx_runtime27 = require("react/jsx-runtime");
|
|
1765
|
-
var ctx = (0, import_react18.createContext)({});
|
|
1766
|
-
|
|
1767
1762
|
// css-module:/home/runner/work/platform/platform/packages/plugin-ai/src/components/ChatBody/styles.module.css#css-module
|
|
1768
1763
|
init_react_import();
|
|
1769
1764
|
var styles_module_default7 = { "Chat": "_Chat_5z5yi_1", "Chat--hasMessages": "_Chat--hasMessages_5z5yi_17", "Chat-inner": "_Chat-inner_5z5yi_28", "Chat--hasChildren": "_Chat--hasChildren_5z5yi_40", "Chat-body": "_Chat-body_5z5yi_45", "Chat--isLoading": "_Chat--isLoading_5z5yi_52", "Chat-messages": "_Chat-messages_5z5yi_56", "Chat-form": "_Chat-form_5z5yi_63", "Chat--hideInput": "_Chat--hideInput_5z5yi_68", "Chat-formHelper": "_Chat-formHelper_5z5yi_82", "Chat-examplePrompts": "_Chat-examplePrompts_5z5yi_97", "Chat-examplePrompt": "_Chat-examplePrompt_5z5yi_97", "Chat-examplePromptArrow": "_Chat-examplePromptArrow_5z5yi_134", "Chat-default": "_Chat-default_5z5yi_139", "ChatMessage": "_ChatMessage_5z5yi_155", "ChatMessage--userRole": "_ChatMessage--userRole_5z5yi_164", "ChatMessage-userBubble": "_ChatMessage-userBubble_5z5yi_164", "ChatMessage-userAttachments": "_ChatMessage-userAttachments_5z5yi_175", "ChatMessage-thumbnail": "_ChatMessage-thumbnail_5z5yi_181", "ChatMessage-thumbnailLabel": "_ChatMessage-thumbnailLabel_5z5yi_211", "ChatMessage-text": "_ChatMessage-text_5z5yi_284", "ChatMessage-event": "_ChatMessage-event_5z5yi_319", "ChatMessage-eventBody": "_ChatMessage-eventBody_5z5yi_323", "ChatMessage-eventCollapse": "_ChatMessage-eventCollapse_5z5yi_332", "ChatMessage-eventHeader": "_ChatMessage-eventHeader_5z5yi_336", "ChatMessage-eventExpand": "_ChatMessage-eventExpand_5z5yi_336", "ChatMessage-eventIcon": "_ChatMessage-eventIcon_5z5yi_362", "ChatMessage-eventLabel": "_ChatMessage-eventLabel_5z5yi_366", "ChatMessage-attachmentImage": "_ChatMessage-attachmentImage_5z5yi_380", "ChatMessage-attachmentFile": "_ChatMessage-attachmentFile_5z5yi_397", "Chat-loader": "_Chat-loader_5z5yi_420", "Chat-loaderIcon": "_Chat-loaderIcon_5z5yi_430", "Chat-error": "_Chat-error_5z5yi_434", "Chat-errorLabel": "_Chat-errorLabel_5z5yi_443", "Chat-errorAction": "_Chat-errorAction_5z5yi_447", "Chat-userError": "_Chat-userError_5z5yi_451", "Chat-userErrorDismiss": "_Chat-userErrorDismiss_5z5yi_461" };
|
|
1770
1765
|
|
|
1771
1766
|
// src/components/PromptForm/index.tsx
|
|
1772
1767
|
init_react_import();
|
|
1773
|
-
var
|
|
1768
|
+
var import_react18 = require("react");
|
|
1774
1769
|
|
|
1775
1770
|
// css-module:/home/runner/work/platform/platform/packages/plugin-ai/src/components/PromptForm/styles.module.css#css-module
|
|
1776
1771
|
init_react_import();
|
|
@@ -1814,6 +1809,42 @@ var matchesAccept = (file, accept) => {
|
|
|
1814
1809
|
return file.type === entry;
|
|
1815
1810
|
});
|
|
1816
1811
|
};
|
|
1812
|
+
var documentExtensionByMediaType = {
|
|
1813
|
+
"application/msword": "doc",
|
|
1814
|
+
"application/vnd.openxmlformats-officedocument.wordprocessingml.document": "docx",
|
|
1815
|
+
"text/markdown": "md",
|
|
1816
|
+
"application/pdf": "pdf",
|
|
1817
|
+
"text/plain": "txt"
|
|
1818
|
+
};
|
|
1819
|
+
var mediaTypeToExtension = (mediaType) => {
|
|
1820
|
+
const mapped = documentExtensionByMediaType[mediaType];
|
|
1821
|
+
if (mapped) {
|
|
1822
|
+
return mapped;
|
|
1823
|
+
}
|
|
1824
|
+
const subtype = mediaType.split("/")[1] ?? "";
|
|
1825
|
+
return subtype.split("+")[0] || "bin";
|
|
1826
|
+
};
|
|
1827
|
+
var getFilesFromClipboard = (data) => {
|
|
1828
|
+
const files = [];
|
|
1829
|
+
for (const item of data.items ? Array.from(data.items) : []) {
|
|
1830
|
+
if (item.kind === "file") {
|
|
1831
|
+
const file = item.getAsFile();
|
|
1832
|
+
if (file) {
|
|
1833
|
+
files.push(file);
|
|
1834
|
+
}
|
|
1835
|
+
}
|
|
1836
|
+
}
|
|
1837
|
+
if (files.length === 0 && data.files) {
|
|
1838
|
+
files.push(...Array.from(data.files));
|
|
1839
|
+
}
|
|
1840
|
+
return files.map(
|
|
1841
|
+
(file, index) => file.name ? file : new File(
|
|
1842
|
+
[file],
|
|
1843
|
+
`pasted-${Date.now()}-${index}.${mediaTypeToExtension(file.type)}`,
|
|
1844
|
+
{ type: file.type }
|
|
1845
|
+
)
|
|
1846
|
+
);
|
|
1847
|
+
};
|
|
1817
1848
|
var getAttachmentIdFromRef = (url) => url.startsWith("attachment://") ? url.slice("attachment://".length) : null;
|
|
1818
1849
|
var resolveAttachmentUrl = (url, attachmentEndpoint) => {
|
|
1819
1850
|
if (!attachmentEndpoint) {
|
|
@@ -1825,6 +1856,20 @@ var resolveAttachmentUrl = (url, attachmentEndpoint) => {
|
|
|
1825
1856
|
}
|
|
1826
1857
|
return `${attachmentEndpoint.replace(/\/$/, "")}/${attachmentId}`;
|
|
1827
1858
|
};
|
|
1859
|
+
var fetchAttachmentUrl = async (endpoint, signal) => {
|
|
1860
|
+
const response = await fetch(endpoint, { redirect: "manual", signal });
|
|
1861
|
+
if (response.type === "opaqueredirect" || response.status >= 300 && response.status < 400) {
|
|
1862
|
+
return endpoint;
|
|
1863
|
+
}
|
|
1864
|
+
if (!response.ok) {
|
|
1865
|
+
throw new Error(`Attachment URL request failed with ${response.status}`);
|
|
1866
|
+
}
|
|
1867
|
+
const { url } = await response.json();
|
|
1868
|
+
if (typeof url !== "string" || !url) {
|
|
1869
|
+
throw new Error("Attachment URL response did not include a url");
|
|
1870
|
+
}
|
|
1871
|
+
return url;
|
|
1872
|
+
};
|
|
1828
1873
|
var isInternalMessage = (text) => text.startsWith(INTERNAL_MESSAGE_PREFIX);
|
|
1829
1874
|
var truncateFilename = (name, max = 25) => {
|
|
1830
1875
|
if (name.length <= max) return name;
|
|
@@ -1836,7 +1881,7 @@ var truncateFilename = (name, max = 25) => {
|
|
|
1836
1881
|
};
|
|
1837
1882
|
|
|
1838
1883
|
// src/components/PromptForm/index.tsx
|
|
1839
|
-
var
|
|
1884
|
+
var import_jsx_runtime27 = require("react/jsx-runtime");
|
|
1840
1885
|
var cx7 = getClassNameFactory2("PromptForm", styles_module_default8);
|
|
1841
1886
|
function PromptForm({
|
|
1842
1887
|
actions,
|
|
@@ -1856,13 +1901,13 @@ function PromptForm({
|
|
|
1856
1901
|
maxRows = 5,
|
|
1857
1902
|
value = ""
|
|
1858
1903
|
}) {
|
|
1859
|
-
const hasSetInitialPrompt = (0,
|
|
1860
|
-
const [prompt, setPrompt] = (0,
|
|
1861
|
-
const internalRef = (0,
|
|
1862
|
-
const [isDragOver, setIsDragOver] = (0,
|
|
1863
|
-
const dragCounterRef = (0,
|
|
1904
|
+
const hasSetInitialPrompt = (0, import_react18.useRef)(false);
|
|
1905
|
+
const [prompt, setPrompt] = (0, import_react18.useState)(value);
|
|
1906
|
+
const internalRef = (0, import_react18.useRef)(null);
|
|
1907
|
+
const [isDragOver, setIsDragOver] = (0, import_react18.useState)(false);
|
|
1908
|
+
const dragCounterRef = (0, import_react18.useRef)(0);
|
|
1864
1909
|
const canDrop = !!onFileDrop && !isDisabled && !isLoading;
|
|
1865
|
-
const handleDragEnter = (0,
|
|
1910
|
+
const handleDragEnter = (0, import_react18.useCallback)(
|
|
1866
1911
|
(e) => {
|
|
1867
1912
|
e.preventDefault();
|
|
1868
1913
|
dragCounterRef.current++;
|
|
@@ -1872,17 +1917,17 @@ function PromptForm({
|
|
|
1872
1917
|
},
|
|
1873
1918
|
[canDrop]
|
|
1874
1919
|
);
|
|
1875
|
-
const handleDragLeave = (0,
|
|
1920
|
+
const handleDragLeave = (0, import_react18.useCallback)((e) => {
|
|
1876
1921
|
e.preventDefault();
|
|
1877
1922
|
dragCounterRef.current--;
|
|
1878
1923
|
if (dragCounterRef.current === 0) {
|
|
1879
1924
|
setIsDragOver(false);
|
|
1880
1925
|
}
|
|
1881
1926
|
}, []);
|
|
1882
|
-
const handleDragOver = (0,
|
|
1927
|
+
const handleDragOver = (0, import_react18.useCallback)((e) => {
|
|
1883
1928
|
e.preventDefault();
|
|
1884
1929
|
}, []);
|
|
1885
|
-
const handleDrop = (0,
|
|
1930
|
+
const handleDrop = (0, import_react18.useCallback)(
|
|
1886
1931
|
(e) => {
|
|
1887
1932
|
e.preventDefault();
|
|
1888
1933
|
dragCounterRef.current = 0;
|
|
@@ -1896,7 +1941,17 @@ function PromptForm({
|
|
|
1896
1941
|
},
|
|
1897
1942
|
[canDrop, onFileDrop]
|
|
1898
1943
|
);
|
|
1899
|
-
(0,
|
|
1944
|
+
const handlePaste = (0, import_react18.useCallback)(
|
|
1945
|
+
(e) => {
|
|
1946
|
+
if (!canDrop) return;
|
|
1947
|
+
const files = getFilesFromClipboard(e.clipboardData);
|
|
1948
|
+
if (files.length === 0) return;
|
|
1949
|
+
e.preventDefault();
|
|
1950
|
+
onFileDrop(files);
|
|
1951
|
+
},
|
|
1952
|
+
[canDrop, onFileDrop]
|
|
1953
|
+
);
|
|
1954
|
+
(0, import_react18.useEffect)(() => {
|
|
1900
1955
|
setPrompt(value);
|
|
1901
1956
|
}, [setPrompt, value]);
|
|
1902
1957
|
const sendPrompt = async () => {
|
|
@@ -1911,7 +1966,7 @@ function PromptForm({
|
|
|
1911
1966
|
setPrompt("");
|
|
1912
1967
|
}
|
|
1913
1968
|
};
|
|
1914
|
-
(0,
|
|
1969
|
+
(0, import_react18.useEffect)(() => {
|
|
1915
1970
|
const currentUrl = new URL(location.href);
|
|
1916
1971
|
const initialPrompt = currentUrl.searchParams.get("initialPrompt");
|
|
1917
1972
|
if (!hasSetInitialPrompt.current && initialPrompt && prompt === "") {
|
|
@@ -1919,7 +1974,7 @@ function PromptForm({
|
|
|
1919
1974
|
setPrompt(initialPrompt);
|
|
1920
1975
|
}
|
|
1921
1976
|
}, [setPrompt]);
|
|
1922
|
-
return /* @__PURE__ */ (0,
|
|
1977
|
+
return /* @__PURE__ */ (0, import_jsx_runtime27.jsxs)(
|
|
1923
1978
|
"div",
|
|
1924
1979
|
{
|
|
1925
1980
|
className: cx7({
|
|
@@ -1934,22 +1989,22 @@ function PromptForm({
|
|
|
1934
1989
|
onDragOver: onFileDrop ? handleDragOver : void 0,
|
|
1935
1990
|
onDrop: onFileDrop ? handleDrop : void 0,
|
|
1936
1991
|
children: [
|
|
1937
|
-
isDragOver ? /* @__PURE__ */ (0,
|
|
1938
|
-
/* @__PURE__ */ (0,
|
|
1939
|
-
/* @__PURE__ */ (0,
|
|
1992
|
+
isDragOver ? /* @__PURE__ */ (0, import_jsx_runtime27.jsxs)("div", { className: cx7("dropOverlay"), children: [
|
|
1993
|
+
/* @__PURE__ */ (0, import_jsx_runtime27.jsx)(Paperclip, { size: 20 }),
|
|
1994
|
+
/* @__PURE__ */ (0, import_jsx_runtime27.jsx)("span", { children: "Attach file" })
|
|
1940
1995
|
] }) : null,
|
|
1941
|
-
helperText ? /* @__PURE__ */ (0,
|
|
1942
|
-
/* @__PURE__ */ (0,
|
|
1943
|
-
/* @__PURE__ */ (0,
|
|
1944
|
-
/* @__PURE__ */ (0,
|
|
1996
|
+
helperText ? /* @__PURE__ */ (0, import_jsx_runtime27.jsx)("div", { className: cx7("helper"), children: helperText }) : null,
|
|
1997
|
+
/* @__PURE__ */ (0, import_jsx_runtime27.jsxs)("div", { className: cx7("inner"), children: [
|
|
1998
|
+
/* @__PURE__ */ (0, import_jsx_runtime27.jsx)("span", { className: cx7("glow") }),
|
|
1999
|
+
/* @__PURE__ */ (0, import_jsx_runtime27.jsx)(
|
|
1945
2000
|
"form",
|
|
1946
2001
|
{
|
|
1947
2002
|
onSubmit: (e) => {
|
|
1948
2003
|
e.preventDefault();
|
|
1949
2004
|
void sendPrompt();
|
|
1950
2005
|
},
|
|
1951
|
-
children: /* @__PURE__ */ (0,
|
|
1952
|
-
attachments && attachments.length > 0 ? /* @__PURE__ */ (0,
|
|
2006
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime27.jsxs)("div", { className: cx7("formInner"), children: [
|
|
2007
|
+
attachments && attachments.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime27.jsx)("div", { className: cx7("attachments"), children: attachments.map((attachment) => /* @__PURE__ */ (0, import_jsx_runtime27.jsxs)(
|
|
1953
2008
|
"div",
|
|
1954
2009
|
{
|
|
1955
2010
|
className: [
|
|
@@ -1958,29 +2013,29 @@ function PromptForm({
|
|
|
1958
2013
|
attachment.status === "failed" ? cx7("attachmentChipFailed") : ""
|
|
1959
2014
|
].filter(Boolean).join(" "),
|
|
1960
2015
|
children: [
|
|
1961
|
-
attachment.status === "uploading" ? /* @__PURE__ */ (0,
|
|
2016
|
+
attachment.status === "uploading" ? /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(
|
|
1962
2017
|
LoaderCircle,
|
|
1963
2018
|
{
|
|
1964
2019
|
className: cx7("attachmentSpinner"),
|
|
1965
2020
|
size: 14
|
|
1966
2021
|
}
|
|
1967
2022
|
) : null,
|
|
1968
|
-
/* @__PURE__ */ (0,
|
|
1969
|
-
attachment.status === "failed" ? /* @__PURE__ */ (0,
|
|
1970
|
-
onRemoveAttachment ? /* @__PURE__ */ (0,
|
|
2023
|
+
/* @__PURE__ */ (0, import_jsx_runtime27.jsx)("span", { title: attachment.filename, children: truncateFilename(attachment.filename) }),
|
|
2024
|
+
attachment.status === "failed" ? /* @__PURE__ */ (0, import_jsx_runtime27.jsx)("span", { className: cx7("attachmentError"), children: "Failed" }) : null,
|
|
2025
|
+
onRemoveAttachment ? /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(
|
|
1971
2026
|
"button",
|
|
1972
2027
|
{
|
|
1973
2028
|
className: cx7("attachmentRemove"),
|
|
1974
2029
|
onClick: () => onRemoveAttachment(attachment.clientId),
|
|
1975
2030
|
type: "button",
|
|
1976
|
-
children: /* @__PURE__ */ (0,
|
|
2031
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(X, { size: 12 })
|
|
1977
2032
|
}
|
|
1978
2033
|
) : null
|
|
1979
2034
|
]
|
|
1980
2035
|
},
|
|
1981
2036
|
attachment.clientId
|
|
1982
2037
|
)) }) : null,
|
|
1983
|
-
/* @__PURE__ */ (0,
|
|
2038
|
+
/* @__PURE__ */ (0, import_jsx_runtime27.jsx)(
|
|
1984
2039
|
import_react_textarea_autosize.default,
|
|
1985
2040
|
{
|
|
1986
2041
|
className: cx7("input"),
|
|
@@ -1997,6 +2052,7 @@ function PromptForm({
|
|
|
1997
2052
|
internalRef.current = node;
|
|
1998
2053
|
},
|
|
1999
2054
|
onChange: (e) => setPrompt(e.target.value),
|
|
2055
|
+
onPaste: onFileDrop ? handlePaste : void 0,
|
|
2000
2056
|
onKeyDown: (e) => {
|
|
2001
2057
|
if (!e.shiftKey && e.key === "Enter") {
|
|
2002
2058
|
e.preventDefault();
|
|
@@ -2010,7 +2066,7 @@ function PromptForm({
|
|
|
2010
2066
|
}
|
|
2011
2067
|
}
|
|
2012
2068
|
),
|
|
2013
|
-
/* @__PURE__ */ (0,
|
|
2069
|
+
/* @__PURE__ */ (0, import_jsx_runtime27.jsxs)(
|
|
2014
2070
|
"div",
|
|
2015
2071
|
{
|
|
2016
2072
|
className: cx7("actions"),
|
|
@@ -2018,7 +2074,7 @@ function PromptForm({
|
|
|
2018
2074
|
internalRef?.current?.focus();
|
|
2019
2075
|
},
|
|
2020
2076
|
children: [
|
|
2021
|
-
/* @__PURE__ */ (0,
|
|
2077
|
+
/* @__PURE__ */ (0, import_jsx_runtime27.jsx)(
|
|
2022
2078
|
"div",
|
|
2023
2079
|
{
|
|
2024
2080
|
className: cx7("actionsLeft"),
|
|
@@ -2026,18 +2082,18 @@ function PromptForm({
|
|
|
2026
2082
|
children: actions
|
|
2027
2083
|
}
|
|
2028
2084
|
),
|
|
2029
|
-
/* @__PURE__ */ (0,
|
|
2085
|
+
/* @__PURE__ */ (0, import_jsx_runtime27.jsx)(
|
|
2030
2086
|
"div",
|
|
2031
2087
|
{
|
|
2032
2088
|
className: cx7("actionsRight"),
|
|
2033
2089
|
onClick: (e) => e.stopPropagation(),
|
|
2034
|
-
children: /* @__PURE__ */ (0,
|
|
2090
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(
|
|
2035
2091
|
"button",
|
|
2036
2092
|
{
|
|
2037
2093
|
className: cx7("actionSubmit"),
|
|
2038
2094
|
type: "submit",
|
|
2039
2095
|
disabled: isLoading,
|
|
2040
|
-
children: isLoading ? /* @__PURE__ */ (0,
|
|
2096
|
+
children: isLoading ? /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(Loader, { size: 18 }) : cta ?? /* @__PURE__ */ (0, import_jsx_runtime27.jsx)(ArrowUp, { size: 24 })
|
|
2041
2097
|
}
|
|
2042
2098
|
)
|
|
2043
2099
|
}
|
|
@@ -2056,16 +2112,45 @@ function PromptForm({
|
|
|
2056
2112
|
|
|
2057
2113
|
// src/lib/context.ts
|
|
2058
2114
|
init_react_import();
|
|
2059
|
-
var
|
|
2060
|
-
var toolStatusContext = (0,
|
|
2115
|
+
var import_react19 = require("react");
|
|
2116
|
+
var toolStatusContext = (0, import_react19.createContext)({});
|
|
2061
2117
|
var ToolStatusProvider = toolStatusContext.Provider;
|
|
2062
|
-
var hostContext = (0,
|
|
2118
|
+
var hostContext = (0, import_react19.createContext)(void 0);
|
|
2063
2119
|
var HostProvider = hostContext.Provider;
|
|
2064
|
-
var subagentStateContext = (0,
|
|
2120
|
+
var subagentStateContext = (0, import_react19.createContext)({});
|
|
2065
2121
|
var SubagentStateProvider = subagentStateContext.Provider;
|
|
2066
2122
|
|
|
2123
|
+
// src/lib/use-attachment-url.ts
|
|
2124
|
+
init_react_import();
|
|
2125
|
+
var import_react20 = require("react");
|
|
2126
|
+
function useAttachmentUrl(url, endpoint) {
|
|
2127
|
+
const isRef = getAttachmentIdFromRef(url) !== null;
|
|
2128
|
+
const [fetched, setFetched] = (0, import_react20.useState)();
|
|
2129
|
+
(0, import_react20.useEffect)(() => {
|
|
2130
|
+
if (!isRef) return;
|
|
2131
|
+
const controller = new AbortController();
|
|
2132
|
+
const loadUrl = async () => {
|
|
2133
|
+
try {
|
|
2134
|
+
const resolved = await fetchAttachmentUrl(
|
|
2135
|
+
resolveAttachmentUrl(url, endpoint),
|
|
2136
|
+
controller.signal
|
|
2137
|
+
);
|
|
2138
|
+
setFetched({ ref: url, url: resolved });
|
|
2139
|
+
} catch (error) {
|
|
2140
|
+
if (!controller.signal.aborted) {
|
|
2141
|
+
console.error("Failed to load attachment:", error);
|
|
2142
|
+
}
|
|
2143
|
+
}
|
|
2144
|
+
};
|
|
2145
|
+
loadUrl();
|
|
2146
|
+
return () => controller.abort();
|
|
2147
|
+
}, [isRef, url, endpoint]);
|
|
2148
|
+
if (!isRef) return url;
|
|
2149
|
+
return fetched?.ref === url ? fetched.url : void 0;
|
|
2150
|
+
}
|
|
2151
|
+
|
|
2067
2152
|
// src/components/ChatBody/index.tsx
|
|
2068
|
-
var
|
|
2153
|
+
var import_jsx_runtime28 = require("react/jsx-runtime");
|
|
2069
2154
|
var cx8 = getClassNameFactory2("Chat", styles_module_default7);
|
|
2070
2155
|
var cxMessage = getClassNameFactory2("ChatMessage", styles_module_default7);
|
|
2071
2156
|
function ChatBody({
|
|
@@ -2090,7 +2175,7 @@ function ChatBody({
|
|
|
2090
2175
|
const lastMessage = hasMessages ? messages[messages.length - 1] : null;
|
|
2091
2176
|
const lastPart = lastMessage ? lastMessage.parts[lastMessage.parts.length - 1] : null;
|
|
2092
2177
|
const isLoading = status === "submitted" || status === "streaming" && !lastPart;
|
|
2093
|
-
return /* @__PURE__ */ (0,
|
|
2178
|
+
return /* @__PURE__ */ (0, import_jsx_runtime28.jsxs)(
|
|
2094
2179
|
"div",
|
|
2095
2180
|
{
|
|
2096
2181
|
className: cx8({
|
|
@@ -2100,22 +2185,22 @@ function ChatBody({
|
|
|
2100
2185
|
isLoading
|
|
2101
2186
|
}),
|
|
2102
2187
|
children: [
|
|
2103
|
-
children ? /* @__PURE__ */ (0,
|
|
2104
|
-
/* @__PURE__ */ (0,
|
|
2105
|
-
/* @__PURE__ */ (0,
|
|
2106
|
-
/* @__PURE__ */ (0,
|
|
2107
|
-
isLoading && /* @__PURE__ */ (0,
|
|
2108
|
-
/* @__PURE__ */ (0,
|
|
2109
|
-
/* @__PURE__ */ (0,
|
|
2188
|
+
children ? /* @__PURE__ */ (0, import_jsx_runtime28.jsx)("div", { className: cx8("default"), children }) : null,
|
|
2189
|
+
/* @__PURE__ */ (0, import_jsx_runtime28.jsxs)("div", { className: cx8("inner"), children: [
|
|
2190
|
+
/* @__PURE__ */ (0, import_jsx_runtime28.jsxs)("div", { className: cx8("body"), ref: scrollRef, children: [
|
|
2191
|
+
/* @__PURE__ */ (0, import_jsx_runtime28.jsx)("div", { className: cx8("messages"), ref: contentRef, children: messages.toReversed().filter((message) => !shouldHideMessage(message)).map((message) => /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(ChatMessage, { message }, message.id)) }),
|
|
2192
|
+
isLoading && /* @__PURE__ */ (0, import_jsx_runtime28.jsxs)("div", { className: cx8("loader"), children: [
|
|
2193
|
+
/* @__PURE__ */ (0, import_jsx_runtime28.jsx)("div", { className: cx8("loaderIcon"), children: /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(Loader, { size: 16 }) }),
|
|
2194
|
+
/* @__PURE__ */ (0, import_jsx_runtime28.jsx)("div", { children: "Thinking..." })
|
|
2110
2195
|
] })
|
|
2111
2196
|
] }),
|
|
2112
|
-
error && /* @__PURE__ */ (0,
|
|
2113
|
-
/* @__PURE__ */ (0,
|
|
2114
|
-
handleRetry && /* @__PURE__ */ (0,
|
|
2197
|
+
error && /* @__PURE__ */ (0, import_jsx_runtime28.jsxs)("div", { className: cx8("error"), children: [
|
|
2198
|
+
/* @__PURE__ */ (0, import_jsx_runtime28.jsx)("div", { className: cx8("errorLabel"), children: "Something went wrong." }),
|
|
2199
|
+
handleRetry && /* @__PURE__ */ (0, import_jsx_runtime28.jsx)("div", { className: cx8("errorAction"), children: /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(IconButton, { title: "Retry", onClick: handleRetry, children: /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(RotateCcw, { size: "14" }) }) })
|
|
2115
2200
|
] }),
|
|
2116
|
-
userError && /* @__PURE__ */ (0,
|
|
2117
|
-
/* @__PURE__ */ (0,
|
|
2118
|
-
onDismissUserError && /* @__PURE__ */ (0,
|
|
2201
|
+
userError && /* @__PURE__ */ (0, import_jsx_runtime28.jsxs)("div", { className: cx8("userError"), children: [
|
|
2202
|
+
/* @__PURE__ */ (0, import_jsx_runtime28.jsx)("span", { children: userError }),
|
|
2203
|
+
onDismissUserError && /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(
|
|
2119
2204
|
"button",
|
|
2120
2205
|
{
|
|
2121
2206
|
"aria-label": "Dismiss",
|
|
@@ -2123,12 +2208,12 @@ function ChatBody({
|
|
|
2123
2208
|
className: cx8("userErrorDismiss"),
|
|
2124
2209
|
onClick: onDismissUserError,
|
|
2125
2210
|
type: "button",
|
|
2126
|
-
children: /* @__PURE__ */ (0,
|
|
2211
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(X, { size: 14 })
|
|
2127
2212
|
}
|
|
2128
2213
|
)
|
|
2129
2214
|
] }),
|
|
2130
|
-
/* @__PURE__ */ (0,
|
|
2131
|
-
/* @__PURE__ */ (0,
|
|
2215
|
+
/* @__PURE__ */ (0, import_jsx_runtime28.jsxs)("div", { className: cx8("form"), children: [
|
|
2216
|
+
/* @__PURE__ */ (0, import_jsx_runtime28.jsx)(
|
|
2132
2217
|
PromptForm,
|
|
2133
2218
|
{
|
|
2134
2219
|
actions,
|
|
@@ -2142,7 +2227,7 @@ function ChatBody({
|
|
|
2142
2227
|
placeholder: "What do you want to build?"
|
|
2143
2228
|
}
|
|
2144
2229
|
),
|
|
2145
|
-
examplePrompts ? /* @__PURE__ */ (0,
|
|
2230
|
+
examplePrompts ? /* @__PURE__ */ (0, import_jsx_runtime28.jsx)("div", { className: cx8("examplePrompts"), children: examplePrompts }) : null
|
|
2146
2231
|
] })
|
|
2147
2232
|
] })
|
|
2148
2233
|
]
|
|
@@ -2171,13 +2256,13 @@ function ChatMessage({ message }) {
|
|
|
2171
2256
|
if (role === "user") {
|
|
2172
2257
|
const attachmentParts = parts.filter((part) => part.type === "file");
|
|
2173
2258
|
const otherParts = parts.filter((part) => part.type !== "file");
|
|
2174
|
-
return /* @__PURE__ */ (0,
|
|
2259
|
+
return /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(
|
|
2175
2260
|
"div",
|
|
2176
2261
|
{
|
|
2177
2262
|
className: cxMessage({ userRole: true }),
|
|
2178
2263
|
"data-message-id": message.id,
|
|
2179
|
-
children: /* @__PURE__ */ (0,
|
|
2180
|
-
otherParts.map((part, i) => /* @__PURE__ */ (0,
|
|
2264
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime28.jsxs)("div", { className: cxMessage("userBubble"), children: [
|
|
2265
|
+
otherParts.map((part, i) => /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(
|
|
2181
2266
|
ChatMessagePart,
|
|
2182
2267
|
{
|
|
2183
2268
|
part,
|
|
@@ -2185,7 +2270,7 @@ function ChatMessage({ message }) {
|
|
|
2185
2270
|
},
|
|
2186
2271
|
`${message.id}-${part.type}-${i}`
|
|
2187
2272
|
)),
|
|
2188
|
-
attachmentParts.length > 0 ? /* @__PURE__ */ (0,
|
|
2273
|
+
attachmentParts.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime28.jsx)("div", { className: cxMessage("userAttachments"), children: attachmentParts.map((part, i) => /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(
|
|
2189
2274
|
ChatAttachmentThumbnail,
|
|
2190
2275
|
{
|
|
2191
2276
|
filename: part.filename,
|
|
@@ -2198,12 +2283,12 @@ function ChatMessage({ message }) {
|
|
|
2198
2283
|
}
|
|
2199
2284
|
);
|
|
2200
2285
|
}
|
|
2201
|
-
return /* @__PURE__ */ (0,
|
|
2286
|
+
return /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(
|
|
2202
2287
|
"div",
|
|
2203
2288
|
{
|
|
2204
2289
|
className: cxMessage({ [`${role}Role`]: true }),
|
|
2205
2290
|
"data-message-id": message.id,
|
|
2206
|
-
children: parts.map((part, i) => /* @__PURE__ */ (0,
|
|
2291
|
+
children: parts.map((part, i) => /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(
|
|
2207
2292
|
ChatMessagePart,
|
|
2208
2293
|
{
|
|
2209
2294
|
part,
|
|
@@ -2221,11 +2306,11 @@ function ChatAttachmentThumbnail({
|
|
|
2221
2306
|
}) {
|
|
2222
2307
|
const host = (0, import_react21.useContext)(hostContext);
|
|
2223
2308
|
const endpoint = host ? `${host.replace(/\/$/, "")}/attachments` : "/api/puck/chat/attachments";
|
|
2224
|
-
const resolvedUrl =
|
|
2309
|
+
const resolvedUrl = useAttachmentUrl(url, endpoint);
|
|
2225
2310
|
const attachmentId = getAttachmentIdFromRef(url);
|
|
2226
2311
|
const label = filename || attachmentId || "Attachment";
|
|
2227
2312
|
const isImage = mediaType.startsWith("image/");
|
|
2228
|
-
return /* @__PURE__ */ (0,
|
|
2313
|
+
return /* @__PURE__ */ (0, import_jsx_runtime28.jsxs)(
|
|
2229
2314
|
"a",
|
|
2230
2315
|
{
|
|
2231
2316
|
"aria-label": label,
|
|
@@ -2235,8 +2320,8 @@ function ChatAttachmentThumbnail({
|
|
|
2235
2320
|
target: "_blank",
|
|
2236
2321
|
title: label,
|
|
2237
2322
|
children: [
|
|
2238
|
-
isImage ? /* @__PURE__ */ (0,
|
|
2239
|
-
/* @__PURE__ */ (0,
|
|
2323
|
+
isImage ? resolvedUrl && /* @__PURE__ */ (0, import_jsx_runtime28.jsx)("img", { alt: label, src: resolvedUrl }) : /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(FileText, { size: 20 }),
|
|
2324
|
+
/* @__PURE__ */ (0, import_jsx_runtime28.jsx)("span", { className: cxMessage("thumbnailLabel"), children: label })
|
|
2240
2325
|
]
|
|
2241
2326
|
}
|
|
2242
2327
|
);
|
|
@@ -2251,9 +2336,9 @@ function ChatMessageWrapper({
|
|
|
2251
2336
|
role
|
|
2252
2337
|
}) {
|
|
2253
2338
|
if (role === "assistant" || role === "user") {
|
|
2254
|
-
return /* @__PURE__ */ (0,
|
|
2339
|
+
return /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(import_react_markdown.default, { children });
|
|
2255
2340
|
}
|
|
2256
|
-
return /* @__PURE__ */ (0,
|
|
2341
|
+
return /* @__PURE__ */ (0, import_jsx_runtime28.jsx)("span", { children });
|
|
2257
2342
|
}
|
|
2258
2343
|
function ReasoningBlock({ part }) {
|
|
2259
2344
|
const startTimeRef = (0, import_react21.useRef)(null);
|
|
@@ -2268,7 +2353,7 @@ function ReasoningBlock({ part }) {
|
|
|
2268
2353
|
}, [part.state]);
|
|
2269
2354
|
const loading = part.state ? part.state !== "done" : false;
|
|
2270
2355
|
const label = durationSecs !== null ? `Thought for ${durationSecs}s` : !loading ? "Thought for a while" : "Thinking...";
|
|
2271
|
-
return /* @__PURE__ */ (0,
|
|
2356
|
+
return /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(
|
|
2272
2357
|
ChatEvent,
|
|
2273
2358
|
{
|
|
2274
2359
|
status: {
|
|
@@ -2276,7 +2361,7 @@ function ReasoningBlock({ part }) {
|
|
|
2276
2361
|
loading,
|
|
2277
2362
|
summary: part.text
|
|
2278
2363
|
},
|
|
2279
|
-
icon: /* @__PURE__ */ (0,
|
|
2364
|
+
icon: /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(Brain, { size: 18 })
|
|
2280
2365
|
}
|
|
2281
2366
|
);
|
|
2282
2367
|
}
|
|
@@ -2285,19 +2370,19 @@ function ChatMessagePart({
|
|
|
2285
2370
|
role
|
|
2286
2371
|
}) {
|
|
2287
2372
|
if (part.type === "text") {
|
|
2288
|
-
return /* @__PURE__ */ (0,
|
|
2373
|
+
return /* @__PURE__ */ (0, import_jsx_runtime28.jsx)("div", { className: cxMessage("text"), children: /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(ChatMessageWrapper, { role, children: part.text }) });
|
|
2289
2374
|
}
|
|
2290
2375
|
if (part.type === "reasoning") {
|
|
2291
|
-
return /* @__PURE__ */ (0,
|
|
2376
|
+
return /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(ReasoningBlock, { part });
|
|
2292
2377
|
}
|
|
2293
2378
|
if (part.type === "tool-subagent") {
|
|
2294
|
-
return /* @__PURE__ */ (0,
|
|
2379
|
+
return /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(SubagentBlock, { toolCallId: part.toolCallId });
|
|
2295
2380
|
}
|
|
2296
2381
|
if (part.type.startsWith("tool-")) {
|
|
2297
|
-
return /* @__PURE__ */ (0,
|
|
2382
|
+
return /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(PuckTool, { ...part });
|
|
2298
2383
|
}
|
|
2299
2384
|
if (part.type === "file") {
|
|
2300
|
-
return /* @__PURE__ */ (0,
|
|
2385
|
+
return /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(
|
|
2301
2386
|
ChatAttachment,
|
|
2302
2387
|
{
|
|
2303
2388
|
filename: part.filename,
|
|
@@ -2315,15 +2400,15 @@ function ChatAttachment({
|
|
|
2315
2400
|
}) {
|
|
2316
2401
|
const host = (0, import_react21.useContext)(hostContext);
|
|
2317
2402
|
const endpoint = host ? `${host.replace(/\/$/, "")}/attachments` : "/api/puck/chat/attachments";
|
|
2318
|
-
const resolvedUrl =
|
|
2403
|
+
const resolvedUrl = useAttachmentUrl(url, endpoint);
|
|
2319
2404
|
const attachmentId = getAttachmentIdFromRef(url);
|
|
2320
2405
|
const label = filename || attachmentId || "Attachment";
|
|
2321
2406
|
if (mediaType.startsWith("image/")) {
|
|
2322
|
-
return /* @__PURE__ */ (0,
|
|
2407
|
+
return /* @__PURE__ */ (0, import_jsx_runtime28.jsx)("div", { className: cxMessage("attachmentImage"), children: /* @__PURE__ */ (0, import_jsx_runtime28.jsx)("a", { href: resolvedUrl, target: "_blank", rel: "noreferrer", children: resolvedUrl && /* @__PURE__ */ (0, import_jsx_runtime28.jsx)("img", { alt: label, src: resolvedUrl }) }) });
|
|
2323
2408
|
}
|
|
2324
|
-
return /* @__PURE__ */ (0,
|
|
2325
|
-
/* @__PURE__ */ (0,
|
|
2326
|
-
/* @__PURE__ */ (0,
|
|
2409
|
+
return /* @__PURE__ */ (0, import_jsx_runtime28.jsx)("div", { className: cxMessage("attachmentFile"), children: /* @__PURE__ */ (0, import_jsx_runtime28.jsxs)("a", { href: resolvedUrl, target: "_blank", rel: "noreferrer", children: [
|
|
2410
|
+
/* @__PURE__ */ (0, import_jsx_runtime28.jsx)(FileText, { size: 16 }),
|
|
2411
|
+
/* @__PURE__ */ (0, import_jsx_runtime28.jsx)("span", { children: label })
|
|
2327
2412
|
] }) });
|
|
2328
2413
|
}
|
|
2329
2414
|
function PuckTool({
|
|
@@ -2337,19 +2422,19 @@ function PuckTool({
|
|
|
2337
2422
|
const status = outputObj && "status" in outputObj ? outputObj.status : toolStatus ?? { loading: true, label: defaultLabel };
|
|
2338
2423
|
let icon = (0, import_react21.useMemo)(() => {
|
|
2339
2424
|
if (type === "tool-write") {
|
|
2340
|
-
return /* @__PURE__ */ (0,
|
|
2425
|
+
return /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(Pen, { size: 18 });
|
|
2341
2426
|
} else if (type === "tool-refreshPageData") {
|
|
2342
|
-
return /* @__PURE__ */ (0,
|
|
2427
|
+
return /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(GitPullRequest, { size: 18 });
|
|
2343
2428
|
} else if (type === "tool-takeScreenshot") {
|
|
2344
|
-
return /* @__PURE__ */ (0,
|
|
2429
|
+
return /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(Camera, { size: 18 });
|
|
2345
2430
|
} else if (type === "tool-fetchUrl") {
|
|
2346
|
-
return /* @__PURE__ */ (0,
|
|
2431
|
+
return /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(CloudDownload, { size: 18 });
|
|
2347
2432
|
} else if (type === "tool-screenshotUrl") {
|
|
2348
|
-
return /* @__PURE__ */ (0,
|
|
2433
|
+
return /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(Camera, { size: 18 });
|
|
2349
2434
|
}
|
|
2350
|
-
return /* @__PURE__ */ (0,
|
|
2435
|
+
return /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(Check, { size: 18 });
|
|
2351
2436
|
}, [type]);
|
|
2352
|
-
return /* @__PURE__ */ (0,
|
|
2437
|
+
return /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(ChatEvent, { status, icon });
|
|
2353
2438
|
}
|
|
2354
2439
|
function SubagentBlock({ toolCallId }) {
|
|
2355
2440
|
const subagentState = (0, import_react21.useContext)(subagentStateContext);
|
|
@@ -2362,38 +2447,38 @@ function SubagentBlock({ toolCallId }) {
|
|
|
2362
2447
|
const hasBody = !!state && state.parts.length > 0;
|
|
2363
2448
|
const parts = state?.parts ?? [];
|
|
2364
2449
|
const [isOpen, setIsOpen] = (0, import_react21.useState)(false);
|
|
2365
|
-
return /* @__PURE__ */ (0,
|
|
2450
|
+
return /* @__PURE__ */ (0, import_jsx_runtime28.jsxs)(
|
|
2366
2451
|
"details",
|
|
2367
2452
|
{
|
|
2368
2453
|
className: cxMessage("event"),
|
|
2369
2454
|
onToggle: (e) => setIsOpen(e.currentTarget.open),
|
|
2370
2455
|
children: [
|
|
2371
|
-
/* @__PURE__ */ (0,
|
|
2456
|
+
/* @__PURE__ */ (0, import_jsx_runtime28.jsxs)(
|
|
2372
2457
|
"summary",
|
|
2373
2458
|
{
|
|
2374
2459
|
className: cxMessage("eventHeader"),
|
|
2375
2460
|
style: hasBody ? {} : { color: "var(--puck-color-grey-05) !important", cursor: "unset" },
|
|
2376
2461
|
children: [
|
|
2377
|
-
/* @__PURE__ */ (0,
|
|
2378
|
-
/* @__PURE__ */ (0,
|
|
2379
|
-
hasBody && /* @__PURE__ */ (0,
|
|
2380
|
-
/* @__PURE__ */ (0,
|
|
2381
|
-
/* @__PURE__ */ (0,
|
|
2462
|
+
/* @__PURE__ */ (0, import_jsx_runtime28.jsx)("div", { className: cxMessage("eventIcon"), children: loading ? /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(Loader, { size: 16 }) : /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(Bot, { size: 18 }) }),
|
|
2463
|
+
/* @__PURE__ */ (0, import_jsx_runtime28.jsx)("div", { className: cxMessage("eventLabel"), children: label }),
|
|
2464
|
+
hasBody && /* @__PURE__ */ (0, import_jsx_runtime28.jsxs)(import_jsx_runtime28.Fragment, { children: [
|
|
2465
|
+
/* @__PURE__ */ (0, import_jsx_runtime28.jsx)("div", { className: cxMessage("eventExpand"), children: /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(Plus, { size: 12 }) }),
|
|
2466
|
+
/* @__PURE__ */ (0, import_jsx_runtime28.jsx)("div", { className: cxMessage("eventCollapse"), children: /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(Minus, { size: 12 }) })
|
|
2382
2467
|
] })
|
|
2383
2468
|
]
|
|
2384
2469
|
}
|
|
2385
2470
|
),
|
|
2386
|
-
hasBody && isOpen && /* @__PURE__ */ (0,
|
|
2471
|
+
hasBody && isOpen && /* @__PURE__ */ (0, import_jsx_runtime28.jsx)("div", { className: cxMessage("eventBody"), children: parts.map((part, i) => /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(SubagentChildPartRenderer, { part }, `${toolCallId}-${i}`)) })
|
|
2387
2472
|
]
|
|
2388
2473
|
}
|
|
2389
2474
|
);
|
|
2390
2475
|
}
|
|
2391
2476
|
function SubagentChildPartRenderer({ part }) {
|
|
2392
2477
|
if (part.kind === "text") {
|
|
2393
|
-
return /* @__PURE__ */ (0,
|
|
2478
|
+
return /* @__PURE__ */ (0, import_jsx_runtime28.jsx)("div", { className: cxMessage("text"), children: /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(import_react_markdown.default, { children: part.text }) });
|
|
2394
2479
|
}
|
|
2395
2480
|
if (part.kind === "reasoning") {
|
|
2396
|
-
return /* @__PURE__ */ (0,
|
|
2481
|
+
return /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(
|
|
2397
2482
|
ReasoningBlock,
|
|
2398
2483
|
{
|
|
2399
2484
|
part: {
|
|
@@ -2405,7 +2490,7 @@ function SubagentChildPartRenderer({ part }) {
|
|
|
2405
2490
|
);
|
|
2406
2491
|
}
|
|
2407
2492
|
if (part.toolName === "subagent") {
|
|
2408
|
-
return /* @__PURE__ */ (0,
|
|
2493
|
+
return /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(SubagentBlock, { toolCallId: part.childToolCallId });
|
|
2409
2494
|
}
|
|
2410
2495
|
const synthesized = {
|
|
2411
2496
|
toolCallId: part.childToolCallId,
|
|
@@ -2414,35 +2499,35 @@ function SubagentChildPartRenderer({ part }) {
|
|
|
2414
2499
|
input: part.input,
|
|
2415
2500
|
output: part.output
|
|
2416
2501
|
};
|
|
2417
|
-
return /* @__PURE__ */ (0,
|
|
2502
|
+
return /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(PuckTool, { ...synthesized });
|
|
2418
2503
|
}
|
|
2419
2504
|
function ChatEvent({
|
|
2420
2505
|
status,
|
|
2421
|
-
icon = /* @__PURE__ */ (0,
|
|
2506
|
+
icon = /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(Check, { size: 18 })
|
|
2422
2507
|
}) {
|
|
2423
2508
|
const [isOpen, setIsOpen] = (0, import_react21.useState)(false);
|
|
2424
|
-
return /* @__PURE__ */ (0,
|
|
2509
|
+
return /* @__PURE__ */ (0, import_jsx_runtime28.jsxs)(
|
|
2425
2510
|
"details",
|
|
2426
2511
|
{
|
|
2427
2512
|
className: cxMessage("event"),
|
|
2428
2513
|
onToggle: (e) => setIsOpen(e.currentTarget.open),
|
|
2429
2514
|
children: [
|
|
2430
|
-
/* @__PURE__ */ (0,
|
|
2515
|
+
/* @__PURE__ */ (0, import_jsx_runtime28.jsxs)(
|
|
2431
2516
|
"summary",
|
|
2432
2517
|
{
|
|
2433
2518
|
className: cxMessage("eventHeader"),
|
|
2434
2519
|
style: status.summary ? {} : { color: "var(--puck-color-grey-05) !important", cursor: "unset" },
|
|
2435
2520
|
children: [
|
|
2436
|
-
/* @__PURE__ */ (0,
|
|
2437
|
-
/* @__PURE__ */ (0,
|
|
2438
|
-
status.summary && /* @__PURE__ */ (0,
|
|
2439
|
-
/* @__PURE__ */ (0,
|
|
2440
|
-
/* @__PURE__ */ (0,
|
|
2521
|
+
/* @__PURE__ */ (0, import_jsx_runtime28.jsx)("div", { className: cxMessage("eventIcon"), children: status.error ? /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(TriangleAlert, { size: 18 }) : status.loading ? /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(Loader, { size: 16 }) : icon }),
|
|
2522
|
+
/* @__PURE__ */ (0, import_jsx_runtime28.jsx)("div", { children: status.label }),
|
|
2523
|
+
status.summary && /* @__PURE__ */ (0, import_jsx_runtime28.jsxs)(import_jsx_runtime28.Fragment, { children: [
|
|
2524
|
+
/* @__PURE__ */ (0, import_jsx_runtime28.jsx)("div", { className: cxMessage("eventExpand"), children: /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(Plus, { size: 12 }) }),
|
|
2525
|
+
/* @__PURE__ */ (0, import_jsx_runtime28.jsx)("div", { className: cxMessage("eventCollapse"), children: /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(Minus, { size: 12 }) })
|
|
2441
2526
|
] })
|
|
2442
2527
|
]
|
|
2443
2528
|
}
|
|
2444
2529
|
),
|
|
2445
|
-
status.summary && isOpen && /* @__PURE__ */ (0,
|
|
2530
|
+
status.summary && isOpen && /* @__PURE__ */ (0, import_jsx_runtime28.jsx)("div", { className: cxMessage("eventBody"), children: /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(import_react_markdown.default, { children: status.summary }) })
|
|
2446
2531
|
]
|
|
2447
2532
|
}
|
|
2448
2533
|
);
|
|
@@ -2453,12 +2538,12 @@ function ExamplePrompt({
|
|
|
2453
2538
|
onClick,
|
|
2454
2539
|
disabled
|
|
2455
2540
|
}) {
|
|
2456
|
-
const content = /* @__PURE__ */ (0,
|
|
2457
|
-
/* @__PURE__ */ (0,
|
|
2458
|
-
/* @__PURE__ */ (0,
|
|
2541
|
+
const content = /* @__PURE__ */ (0, import_jsx_runtime28.jsxs)(import_jsx_runtime28.Fragment, { children: [
|
|
2542
|
+
/* @__PURE__ */ (0, import_jsx_runtime28.jsx)("div", { children: label }),
|
|
2543
|
+
/* @__PURE__ */ (0, import_jsx_runtime28.jsx)("div", { className: cx8("examplePromptArrow"), children: /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(ArrowUp, { size: "16" }) })
|
|
2459
2544
|
] });
|
|
2460
2545
|
if (href) {
|
|
2461
|
-
return /* @__PURE__ */ (0,
|
|
2546
|
+
return /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(
|
|
2462
2547
|
"a",
|
|
2463
2548
|
{
|
|
2464
2549
|
className: cx8("examplePrompt"),
|
|
@@ -2475,7 +2560,7 @@ function ExamplePrompt({
|
|
|
2475
2560
|
}
|
|
2476
2561
|
);
|
|
2477
2562
|
}
|
|
2478
|
-
return /* @__PURE__ */ (0,
|
|
2563
|
+
return /* @__PURE__ */ (0, import_jsx_runtime28.jsx)(
|
|
2479
2564
|
"button",
|
|
2480
2565
|
{
|
|
2481
2566
|
className: cx8("examplePrompt"),
|
|
@@ -2515,14 +2600,14 @@ init_react_import();
|
|
|
2515
2600
|
var styles_module_default9 = { "DesignModeToggle": "_DesignModeToggle_o5uty_1", "DesignModeToggle-button": "_DesignModeToggle-button_o5uty_8", "DesignModeToggle-button--active": "_DesignModeToggle-button--active_o5uty_28" };
|
|
2516
2601
|
|
|
2517
2602
|
// src/components/DesignModeToggle/index.tsx
|
|
2518
|
-
var
|
|
2603
|
+
var import_jsx_runtime29 = require("react/jsx-runtime");
|
|
2519
2604
|
var cx9 = getClassNameFactory2("DesignModeToggle", styles_module_default9);
|
|
2520
2605
|
function DesignModeToggle({
|
|
2521
2606
|
active,
|
|
2522
2607
|
onToggle,
|
|
2523
2608
|
disabled
|
|
2524
2609
|
}) {
|
|
2525
|
-
return /* @__PURE__ */ (0,
|
|
2610
|
+
return /* @__PURE__ */ (0, import_jsx_runtime29.jsx)("div", { className: cx9(), children: /* @__PURE__ */ (0, import_jsx_runtime29.jsxs)(
|
|
2526
2611
|
"button",
|
|
2527
2612
|
{
|
|
2528
2613
|
className: `${cx9("button")} ${active ? cx9("button--active") : ""}`,
|
|
@@ -2531,7 +2616,7 @@ function DesignModeToggle({
|
|
|
2531
2616
|
type: "button",
|
|
2532
2617
|
title: active ? "Disable design mode" : "Enable design mode",
|
|
2533
2618
|
children: [
|
|
2534
|
-
/* @__PURE__ */ (0,
|
|
2619
|
+
/* @__PURE__ */ (0, import_jsx_runtime29.jsx)(WandSparkles, { size: 12 }),
|
|
2535
2620
|
"Design"
|
|
2536
2621
|
]
|
|
2537
2622
|
}
|
|
@@ -2545,163 +2630,20 @@ var import_core4 = require("@puckeditor/core");
|
|
|
2545
2630
|
// src/lib/design/component.tsx
|
|
2546
2631
|
init_react_import();
|
|
2547
2632
|
var import_core3 = require("@puckeditor/core");
|
|
2548
|
-
var
|
|
2633
|
+
var import_react24 = require("react");
|
|
2549
2634
|
|
|
2550
2635
|
// src/lib/morph-html.ts
|
|
2551
2636
|
init_react_import();
|
|
2552
|
-
var PROTECTED_ATTRS = /* @__PURE__ */ new Set([
|
|
2553
|
-
"contenteditable",
|
|
2554
|
-
"data-puck-overlay-portal"
|
|
2555
|
-
]);
|
|
2556
|
-
var SLOT_OWNED_ATTRS = /* @__PURE__ */ new Set(["style", "class"]);
|
|
2557
|
-
var isEventHandlerAttr = (name) => /^on/i.test(name);
|
|
2558
|
-
var FIELD_ATTR_PREFIX = "data-puck-field-";
|
|
2559
|
-
var hasJsonFieldBinding = (el) => {
|
|
2560
|
-
const attrBoundNames = /* @__PURE__ */ new Set();
|
|
2561
|
-
const jsonFieldNames = [];
|
|
2562
|
-
for (const attr of Array.from(el.attributes)) {
|
|
2563
|
-
if (!attr.name.startsWith(FIELD_ATTR_PREFIX)) continue;
|
|
2564
|
-
if (attr.name.startsWith("data-puck-field-value-")) continue;
|
|
2565
|
-
const target = attr.name.slice(FIELD_ATTR_PREFIX.length);
|
|
2566
|
-
const dotted = target.includes(".");
|
|
2567
|
-
const attrTarget = dotted ? target.split(".").pop() : target;
|
|
2568
|
-
const placementOnly = !attr.value || dotted && !el.hasAttribute(attrTarget);
|
|
2569
|
-
if (attr.value.trimStart().startsWith("{") || placementOnly) {
|
|
2570
|
-
if (target && target !== "name") jsonFieldNames.push(target);
|
|
2571
|
-
} else {
|
|
2572
|
-
const fieldName = attr.value.trim();
|
|
2573
|
-
if (fieldName) attrBoundNames.add(fieldName);
|
|
2574
|
-
}
|
|
2575
|
-
}
|
|
2576
|
-
return jsonFieldNames.some((name) => !attrBoundNames.has(name));
|
|
2577
|
-
};
|
|
2578
|
-
var ownsItsChildren = (el) => el.hasAttribute("data-puck-slot") || el.hasAttribute("data-puck-field-name") || el.hasAttribute("data-puck-array") || hasJsonFieldBinding(el);
|
|
2579
|
-
var syncAttributes = (target, source) => {
|
|
2580
|
-
const isSlot = target.hasAttribute("data-puck-slot");
|
|
2581
|
-
for (const attr of Array.from(target.attributes)) {
|
|
2582
|
-
if (PROTECTED_ATTRS.has(attr.name)) continue;
|
|
2583
|
-
if (isSlot && SLOT_OWNED_ATTRS.has(attr.name)) continue;
|
|
2584
|
-
if (isEventHandlerAttr(attr.name) || !source.hasAttribute(attr.name)) {
|
|
2585
|
-
target.removeAttribute(attr.name);
|
|
2586
|
-
}
|
|
2587
|
-
}
|
|
2588
|
-
for (const attr of Array.from(source.attributes)) {
|
|
2589
|
-
if (PROTECTED_ATTRS.has(attr.name)) continue;
|
|
2590
|
-
if (isSlot && SLOT_OWNED_ATTRS.has(attr.name)) continue;
|
|
2591
|
-
if (isEventHandlerAttr(attr.name)) continue;
|
|
2592
|
-
if (target.getAttribute(attr.name) !== attr.value) {
|
|
2593
|
-
target.setAttribute(attr.name, attr.value);
|
|
2594
|
-
}
|
|
2595
|
-
}
|
|
2596
|
-
};
|
|
2597
|
-
var isSameKind = (a, b) => a.nodeType === b.nodeType && (a.nodeType !== Node.ELEMENT_NODE || a.tagName === b.tagName);
|
|
2598
|
-
var isIncompleteTagArtifact = (node) => node.nodeType === Node.TEXT_NODE && /^<\/?[a-zA-Z]*$/.test(node.nodeValue ?? "");
|
|
2599
|
-
var stripIncompleteTagArtifacts = (root) => {
|
|
2600
|
-
for (const child of Array.from(root.childNodes)) {
|
|
2601
|
-
if (isIncompleteTagArtifact(child)) {
|
|
2602
|
-
root.removeChild(child);
|
|
2603
|
-
} else if (child.nodeType === Node.ELEMENT_NODE) {
|
|
2604
|
-
stripIncompleteTagArtifacts(child);
|
|
2605
|
-
}
|
|
2606
|
-
}
|
|
2607
|
-
};
|
|
2608
|
-
var stripEventHandlerAttrs = (root) => {
|
|
2609
|
-
root.querySelectorAll("*").forEach((el) => {
|
|
2610
|
-
for (const attr of Array.from(el.attributes)) {
|
|
2611
|
-
if (isEventHandlerAttr(attr.name)) el.removeAttribute(attr.name);
|
|
2612
|
-
}
|
|
2613
|
-
});
|
|
2614
|
-
};
|
|
2615
|
-
var morphChildren = (target, source, skipChildrenOf = ownsItsChildren) => {
|
|
2616
|
-
const sourceChildren = Array.from(source.childNodes);
|
|
2617
|
-
for (let i = 0; i < sourceChildren.length; i++) {
|
|
2618
|
-
const sourceChild = sourceChildren[i];
|
|
2619
|
-
const targetChild = target.childNodes[i];
|
|
2620
|
-
if (!targetChild) {
|
|
2621
|
-
target.appendChild(sourceChild);
|
|
2622
|
-
continue;
|
|
2623
|
-
}
|
|
2624
|
-
if (!isSameKind(targetChild, sourceChild)) {
|
|
2625
|
-
target.replaceChild(sourceChild, targetChild);
|
|
2626
|
-
continue;
|
|
2627
|
-
}
|
|
2628
|
-
if (sourceChild.nodeType !== Node.ELEMENT_NODE) {
|
|
2629
|
-
if (targetChild.nodeValue !== sourceChild.nodeValue) {
|
|
2630
|
-
targetChild.nodeValue = sourceChild.nodeValue;
|
|
2631
|
-
}
|
|
2632
|
-
continue;
|
|
2633
|
-
}
|
|
2634
|
-
const targetEl = targetChild;
|
|
2635
|
-
syncAttributes(targetEl, sourceChild);
|
|
2636
|
-
if (!skipChildrenOf(targetEl)) {
|
|
2637
|
-
morphChildren(targetEl, sourceChild, skipChildrenOf);
|
|
2638
|
-
}
|
|
2639
|
-
}
|
|
2640
|
-
while (target.childNodes.length > sourceChildren.length) {
|
|
2641
|
-
target.removeChild(target.lastChild);
|
|
2642
|
-
}
|
|
2643
|
-
};
|
|
2644
|
-
function morphHtml(container, html, attrOverrides = [], skipChildrenOf = ownsItsChildren) {
|
|
2645
|
-
const template = container.ownerDocument.createElement("template");
|
|
2646
|
-
template.innerHTML = html;
|
|
2647
|
-
stripIncompleteTagArtifacts(template.content);
|
|
2648
|
-
stripEventHandlerAttrs(template.content);
|
|
2649
|
-
if (attrOverrides.length > 0) {
|
|
2650
|
-
const overridesByAttr = /* @__PURE__ */ new Map();
|
|
2651
|
-
for (const override of attrOverrides) {
|
|
2652
|
-
if (isEventHandlerAttr(override.attr)) continue;
|
|
2653
|
-
const bindingAttr = `${FIELD_ATTR_PREFIX}${override.attr}`;
|
|
2654
|
-
const fields = overridesByAttr.get(bindingAttr) ?? /* @__PURE__ */ new Map();
|
|
2655
|
-
fields.set(override.name, override);
|
|
2656
|
-
overridesByAttr.set(bindingAttr, fields);
|
|
2657
|
-
}
|
|
2658
|
-
template.content.querySelectorAll("*").forEach((el) => {
|
|
2659
|
-
for (const attr of Array.from(el.attributes)) {
|
|
2660
|
-
const override = overridesByAttr.get(attr.name)?.get(attr.value.trim());
|
|
2661
|
-
if (!override) continue;
|
|
2662
|
-
if (el.closest("[data-puck-array]")) return;
|
|
2663
|
-
el.setAttribute(override.attr, override.value);
|
|
2664
|
-
}
|
|
2665
|
-
});
|
|
2666
|
-
}
|
|
2667
|
-
morphChildren(container, template.content, skipChildrenOf);
|
|
2668
|
-
}
|
|
2669
2637
|
|
|
2670
|
-
// src/lib/design/
|
|
2638
|
+
// src/lib/design/annotations.ts
|
|
2671
2639
|
init_react_import();
|
|
2672
|
-
var wrapScriptWithObserverGuard = (script) => {
|
|
2673
|
-
if (!script.includes("MutationObserver")) return script;
|
|
2674
|
-
return `(function () {
|
|
2675
|
-
var __NativeMutationObserver = window.MutationObserver;
|
|
2676
|
-
function MutationObserver(callback) {
|
|
2677
|
-
var observed = [];
|
|
2678
|
-
var inner = new __NativeMutationObserver(function (records) {
|
|
2679
|
-
inner.disconnect();
|
|
2680
|
-
try {
|
|
2681
|
-
callback(records, inner);
|
|
2682
|
-
} finally {
|
|
2683
|
-
for (var i = 0; i < observed.length; i++) {
|
|
2684
|
-
__nativeObserve.call(inner, observed[i][0], observed[i][1]);
|
|
2685
|
-
}
|
|
2686
|
-
}
|
|
2687
|
-
});
|
|
2688
|
-
var __nativeObserve = inner.observe;
|
|
2689
|
-
inner.observe = function (target, options) {
|
|
2690
|
-
observed.push([target, options]);
|
|
2691
|
-
return __nativeObserve.call(inner, target, options);
|
|
2692
|
-
};
|
|
2693
|
-
return inner;
|
|
2694
|
-
}
|
|
2695
|
-
${script}
|
|
2696
|
-
})();`;
|
|
2697
|
-
};
|
|
2698
2640
|
|
|
2699
2641
|
// src/lib/html-annotations.ts
|
|
2700
2642
|
init_react_import();
|
|
2701
2643
|
var import_htmlparser2 = require("htmlparser2");
|
|
2702
2644
|
var import_domutils = require("domutils");
|
|
2703
2645
|
var import_domhandler = require("domhandler");
|
|
2704
|
-
var
|
|
2646
|
+
var FIELD_ATTR_PREFIX = "data-puck-field-";
|
|
2705
2647
|
var OPTIONS_ATTR_PREFIX = "data-puck-options-";
|
|
2706
2648
|
var BIND_ATTR_PREFIX = "data-puck-bind-";
|
|
2707
2649
|
var BIND_INPUT_ATTR_PREFIX = "data-puck-bind-input-";
|
|
@@ -2711,26 +2653,21 @@ var MAX_ATTR_PREFIX = "data-puck-max-";
|
|
|
2711
2653
|
var STEP_ATTR_PREFIX = "data-puck-step-";
|
|
2712
2654
|
var SLOT_ATTR = "data-puck-slot";
|
|
2713
2655
|
var ARRAY_ATTR = "data-puck-array";
|
|
2714
|
-
var
|
|
2656
|
+
var RECOGNIZED_FIELD_TYPES = /* @__PURE__ */ new Set([
|
|
2715
2657
|
"text",
|
|
2716
2658
|
"textarea",
|
|
2717
2659
|
"number",
|
|
2718
2660
|
"richtext",
|
|
2719
2661
|
"radio",
|
|
2720
2662
|
"select",
|
|
2721
|
-
"slot"
|
|
2722
|
-
"array",
|
|
2723
|
-
"object",
|
|
2724
|
-
"external",
|
|
2725
|
-
"custom"
|
|
2663
|
+
"slot"
|
|
2726
2664
|
]);
|
|
2727
|
-
var
|
|
2728
|
-
|
|
2729
|
-
const trimmed = attrValue.trimStart();
|
|
2665
|
+
var tryParseFieldShape = (value) => {
|
|
2666
|
+
const trimmed = value.trimStart();
|
|
2730
2667
|
if (!trimmed.startsWith("{")) return null;
|
|
2731
2668
|
try {
|
|
2732
2669
|
const parsed = JSON.parse(trimmed);
|
|
2733
|
-
if (isRecord(parsed) && typeof parsed.type === "string" && parsed.type) {
|
|
2670
|
+
if (isRecord(parsed) && typeof parsed.type === "string" && RECOGNIZED_FIELD_TYPES.has(parsed.type)) {
|
|
2734
2671
|
return parsed;
|
|
2735
2672
|
}
|
|
2736
2673
|
} catch {
|
|
@@ -2754,6 +2691,19 @@ var textContentWithBreaks = (node) => {
|
|
|
2754
2691
|
var isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2755
2692
|
var FIELD_NAME_RE = /^[A-Za-z0-9_]+(?:[-.][A-Za-z0-9_]+)*$/;
|
|
2756
2693
|
var isValidFieldName = (name) => FIELD_NAME_RE.test(name);
|
|
2694
|
+
var isFieldNameClaimed = (name, claimed, includeExact = true) => {
|
|
2695
|
+
for (const entry of claimed) {
|
|
2696
|
+
if (includeExact && entry === name || entry.startsWith(`${name}.`) || name.startsWith(`${entry}.`)) {
|
|
2697
|
+
return true;
|
|
2698
|
+
}
|
|
2699
|
+
}
|
|
2700
|
+
return false;
|
|
2701
|
+
};
|
|
2702
|
+
var attrBoundFieldNames = (attribs) => new Set(
|
|
2703
|
+
Object.entries(attribs).filter(
|
|
2704
|
+
([name, value]) => name.startsWith(FIELD_ATTR_PREFIX) && name !== `${FIELD_ATTR_PREFIX}name` && !name.startsWith(`${FIELD_ATTR_PREFIX}value-`) && !tryParseFieldShape(value)
|
|
2705
|
+
).map(([, value]) => value.trim()).filter(isValidFieldName)
|
|
2706
|
+
);
|
|
2757
2707
|
var getDeepValue = (source, path) => {
|
|
2758
2708
|
if (!path.includes(".")) return source[path];
|
|
2759
2709
|
let current = source;
|
|
@@ -2818,8 +2768,7 @@ var getNumberConstraints = (attribs, name) => {
|
|
|
2818
2768
|
if (step !== void 0) constraints.step = step;
|
|
2819
2769
|
return constraints;
|
|
2820
2770
|
};
|
|
2821
|
-
var createAccumulator = (
|
|
2822
|
-
known,
|
|
2771
|
+
var createAccumulator = () => ({
|
|
2823
2772
|
fields: [],
|
|
2824
2773
|
values: {},
|
|
2825
2774
|
seenFields: /* @__PURE__ */ new Set(),
|
|
@@ -2855,6 +2804,7 @@ var collectElementFields = (element, acc) => {
|
|
|
2855
2804
|
return true;
|
|
2856
2805
|
}
|
|
2857
2806
|
let skipChildren = false;
|
|
2807
|
+
const attrBound = attrBoundFieldNames(attribs);
|
|
2858
2808
|
for (const [attrName, attrValue] of Object.entries(attribs)) {
|
|
2859
2809
|
if (attrName.startsWith(OPTIONS_ATTR_PREFIX)) {
|
|
2860
2810
|
const fieldName = attrName.slice(OPTIONS_ATTR_PREFIX.length);
|
|
@@ -2883,11 +2833,9 @@ var collectElementFields = (element, acc) => {
|
|
|
2883
2833
|
}
|
|
2884
2834
|
continue;
|
|
2885
2835
|
}
|
|
2886
|
-
if (!attrName.startsWith(
|
|
2887
|
-
const target = attrName.slice(
|
|
2836
|
+
if (!attrName.startsWith(FIELD_ATTR_PREFIX)) continue;
|
|
2837
|
+
const target = attrName.slice(FIELD_ATTR_PREFIX.length);
|
|
2888
2838
|
if (!target) continue;
|
|
2889
|
-
const dotted = target.includes(".");
|
|
2890
|
-
const attrTarget = dotted ? target.split(".").pop() : target;
|
|
2891
2839
|
const shape = tryParseFieldShape(attrValue);
|
|
2892
2840
|
if (shape) {
|
|
2893
2841
|
if (shape.type === "slot") continue;
|
|
@@ -2900,17 +2848,11 @@ var collectElementFields = (element, acc) => {
|
|
|
2900
2848
|
if (existing) existing.shape = shape;
|
|
2901
2849
|
continue;
|
|
2902
2850
|
}
|
|
2851
|
+
if (isFieldNameClaimed(name2, attrBound, false) || isFieldNameClaimed(name2, acc.seenFields)) {
|
|
2852
|
+
continue;
|
|
2853
|
+
}
|
|
2903
2854
|
acc.seenFields.add(name2);
|
|
2904
|
-
if (
|
|
2905
|
-
const { type, ...value } = shape;
|
|
2906
|
-
acc.fields.push({
|
|
2907
|
-
name: name2,
|
|
2908
|
-
binding: "text",
|
|
2909
|
-
shape: { type },
|
|
2910
|
-
format: "json"
|
|
2911
|
-
});
|
|
2912
|
-
setExtractedValue(acc.values, name2, value);
|
|
2913
|
-
} else if (shape.type === "richtext") {
|
|
2855
|
+
if (shape.type === "richtext") {
|
|
2914
2856
|
acc.fields.push({ name: name2, binding: "text", shape, format: "json" });
|
|
2915
2857
|
setExtractedValue(acc.values, name2, (0, import_domutils.getInnerHTML)(element).trim());
|
|
2916
2858
|
skipChildren = true;
|
|
@@ -2932,26 +2874,6 @@ var collectElementFields = (element, acc) => {
|
|
|
2932
2874
|
}
|
|
2933
2875
|
continue;
|
|
2934
2876
|
}
|
|
2935
|
-
if ((!attrValue || dotted && !(attrTarget in attribs)) && isValidFieldName(target)) {
|
|
2936
|
-
if (acc.seenFields.has(target)) continue;
|
|
2937
|
-
acc.seenFields.add(target);
|
|
2938
|
-
const knownShape = getFieldShapeAt(acc.known, target);
|
|
2939
|
-
acc.fields.push({
|
|
2940
|
-
name: target,
|
|
2941
|
-
binding: "text",
|
|
2942
|
-
format: "json",
|
|
2943
|
-
...knownShape ? { shape: knownShape } : {}
|
|
2944
|
-
});
|
|
2945
|
-
const asHtml = knownShape ? knownShape.type === "richtext" : element.children.some(isElement);
|
|
2946
|
-
if (asHtml) {
|
|
2947
|
-
setExtractedValue(acc.values, target, (0, import_domutils.getInnerHTML)(element).trim());
|
|
2948
|
-
skipChildren = true;
|
|
2949
|
-
} else {
|
|
2950
|
-
const text = collapseWhitespace(textContentWithBreaks(element));
|
|
2951
|
-
if (text) setExtractedValue(acc.values, target, text);
|
|
2952
|
-
}
|
|
2953
|
-
continue;
|
|
2954
|
-
}
|
|
2955
2877
|
const name = attrValue.trim();
|
|
2956
2878
|
if (!name) continue;
|
|
2957
2879
|
if (!isValidFieldName(name)) continue;
|
|
@@ -2965,7 +2887,7 @@ var collectElementFields = (element, acc) => {
|
|
|
2965
2887
|
acc.fields[idx] = {
|
|
2966
2888
|
name,
|
|
2967
2889
|
binding: "attr",
|
|
2968
|
-
attr:
|
|
2890
|
+
attr: target,
|
|
2969
2891
|
shape: prev.shape
|
|
2970
2892
|
};
|
|
2971
2893
|
const segments = name.split(".");
|
|
@@ -2978,11 +2900,14 @@ var collectElementFields = (element, acc) => {
|
|
|
2978
2900
|
break;
|
|
2979
2901
|
}
|
|
2980
2902
|
}
|
|
2981
|
-
current[segments[segments.length - 1]] = attribs[
|
|
2903
|
+
current[segments[segments.length - 1]] = attribs[target] ?? "";
|
|
2982
2904
|
}
|
|
2983
2905
|
}
|
|
2984
2906
|
continue;
|
|
2985
2907
|
}
|
|
2908
|
+
if (target === "name" && isFieldNameClaimed(name, attrBound) || isFieldNameClaimed(name, acc.seenFields)) {
|
|
2909
|
+
continue;
|
|
2910
|
+
}
|
|
2986
2911
|
acc.seenFields.add(name);
|
|
2987
2912
|
const fieldType = getTypeModifier(attribs, name);
|
|
2988
2913
|
const constraints = fieldType === "number" ? getNumberConstraints(attribs, name) : {};
|
|
@@ -3016,11 +2941,11 @@ var collectElementFields = (element, acc) => {
|
|
|
3016
2941
|
acc.fields.push({
|
|
3017
2942
|
name,
|
|
3018
2943
|
binding: "attr",
|
|
3019
|
-
attr:
|
|
2944
|
+
attr: target,
|
|
3020
2945
|
fieldType,
|
|
3021
2946
|
...constraints
|
|
3022
2947
|
});
|
|
3023
|
-
const value = parseNumber(attribs[
|
|
2948
|
+
const value = parseNumber(attribs[target]);
|
|
3024
2949
|
if (value !== void 0) {
|
|
3025
2950
|
setExtractedValue(acc.values, name, value);
|
|
3026
2951
|
}
|
|
@@ -3028,10 +2953,10 @@ var collectElementFields = (element, acc) => {
|
|
|
3028
2953
|
acc.fields.push({
|
|
3029
2954
|
name,
|
|
3030
2955
|
binding: "attr",
|
|
3031
|
-
attr:
|
|
2956
|
+
attr: target,
|
|
3032
2957
|
...fieldType && fieldType !== "richtext" ? { fieldType } : {}
|
|
3033
2958
|
});
|
|
3034
|
-
setExtractedValue(acc.values, name, attribs[
|
|
2959
|
+
setExtractedValue(acc.values, name, attribs[target] ?? "");
|
|
3035
2960
|
}
|
|
3036
2961
|
}
|
|
3037
2962
|
}
|
|
@@ -3056,16 +2981,7 @@ var attachOptions = (acc) => {
|
|
|
3056
2981
|
return options ? { ...field, options } : field;
|
|
3057
2982
|
});
|
|
3058
2983
|
};
|
|
3059
|
-
var
|
|
3060
|
-
const segments = name.split(".");
|
|
3061
|
-
let cursor = shapes;
|
|
3062
|
-
for (let i = 0; i < segments.length - 1; i++) {
|
|
3063
|
-
cursor = cursor?.[segments[i]]?.objectFields;
|
|
3064
|
-
}
|
|
3065
|
-
const shape = cursor?.[segments[segments.length - 1]];
|
|
3066
|
-
return shape && shape.type !== "object" ? shape : void 0;
|
|
3067
|
-
};
|
|
3068
|
-
var parseHtmlAnnotations = (html, known) => {
|
|
2984
|
+
var parseHtmlAnnotations = (html) => {
|
|
3069
2985
|
const annotations = {
|
|
3070
2986
|
fields: [],
|
|
3071
2987
|
slots: [],
|
|
@@ -3074,7 +2990,7 @@ var parseHtmlAnnotations = (html, known) => {
|
|
|
3074
2990
|
bindInputs: {}
|
|
3075
2991
|
};
|
|
3076
2992
|
if (!html) return annotations;
|
|
3077
|
-
const acc = createAccumulator(
|
|
2993
|
+
const acc = createAccumulator();
|
|
3078
2994
|
const seenSlots = /* @__PURE__ */ new Set();
|
|
3079
2995
|
const walk = (nodes) => {
|
|
3080
2996
|
for (const node of nodes) {
|
|
@@ -3085,7 +3001,7 @@ var parseHtmlAnnotations = (html, known) => {
|
|
|
3085
3001
|
if (slotName && isValidFieldName(slotName) && !seenSlots.has(slotName)) {
|
|
3086
3002
|
seenSlots.add(slotName);
|
|
3087
3003
|
const shape = tryParseFieldShape(
|
|
3088
|
-
attribs[
|
|
3004
|
+
attribs[FIELD_ATTR_PREFIX + slotName.toLowerCase()] ?? ""
|
|
3089
3005
|
);
|
|
3090
3006
|
const allow = shape?.type === "slot" ? sanitizeStringArray(shape.allow) : void 0;
|
|
3091
3007
|
const disallow = shape?.type === "slot" ? sanitizeStringArray(shape.disallow) : void 0;
|
|
@@ -3234,21 +3150,16 @@ var patchElement = (element, props) => {
|
|
|
3234
3150
|
}
|
|
3235
3151
|
return { didPatch, skipChildren: true };
|
|
3236
3152
|
}
|
|
3237
|
-
const attrBoundFields =
|
|
3238
|
-
for (const [an, av] of Object.entries(attribs)) {
|
|
3239
|
-
if (an.startsWith(FIELD_ATTR_PREFIX2) && an !== `${FIELD_ATTR_PREFIX2}name` && !tryParseFieldShape(av)) {
|
|
3240
|
-
attrBoundFields.add(av.trim());
|
|
3241
|
-
}
|
|
3242
|
-
}
|
|
3153
|
+
const attrBoundFields = attrBoundFieldNames(attribs);
|
|
3243
3154
|
for (const [attrName, attrValue] of Object.entries(attribs)) {
|
|
3244
|
-
if (!attrName.startsWith(
|
|
3245
|
-
const target = attrName.slice(
|
|
3155
|
+
if (!attrName.startsWith(FIELD_ATTR_PREFIX)) continue;
|
|
3156
|
+
const target = attrName.slice(FIELD_ATTR_PREFIX.length);
|
|
3246
3157
|
if (!target) continue;
|
|
3247
3158
|
const shape = tryParseFieldShape(attrValue);
|
|
3248
3159
|
if (shape) {
|
|
3249
3160
|
if (shape.type === "slot") continue;
|
|
3250
3161
|
const name2 = target;
|
|
3251
|
-
if (
|
|
3162
|
+
if (isFieldNameClaimed(name2, attrBoundFields)) continue;
|
|
3252
3163
|
const value2 = getDeepValue(props, name2);
|
|
3253
3164
|
if (shape.type === "richtext") {
|
|
3254
3165
|
if (typeof value2 !== "string") continue;
|
|
@@ -3264,27 +3175,11 @@ var patchElement = (element, props) => {
|
|
|
3264
3175
|
element.children = [text];
|
|
3265
3176
|
continue;
|
|
3266
3177
|
}
|
|
3267
|
-
const dotted = target.includes(".");
|
|
3268
|
-
const attrTarget = dotted ? target.split(".").pop() : target;
|
|
3269
|
-
if (!attrValue || dotted && !(attrTarget in attribs)) {
|
|
3270
|
-
if (attrBoundFields.has(target)) continue;
|
|
3271
|
-
const value2 = getDeepValue(props, target);
|
|
3272
|
-
if (element.children.some(isElement)) {
|
|
3273
|
-
if (typeof value2 !== "string") continue;
|
|
3274
|
-
replaceChildrenWithHtml(element, value2);
|
|
3275
|
-
didPatch = true;
|
|
3276
|
-
skipChildren = true;
|
|
3277
|
-
continue;
|
|
3278
|
-
}
|
|
3279
|
-
if (!isPatchablePrimitive(value2)) continue;
|
|
3280
|
-
didPatch = true;
|
|
3281
|
-
const text = new import_domhandler.Text(String(value2));
|
|
3282
|
-
text.parent = element;
|
|
3283
|
-
element.children = [text];
|
|
3284
|
-
continue;
|
|
3285
|
-
}
|
|
3286
3178
|
const name = attrValue.trim();
|
|
3287
3179
|
if (!name) continue;
|
|
3180
|
+
if (target === "name" && isFieldNameClaimed(name, attrBoundFields)) {
|
|
3181
|
+
continue;
|
|
3182
|
+
}
|
|
3288
3183
|
const value = getDeepValue(props, name);
|
|
3289
3184
|
if (target === "name" && getTypeModifier(attribs, name) === "richtext") {
|
|
3290
3185
|
if (typeof value !== "string") continue;
|
|
@@ -3300,7 +3195,7 @@ var patchElement = (element, props) => {
|
|
|
3300
3195
|
text.parent = element;
|
|
3301
3196
|
element.children = [text];
|
|
3302
3197
|
} else {
|
|
3303
|
-
attribs[
|
|
3198
|
+
attribs[target] = String(value);
|
|
3304
3199
|
}
|
|
3305
3200
|
}
|
|
3306
3201
|
return { didPatch, skipChildren };
|
|
@@ -3357,188 +3252,175 @@ var renderHtmlArrayItems = (html, arrayName, items) => {
|
|
|
3357
3252
|
};
|
|
3358
3253
|
|
|
3359
3254
|
// src/lib/design/annotations.ts
|
|
3360
|
-
init_react_import();
|
|
3361
3255
|
var cache = /* @__PURE__ */ new Map();
|
|
3362
|
-
var shapeSignature = (shapes) => Object.entries(shapes).map(([name, shape]) => `${name}:${shape?.type ?? ""}`).join(",");
|
|
3363
3256
|
var MAX_CACHE_ENTRIES = 32;
|
|
3364
|
-
var getAnnotations = (html
|
|
3365
|
-
const
|
|
3366
|
-
const cached = cache.get(key);
|
|
3257
|
+
var getAnnotations = (html) => {
|
|
3258
|
+
const cached = cache.get(html);
|
|
3367
3259
|
if (cached) return cached;
|
|
3368
|
-
const parsed = parseHtmlAnnotations(html
|
|
3260
|
+
const parsed = parseHtmlAnnotations(html);
|
|
3369
3261
|
if (cache.size >= MAX_CACHE_ENTRIES) {
|
|
3370
3262
|
cache.delete(cache.keys().next().value);
|
|
3371
3263
|
}
|
|
3372
|
-
cache.set(
|
|
3264
|
+
cache.set(html, parsed);
|
|
3373
3265
|
return parsed;
|
|
3374
3266
|
};
|
|
3375
3267
|
var getSlotFields = (html) => Object.fromEntries(
|
|
3376
3268
|
getAnnotations(html).slots.map((slot) => [slot.name, toSlotField(slot)])
|
|
3377
3269
|
);
|
|
3378
|
-
var UNTRANSFORMABLE_FIELD_TYPES = /* @__PURE__ */ new Set(["richtext", "array", "slot"]);
|
|
3379
|
-
var isTransformable = (field) => {
|
|
3380
|
-
if (!field?.type) return false;
|
|
3381
|
-
if (UNTRANSFORMABLE_FIELD_TYPES.has(field.type)) return false;
|
|
3382
|
-
const nested = field.objectFields ?? field.arrayFields;
|
|
3383
|
-
return nested ? Object.values(nested).every(isTransformable) : true;
|
|
3384
|
-
};
|
|
3385
|
-
var getTransformableFields = (reg) => {
|
|
3386
|
-
const annotations = getAnnotations(reg.html ?? "", reg.fields);
|
|
3387
|
-
const source = {
|
|
3388
|
-
...toPuckFields(annotations.fields, annotations.values),
|
|
3389
|
-
...reg.fields ?? {}
|
|
3390
|
-
};
|
|
3391
|
-
return Object.fromEntries(
|
|
3392
|
-
Object.entries(source).filter(([, field]) => isTransformable(field))
|
|
3393
|
-
);
|
|
3394
|
-
};
|
|
3395
|
-
|
|
3396
|
-
// src/lib/field-types.ts
|
|
3397
|
-
init_react_import();
|
|
3398
3270
|
|
|
3399
|
-
// src/lib/
|
|
3400
|
-
|
|
3401
|
-
|
|
3402
|
-
"
|
|
3403
|
-
|
|
3404
|
-
|
|
3405
|
-
|
|
3406
|
-
|
|
3407
|
-
|
|
3408
|
-
|
|
3409
|
-
|
|
3410
|
-
|
|
3271
|
+
// src/lib/morph-html.ts
|
|
3272
|
+
var PROTECTED_ATTRS = /* @__PURE__ */ new Set([
|
|
3273
|
+
"contenteditable",
|
|
3274
|
+
"data-puck-overlay-portal"
|
|
3275
|
+
]);
|
|
3276
|
+
var SLOT_OWNED_ATTRS = /* @__PURE__ */ new Set(["style", "class"]);
|
|
3277
|
+
var isEventHandlerAttr = (name) => /^on/i.test(name);
|
|
3278
|
+
var FIELD_ATTR_PREFIX2 = "data-puck-field-";
|
|
3279
|
+
var LEGACY_TEXT_ATTR = `${FIELD_ATTR_PREFIX2}name`;
|
|
3280
|
+
var VALUE_ATTR_PREFIX = `${FIELD_ATTR_PREFIX2}value-`;
|
|
3281
|
+
var hasTextBinding = (el, parsedTextFields) => {
|
|
3282
|
+
for (const attr of Array.from(el.attributes)) {
|
|
3283
|
+
if (!attr.name.startsWith(FIELD_ATTR_PREFIX2)) continue;
|
|
3284
|
+
if (attr.name.startsWith(VALUE_ATTR_PREFIX)) continue;
|
|
3285
|
+
const isShape = attr.value.trimStart().startsWith("{");
|
|
3286
|
+
const fieldName = isShape ? attr.name.slice(FIELD_ATTR_PREFIX2.length) : attr.value.trim();
|
|
3287
|
+
if (isValidFieldName(fieldName) && (attr.name === LEGACY_TEXT_ATTR || isShape) && (!parsedTextFields || parsedTextFields.has(fieldName))) {
|
|
3288
|
+
return true;
|
|
3289
|
+
}
|
|
3290
|
+
}
|
|
3291
|
+
return false;
|
|
3411
3292
|
};
|
|
3412
|
-
var
|
|
3413
|
-
|
|
3414
|
-
|
|
3415
|
-
|
|
3416
|
-
|
|
3417
|
-
|
|
3293
|
+
var ownsItsChildren = (el, parsedTextFields) => el.hasAttribute("data-puck-slot") || el.hasAttribute("data-puck-array") || hasTextBinding(el, parsedTextFields);
|
|
3294
|
+
var syncAttributes = (target, source) => {
|
|
3295
|
+
const isSlot = target.hasAttribute("data-puck-slot");
|
|
3296
|
+
for (const attr of Array.from(target.attributes)) {
|
|
3297
|
+
if (PROTECTED_ATTRS.has(attr.name)) continue;
|
|
3298
|
+
if (isSlot && SLOT_OWNED_ATTRS.has(attr.name)) continue;
|
|
3299
|
+
if (isEventHandlerAttr(attr.name) || !source.hasAttribute(attr.name)) {
|
|
3300
|
+
target.removeAttribute(attr.name);
|
|
3301
|
+
}
|
|
3302
|
+
}
|
|
3303
|
+
for (const attr of Array.from(source.attributes)) {
|
|
3304
|
+
if (PROTECTED_ATTRS.has(attr.name)) continue;
|
|
3305
|
+
if (isSlot && SLOT_OWNED_ATTRS.has(attr.name)) continue;
|
|
3306
|
+
if (isEventHandlerAttr(attr.name)) continue;
|
|
3307
|
+
if (target.getAttribute(attr.name) !== attr.value) {
|
|
3308
|
+
target.setAttribute(attr.name, attr.value);
|
|
3309
|
+
}
|
|
3310
|
+
}
|
|
3418
3311
|
};
|
|
3419
|
-
var
|
|
3420
|
-
|
|
3421
|
-
|
|
3312
|
+
var isSameKind = (a, b) => a.nodeType === b.nodeType && (a.nodeType !== Node.ELEMENT_NODE || a.tagName === b.tagName);
|
|
3313
|
+
var isIncompleteTagArtifact = (node) => node.nodeType === Node.TEXT_NODE && /^<\/?[a-zA-Z]*$/.test(node.nodeValue ?? "");
|
|
3314
|
+
var stripIncompleteTagArtifacts = (root) => {
|
|
3315
|
+
for (const child of Array.from(root.childNodes)) {
|
|
3316
|
+
if (isIncompleteTagArtifact(child)) {
|
|
3317
|
+
root.removeChild(child);
|
|
3318
|
+
} else if (child.nodeType === Node.ELEMENT_NODE) {
|
|
3319
|
+
stripIncompleteTagArtifacts(child);
|
|
3320
|
+
}
|
|
3422
3321
|
}
|
|
3423
|
-
if (key && NAME_EXAMPLES[key]) return NAME_EXAMPLES[key];
|
|
3424
|
-
if (typeof schema.pattern === "string") return `<matching ${schema.pattern}>`;
|
|
3425
|
-
return "Example";
|
|
3426
3322
|
};
|
|
3427
|
-
var
|
|
3428
|
-
|
|
3429
|
-
|
|
3430
|
-
|
|
3431
|
-
|
|
3432
|
-
|
|
3433
|
-
value = Math.ceil(value / multipleOf) * multipleOf;
|
|
3434
|
-
}
|
|
3435
|
-
if (typeof maximum === "number" && value > maximum) value = maximum;
|
|
3436
|
-
if (typeof exclusiveMaximum === "number" && value >= exclusiveMaximum) {
|
|
3437
|
-
value = exclusiveMaximum - (isInteger ? 1 : step);
|
|
3438
|
-
}
|
|
3439
|
-
return isInteger ? Math.round(value) : value;
|
|
3323
|
+
var stripEventHandlerAttrs = (root) => {
|
|
3324
|
+
root.querySelectorAll("*").forEach((el) => {
|
|
3325
|
+
for (const attr of Array.from(el.attributes)) {
|
|
3326
|
+
if (isEventHandlerAttr(attr.name)) el.removeAttribute(attr.name);
|
|
3327
|
+
}
|
|
3328
|
+
});
|
|
3440
3329
|
};
|
|
3441
|
-
var
|
|
3442
|
-
|
|
3443
|
-
|
|
3444
|
-
|
|
3445
|
-
|
|
3446
|
-
|
|
3447
|
-
|
|
3448
|
-
|
|
3449
|
-
if (Array.isArray(schema.anyOf) && schema.anyOf.length > 0) {
|
|
3450
|
-
return jsonSchemaExample(schema.anyOf[0]);
|
|
3451
|
-
}
|
|
3452
|
-
switch (schema.type) {
|
|
3453
|
-
case "string":
|
|
3454
|
-
return stringExample(schema, key);
|
|
3455
|
-
case "number":
|
|
3456
|
-
case "integer":
|
|
3457
|
-
return numberExample(schema);
|
|
3458
|
-
case "boolean":
|
|
3459
|
-
return true;
|
|
3460
|
-
case "array": {
|
|
3461
|
-
const min = typeof schema.minItems === "number" ? schema.minItems : 1;
|
|
3462
|
-
const max = typeof schema.maxItems === "number" ? schema.maxItems : Infinity;
|
|
3463
|
-
const count = Math.max(Math.min(min || 1, max), 0);
|
|
3464
|
-
return Array.from(
|
|
3465
|
-
{ length: count },
|
|
3466
|
-
() => jsonSchemaExample(schema.items, key)
|
|
3467
|
-
);
|
|
3330
|
+
var morphChildren = (target, source, skipChildrenOf = ownsItsChildren) => {
|
|
3331
|
+
const sourceChildren = Array.from(source.childNodes);
|
|
3332
|
+
for (let i = 0; i < sourceChildren.length; i++) {
|
|
3333
|
+
const sourceChild = sourceChildren[i];
|
|
3334
|
+
const targetChild = target.childNodes[i];
|
|
3335
|
+
if (!targetChild) {
|
|
3336
|
+
target.appendChild(sourceChild);
|
|
3337
|
+
continue;
|
|
3468
3338
|
}
|
|
3469
|
-
|
|
3470
|
-
|
|
3471
|
-
|
|
3472
|
-
|
|
3473
|
-
|
|
3474
|
-
|
|
3475
|
-
|
|
3476
|
-
|
|
3339
|
+
if (!isSameKind(targetChild, sourceChild)) {
|
|
3340
|
+
target.replaceChild(sourceChild, targetChild);
|
|
3341
|
+
continue;
|
|
3342
|
+
}
|
|
3343
|
+
if (sourceChild.nodeType !== Node.ELEMENT_NODE) {
|
|
3344
|
+
if (targetChild.nodeValue !== sourceChild.nodeValue) {
|
|
3345
|
+
targetChild.nodeValue = sourceChild.nodeValue;
|
|
3346
|
+
}
|
|
3347
|
+
continue;
|
|
3477
3348
|
}
|
|
3478
|
-
|
|
3479
|
-
|
|
3349
|
+
const targetEl = targetChild;
|
|
3350
|
+
syncAttributes(targetEl, sourceChild);
|
|
3351
|
+
if (!skipChildrenOf(targetEl)) {
|
|
3352
|
+
morphChildren(targetEl, sourceChild, skipChildrenOf);
|
|
3353
|
+
}
|
|
3354
|
+
}
|
|
3355
|
+
while (target.childNodes.length > sourceChildren.length) {
|
|
3356
|
+
target.removeChild(target.lastChild);
|
|
3480
3357
|
}
|
|
3481
3358
|
};
|
|
3359
|
+
function morphHtml(container, html, attrOverrides = [], skipChildrenOf) {
|
|
3360
|
+
const template = container.ownerDocument.createElement("template");
|
|
3361
|
+
template.innerHTML = html;
|
|
3362
|
+
stripIncompleteTagArtifacts(template.content);
|
|
3363
|
+
stripEventHandlerAttrs(template.content);
|
|
3364
|
+
if (attrOverrides.length > 0) {
|
|
3365
|
+
const overridesByAttr = /* @__PURE__ */ new Map();
|
|
3366
|
+
for (const override of attrOverrides) {
|
|
3367
|
+
if (isEventHandlerAttr(override.attr)) continue;
|
|
3368
|
+
const bindingAttr = `${FIELD_ATTR_PREFIX2}${override.attr}`;
|
|
3369
|
+
const fields = overridesByAttr.get(bindingAttr) ?? /* @__PURE__ */ new Map();
|
|
3370
|
+
fields.set(override.name, override);
|
|
3371
|
+
overridesByAttr.set(bindingAttr, fields);
|
|
3372
|
+
}
|
|
3373
|
+
template.content.querySelectorAll("*").forEach((el) => {
|
|
3374
|
+
for (const attr of Array.from(el.attributes)) {
|
|
3375
|
+
const override = overridesByAttr.get(attr.name)?.get(attr.value.trim());
|
|
3376
|
+
if (!override) continue;
|
|
3377
|
+
if (el.closest("[data-puck-array]")) return;
|
|
3378
|
+
el.setAttribute(override.attr, override.value);
|
|
3379
|
+
}
|
|
3380
|
+
});
|
|
3381
|
+
}
|
|
3382
|
+
if (skipChildrenOf) {
|
|
3383
|
+
morphChildren(container, template.content, skipChildrenOf);
|
|
3384
|
+
return;
|
|
3385
|
+
}
|
|
3386
|
+
const parsedTextFields = new Set(
|
|
3387
|
+
getAnnotations(html).fields.filter((field) => field.binding === "text").map((field) => field.name)
|
|
3388
|
+
);
|
|
3389
|
+
morphChildren(
|
|
3390
|
+
container,
|
|
3391
|
+
template.content,
|
|
3392
|
+
(el) => ownsItsChildren(el, parsedTextFields)
|
|
3393
|
+
);
|
|
3394
|
+
}
|
|
3482
3395
|
|
|
3483
|
-
// src/lib/
|
|
3484
|
-
|
|
3485
|
-
|
|
3486
|
-
|
|
3487
|
-
|
|
3488
|
-
|
|
3489
|
-
|
|
3490
|
-
|
|
3491
|
-
|
|
3396
|
+
// src/lib/design/observer-guard.ts
|
|
3397
|
+
init_react_import();
|
|
3398
|
+
var wrapScriptWithObserverGuard = (script) => {
|
|
3399
|
+
if (!script.includes("MutationObserver")) return script;
|
|
3400
|
+
return `(function () {
|
|
3401
|
+
var __NativeMutationObserver = window.MutationObserver;
|
|
3402
|
+
function MutationObserver(callback) {
|
|
3403
|
+
var observed = [];
|
|
3404
|
+
var inner = new __NativeMutationObserver(function (records) {
|
|
3405
|
+
inner.disconnect();
|
|
3406
|
+
try {
|
|
3407
|
+
callback(records, inner);
|
|
3408
|
+
} finally {
|
|
3409
|
+
for (var i = 0; i < observed.length; i++) {
|
|
3410
|
+
__nativeObserve.call(inner, observed[i][0], observed[i][1]);
|
|
3411
|
+
}
|
|
3492
3412
|
}
|
|
3493
|
-
|
|
3494
|
-
|
|
3495
|
-
)
|
|
3496
|
-
|
|
3497
|
-
|
|
3498
|
-
|
|
3499
|
-
|
|
3500
|
-
var getFieldTypes = () => registry;
|
|
3501
|
-
var getFieldTypeDefault = (type, ctx2) => {
|
|
3502
|
-
const fieldType = registry[type];
|
|
3503
|
-
if (!fieldType) return void 0;
|
|
3504
|
-
if (fieldType.defaultValue !== void 0) {
|
|
3505
|
-
return typeof fieldType.defaultValue === "function" ? fieldType.defaultValue(ctx2) : fieldType.defaultValue;
|
|
3506
|
-
}
|
|
3507
|
-
return jsonSchemaExample(fieldType.schema);
|
|
3508
|
-
};
|
|
3509
|
-
var isUnvalued = (value) => value === void 0 || !!value && typeof value === "object" && !Array.isArray(value) && Object.keys(value).length === 0;
|
|
3510
|
-
var fill = (values, fields, componentName, declared, path) => {
|
|
3511
|
-
let out = values;
|
|
3512
|
-
for (const [fieldName, field] of Object.entries(fields ?? {})) {
|
|
3513
|
-
const type = field?.type;
|
|
3514
|
-
if (!type) continue;
|
|
3515
|
-
const qualified = path ? `${path}.${fieldName}` : fieldName;
|
|
3516
|
-
if (registry[type]) {
|
|
3517
|
-
if (!isUnvalued(out[fieldName])) continue;
|
|
3518
|
-
const declaredValue = declared?.[fieldName];
|
|
3519
|
-
const value = isUnvalued(declaredValue) ? getFieldTypeDefault(type, { componentName, fieldName: qualified }) : declaredValue;
|
|
3520
|
-
if (isUnvalued(value)) continue;
|
|
3521
|
-
if (out === values) out = { ...values };
|
|
3522
|
-
out[fieldName] = value;
|
|
3523
|
-
continue;
|
|
3524
|
-
}
|
|
3525
|
-
if (!field.objectFields) continue;
|
|
3526
|
-
const group = out[fieldName];
|
|
3527
|
-
const declaredGroup = declared?.[fieldName];
|
|
3528
|
-
const filled = fill(
|
|
3529
|
-
group && typeof group === "object" ? group : {},
|
|
3530
|
-
field.objectFields,
|
|
3531
|
-
componentName,
|
|
3532
|
-
declaredGroup && typeof declaredGroup === "object" ? declaredGroup : void 0,
|
|
3533
|
-
qualified
|
|
3534
|
-
);
|
|
3535
|
-
if (filled === group) continue;
|
|
3536
|
-
if (out === values) out = { ...values };
|
|
3537
|
-
out[fieldName] = filled;
|
|
3413
|
+
});
|
|
3414
|
+
var __nativeObserve = inner.observe;
|
|
3415
|
+
inner.observe = function (target, options) {
|
|
3416
|
+
observed.push([target, options]);
|
|
3417
|
+
return __nativeObserve.call(inner, target, options);
|
|
3418
|
+
};
|
|
3419
|
+
return inner;
|
|
3538
3420
|
}
|
|
3539
|
-
|
|
3421
|
+
${script}
|
|
3422
|
+
})();`;
|
|
3540
3423
|
};
|
|
3541
|
-
var withFieldTypeDefaults = (values, fields, componentName, declared) => fill(values, fields, componentName, declared, "");
|
|
3542
3424
|
|
|
3543
3425
|
// src/lib/design/registration-store.ts
|
|
3544
3426
|
init_react_import();
|
|
@@ -3613,12 +3495,7 @@ init_react_import();
|
|
|
3613
3495
|
var import_core2 = require("@puckeditor/core");
|
|
3614
3496
|
var CONTENT_EDITABLE_ATTR = "data-puck-content-editable";
|
|
3615
3497
|
var isInlineEditingDisabled = (el) => el.closest(`[${CONTENT_EDITABLE_ATTR}="false"]`) !== null;
|
|
3616
|
-
var cssEscape = (value) => typeof CSS !== "undefined" && CSS.escape ? CSS.escape(value) : (
|
|
3617
|
-
// Escapes for an IDENTIFIER, not just a quoted value: a dotted field name
|
|
3618
|
-
// sits in the attribute-name slot too, where an unescaped `.` reads as a
|
|
3619
|
-
// class selector and throws. Over-escaping inside quotes is harmless.
|
|
3620
|
-
value.replace(/[^\w-]/g, "\\$&")
|
|
3621
|
-
);
|
|
3498
|
+
var cssEscape = (value) => typeof CSS !== "undefined" && CSS.escape ? CSS.escape(value) : value.replace(/["\\]/g, "\\$&");
|
|
3622
3499
|
var queryScopedFields = (entry, selector) => Array.from(entry.querySelectorAll(selector)).filter((el) => {
|
|
3623
3500
|
if (el.closest("[data-puck-array]")) return false;
|
|
3624
3501
|
const closestSlot = el.closest("[data-puck-slot]");
|
|
@@ -3912,15 +3789,7 @@ var parseStyleString = (cssText) => {
|
|
|
3912
3789
|
return style;
|
|
3913
3790
|
};
|
|
3914
3791
|
var isEventHandlerAttr2 = (name) => /^on/i.test(name);
|
|
3915
|
-
var
|
|
3916
|
-
var fieldContentFor = (attribs, fields) => {
|
|
3917
|
-
for (const name of Object.keys(fields)) {
|
|
3918
|
-
if (attribs[`${FIELD_ATTR_PREFIX3}${name}`] !== void 0) return name;
|
|
3919
|
-
if (attribs["data-puck-field-name"] === name) return name;
|
|
3920
|
-
}
|
|
3921
|
-
return void 0;
|
|
3922
|
-
};
|
|
3923
|
-
var nodeToReact = (node, slots, fields, key) => {
|
|
3792
|
+
var nodeToReact = (node, slots, key) => {
|
|
3924
3793
|
if (node.type === "text") {
|
|
3925
3794
|
return node.data;
|
|
3926
3795
|
}
|
|
@@ -3951,17 +3820,13 @@ var nodeToReact = (node, slots, fields, key) => {
|
|
|
3951
3820
|
if (VOID_ELEMENTS.has(tag)) {
|
|
3952
3821
|
return (0, import_react22.createElement)(tag, props);
|
|
3953
3822
|
}
|
|
3954
|
-
const
|
|
3955
|
-
if (fieldName !== void 0) {
|
|
3956
|
-
return (0, import_react22.createElement)(tag, props, fields[fieldName]);
|
|
3957
|
-
}
|
|
3958
|
-
const children = el.children.map((child, i) => nodeToReact(child, slots, fields, i)).filter((c) => c !== null);
|
|
3823
|
+
const children = el.children.map((child, i) => nodeToReact(child, slots, i)).filter((c) => c !== null);
|
|
3959
3824
|
return (0, import_react22.createElement)(tag, props, ...children);
|
|
3960
3825
|
};
|
|
3961
|
-
var htmlToReactTree = (html, slots
|
|
3826
|
+
var htmlToReactTree = (html, slots) => {
|
|
3962
3827
|
if (!html) return null;
|
|
3963
3828
|
const doc = (0, import_htmlparser22.parseDocument)(html);
|
|
3964
|
-
const children = doc.children.map((child, i) => nodeToReact(child, slots,
|
|
3829
|
+
const children = doc.children.map((child, i) => nodeToReact(child, slots, i)).filter((c) => c !== null);
|
|
3965
3830
|
if (children.length === 0) return null;
|
|
3966
3831
|
if (children.length === 1) return children[0];
|
|
3967
3832
|
return (0, import_react22.createElement)(import_react22.Fragment, null, ...children);
|
|
@@ -3971,7 +3836,7 @@ var htmlToReactTree = (html, slots, fields = {}) => {
|
|
|
3971
3836
|
init_react_import();
|
|
3972
3837
|
var import_react23 = require("react");
|
|
3973
3838
|
var import_react_dom = require("react-dom");
|
|
3974
|
-
var
|
|
3839
|
+
var import_jsx_runtime30 = require("react/jsx-runtime");
|
|
3975
3840
|
var parseInlineStyle = (cssText) => {
|
|
3976
3841
|
const style = {};
|
|
3977
3842
|
for (const declaration of cssText.split(";")) {
|
|
@@ -4013,37 +3878,15 @@ var SlotPortal = ({
|
|
|
4013
3878
|
}, [entry, html, slotName]);
|
|
4014
3879
|
if (!target || typeof SlotContent !== "function") return null;
|
|
4015
3880
|
return (0, import_react_dom.createPortal)(
|
|
4016
|
-
/* @__PURE__ */ (0,
|
|
3881
|
+
/* @__PURE__ */ (0, import_jsx_runtime30.jsx)(SlotContent, { style, className: slotClassName || void 0 }),
|
|
4017
3882
|
target
|
|
4018
3883
|
);
|
|
4019
3884
|
};
|
|
4020
3885
|
|
|
4021
|
-
// src/lib/design/field-portal.tsx
|
|
4022
|
-
init_react_import();
|
|
4023
|
-
var import_react24 = require("react");
|
|
4024
|
-
var import_react_dom2 = require("react-dom");
|
|
4025
|
-
var FieldPortal = ({
|
|
4026
|
-
entry,
|
|
4027
|
-
html,
|
|
4028
|
-
selector,
|
|
4029
|
-
children
|
|
4030
|
-
}) => {
|
|
4031
|
-
const [target, setTarget] = (0, import_react24.useState)(null);
|
|
4032
|
-
const lastTarget = (0, import_react24.useRef)(null);
|
|
4033
|
-
(0, import_react24.useEffect)(() => {
|
|
4034
|
-
const el = queryScopedFields(entry, selector)[0] ?? null;
|
|
4035
|
-
if (el !== lastTarget.current) {
|
|
4036
|
-
el?.replaceChildren();
|
|
4037
|
-
lastTarget.current = el;
|
|
4038
|
-
setTarget(el);
|
|
4039
|
-
}
|
|
4040
|
-
}, [entry, html, selector]);
|
|
4041
|
-
if (!target) return null;
|
|
4042
|
-
return (0, import_react_dom2.createPortal)(children, target);
|
|
4043
|
-
};
|
|
4044
|
-
|
|
4045
3886
|
// src/lib/design/component.tsx
|
|
4046
|
-
var
|
|
3887
|
+
var import_jsx_runtime31 = require("react/jsx-runtime");
|
|
3888
|
+
var DESIGN_COMPONENT = Symbol("puck-ai.designComponent");
|
|
3889
|
+
var isDesignComponent = (config) => !!config?.[DESIGN_COMPONENT];
|
|
4047
3890
|
var streamingValues = /* @__PURE__ */ new Map();
|
|
4048
3891
|
var instanceKey = (name, instanceId) => `${name}:${typeof instanceId === "string" ? instanceId : ""}`;
|
|
4049
3892
|
var getRegistrationSlotFields = (reg) => {
|
|
@@ -4062,43 +3905,16 @@ var getRegistrationSlotFields = (reg) => {
|
|
|
4062
3905
|
])
|
|
4063
3906
|
);
|
|
4064
3907
|
};
|
|
4065
|
-
var hasPendingUserField = (field, value) => {
|
|
4066
|
-
if (!field?.type || field.type === "slot") return false;
|
|
4067
|
-
if (!isBuiltInFieldType(field.type)) return value === void 0;
|
|
4068
|
-
if (field.objectFields) {
|
|
4069
|
-
const group = value && typeof value === "object" ? value : {};
|
|
4070
|
-
return Object.entries(field.objectFields).some(
|
|
4071
|
-
([key, child]) => hasPendingUserField(child, group[key])
|
|
4072
|
-
);
|
|
4073
|
-
}
|
|
4074
|
-
if (field.arrayFields) {
|
|
4075
|
-
const items = Array.isArray(value) ? value : [];
|
|
4076
|
-
return items.some(
|
|
4077
|
-
(item) => Object.entries(field.arrayFields).some(
|
|
4078
|
-
([key, child]) => hasPendingUserField(child, item?.[key])
|
|
4079
|
-
)
|
|
4080
|
-
);
|
|
4081
|
-
}
|
|
4082
|
-
return false;
|
|
4083
|
-
};
|
|
4084
3908
|
function createDesignComponentConfig(registration) {
|
|
4085
3909
|
const name = registration.name;
|
|
4086
3910
|
if (registrationStore.get(name) !== registration) {
|
|
4087
3911
|
registrationStore.apply(registration);
|
|
4088
3912
|
}
|
|
4089
3913
|
const slotFields = getRegistrationSlotFields(registration);
|
|
4090
|
-
const
|
|
4091
|
-
...slotFields,
|
|
4092
|
-
...getTransformableFields(registration)
|
|
4093
|
-
};
|
|
4094
|
-
return {
|
|
3914
|
+
const componentConfig = {
|
|
4095
3915
|
...registration.label ? { label: registration.label } : {},
|
|
4096
|
-
fields:
|
|
4097
|
-
defaultProps:
|
|
4098
|
-
{ ...registration.defaultProps ?? {} },
|
|
4099
|
-
staticFields,
|
|
4100
|
-
name
|
|
4101
|
-
),
|
|
3916
|
+
fields: { ...slotFields },
|
|
3917
|
+
defaultProps: { ...registration.defaultProps ?? {} },
|
|
4102
3918
|
resolveData: (data, { trigger }) => {
|
|
4103
3919
|
if (trigger !== "replace" && trigger !== "insert" && trigger !== "force") {
|
|
4104
3920
|
return data;
|
|
@@ -4106,22 +3922,22 @@ function createDesignComponentConfig(registration) {
|
|
|
4106
3922
|
const reg = registrationStore.get(name) ?? registration;
|
|
4107
3923
|
const markup = reg.html ?? "";
|
|
4108
3924
|
if (!markup) return { props: {} };
|
|
4109
|
-
const annotations = getAnnotations(markup
|
|
4110
|
-
const fieldSet = getTransformableFields(reg);
|
|
4111
|
-
const extracted = withFieldTypeDefaults(
|
|
4112
|
-
annotations.values,
|
|
4113
|
-
fieldSet,
|
|
4114
|
-
name,
|
|
4115
|
-
reg.defaultProps
|
|
4116
|
-
);
|
|
3925
|
+
const annotations = getAnnotations(markup);
|
|
4117
3926
|
const cacheKey = instanceKey(name, data.props.id);
|
|
4118
3927
|
let newProps;
|
|
4119
3928
|
if (reg.streaming) {
|
|
4120
3929
|
const previous = streamingValues.get(cacheKey) ?? registrationStore.getPreviousValues(name);
|
|
4121
|
-
newProps = resolveStreamingProps(
|
|
4122
|
-
|
|
3930
|
+
newProps = resolveStreamingProps(
|
|
3931
|
+
data.props,
|
|
3932
|
+
annotations.values,
|
|
3933
|
+
previous
|
|
3934
|
+
);
|
|
3935
|
+
streamingValues.set(cacheKey, annotations.values);
|
|
4123
3936
|
} else {
|
|
4124
|
-
const values = {
|
|
3937
|
+
const values = {
|
|
3938
|
+
...annotations.values,
|
|
3939
|
+
...reg.defaultProps ?? {}
|
|
3940
|
+
};
|
|
4125
3941
|
const previous = streamingValues.get(cacheKey);
|
|
4126
3942
|
if (previous) {
|
|
4127
3943
|
newProps = resolveStreamingProps(data.props, values, previous);
|
|
@@ -4135,46 +3951,32 @@ function createDesignComponentConfig(registration) {
|
|
|
4135
3951
|
}
|
|
4136
3952
|
streamingValues.delete(cacheKey);
|
|
4137
3953
|
}
|
|
4138
|
-
const merged = { ...data.props, ...newProps };
|
|
4139
|
-
const filled = withFieldTypeDefaults(
|
|
4140
|
-
merged,
|
|
4141
|
-
fieldSet,
|
|
4142
|
-
name,
|
|
4143
|
-
reg.defaultProps
|
|
4144
|
-
);
|
|
4145
|
-
if (filled !== merged) {
|
|
4146
|
-
for (const [key, value] of Object.entries(filled)) {
|
|
4147
|
-
if (value !== merged[key]) newProps[key] = value;
|
|
4148
|
-
}
|
|
4149
|
-
}
|
|
4150
3954
|
if (Object.keys(newProps).length === 0) return { props: {} };
|
|
4151
3955
|
return { props: newProps };
|
|
4152
3956
|
},
|
|
4153
|
-
resolveFields: (
|
|
3957
|
+
resolveFields: () => {
|
|
4154
3958
|
const reg = registrationStore.get(name) ?? registration;
|
|
4155
3959
|
const fields = reg.fields ?? {};
|
|
4156
|
-
let resolvedFields;
|
|
4157
3960
|
if (Object.keys(fields).length > 0) {
|
|
4158
|
-
|
|
4159
|
-
} else {
|
|
4160
|
-
const annotations = getAnnotations(reg.html ?? "");
|
|
4161
|
-
resolvedFields = toPuckFields(annotations.fields, annotations.values);
|
|
4162
|
-
for (const slot of annotations.slots) {
|
|
4163
|
-
resolvedFields[slot.name] = toSlotField(slot);
|
|
4164
|
-
}
|
|
3961
|
+
return { ...fields };
|
|
4165
3962
|
}
|
|
4166
|
-
|
|
4167
|
-
|
|
4168
|
-
|
|
4169
|
-
|
|
4170
|
-
)
|
|
3963
|
+
const annotations = getAnnotations(reg.html ?? "");
|
|
3964
|
+
const resolvedFields = toPuckFields(
|
|
3965
|
+
annotations.fields,
|
|
3966
|
+
annotations.values
|
|
4171
3967
|
);
|
|
3968
|
+
for (const slot of annotations.slots) {
|
|
3969
|
+
resolvedFields[slot.name] = toSlotField(slot);
|
|
3970
|
+
}
|
|
3971
|
+
return resolvedFields;
|
|
4172
3972
|
},
|
|
4173
|
-
render: (renderProps) => renderProps.puck?.isEditing ? /* @__PURE__ */ (0,
|
|
3973
|
+
render: (renderProps) => renderProps.puck?.isEditing ? /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(EditorEntry, { ...renderProps }) : /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(Entry, { ...renderProps, getPuck: null })
|
|
4174
3974
|
};
|
|
3975
|
+
componentConfig[DESIGN_COMPONENT] = true;
|
|
3976
|
+
return componentConfig;
|
|
4175
3977
|
function EditorEntry(renderProps) {
|
|
4176
3978
|
const getPuck = (0, import_core3.useGetPuck)();
|
|
4177
|
-
return /* @__PURE__ */ (0,
|
|
3979
|
+
return /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(Entry, { ...renderProps, getPuck });
|
|
4178
3980
|
}
|
|
4179
3981
|
function Entry({
|
|
4180
3982
|
getPuck,
|
|
@@ -4183,11 +3985,11 @@ function createDesignComponentConfig(registration) {
|
|
|
4183
3985
|
style,
|
|
4184
3986
|
...props
|
|
4185
3987
|
}) {
|
|
4186
|
-
const getSnapshot = (0,
|
|
3988
|
+
const getSnapshot = (0, import_react24.useCallback)(
|
|
4187
3989
|
() => registrationStore.get(name) ?? registration,
|
|
4188
3990
|
[]
|
|
4189
3991
|
);
|
|
4190
|
-
const reg = (0,
|
|
3992
|
+
const reg = (0, import_react24.useSyncExternalStore)(
|
|
4191
3993
|
registrationStore.subscribe,
|
|
4192
3994
|
getSnapshot,
|
|
4193
3995
|
getSnapshot
|
|
@@ -4195,13 +3997,10 @@ function createDesignComponentConfig(registration) {
|
|
|
4195
3997
|
const html = reg.html ?? "";
|
|
4196
3998
|
const styles = reg.styles;
|
|
4197
3999
|
const script = reg.script;
|
|
4198
|
-
const [entryEl, setEntryEl] = (0,
|
|
4199
|
-
const scriptRef = (0,
|
|
4200
|
-
const annotations = (0,
|
|
4201
|
-
|
|
4202
|
-
[html, reg.fields]
|
|
4203
|
-
);
|
|
4204
|
-
const { attrFields, arrayFields, attrSig, arraySig } = (0, import_react25.useMemo)(() => {
|
|
4000
|
+
const [entryEl, setEntryEl] = (0, import_react24.useState)(null);
|
|
4001
|
+
const scriptRef = (0, import_react24.useRef)(null);
|
|
4002
|
+
const annotations = (0, import_react24.useMemo)(() => getAnnotations(html), [html]);
|
|
4003
|
+
const { attrFields, arrayFields, attrSig, arraySig } = (0, import_react24.useMemo)(() => {
|
|
4205
4004
|
const attr = [];
|
|
4206
4005
|
const arrays = [];
|
|
4207
4006
|
for (const field of annotations.fields) {
|
|
@@ -4223,61 +4022,32 @@ function createDesignComponentConfig(registration) {
|
|
|
4223
4022
|
arraySig: JSON.stringify(arrays)
|
|
4224
4023
|
};
|
|
4225
4024
|
}, [props, annotations]);
|
|
4226
|
-
const
|
|
4227
|
-
const out = [];
|
|
4228
|
-
for (const field of annotations.fields) {
|
|
4229
|
-
if (field.binding !== "text") continue;
|
|
4230
|
-
const value = getDeepValue(props, field.name);
|
|
4231
|
-
if (!import_react25.default.isValidElement(value)) continue;
|
|
4232
|
-
out.push({
|
|
4233
|
-
name: field.name,
|
|
4234
|
-
selector: textFieldSelector(field),
|
|
4235
|
-
node: value
|
|
4236
|
-
});
|
|
4237
|
-
}
|
|
4238
|
-
return out;
|
|
4239
|
-
}, [annotations, props]);
|
|
4240
|
-
const storedProps = (0, import_react25.useMemo)(
|
|
4241
|
-
() => getPuck ? getPuck().getItemById(id)?.props : void 0,
|
|
4242
|
-
[getPuck, id, props]
|
|
4243
|
-
);
|
|
4244
|
-
const editableFields = (0, import_react25.useMemo)(() => {
|
|
4245
|
-
const mounted = new Set(nodeFields.map((f) => f.name));
|
|
4246
|
-
return annotations.fields.filter((field) => {
|
|
4247
|
-
if (mounted.has(field.name)) return false;
|
|
4248
|
-
if (field.binding === "array") return true;
|
|
4249
|
-
if (field.shape && !isBuiltInFieldType(field.shape.type)) return false;
|
|
4250
|
-
if (!storedProps) return true;
|
|
4251
|
-
return getDeepValue(props, field.name) === getDeepValue(storedProps, field.name);
|
|
4252
|
-
});
|
|
4253
|
-
}, [annotations, nodeFields, props, storedProps]);
|
|
4254
|
-
const patchedHtml = (0, import_react25.useMemo)(() => {
|
|
4025
|
+
const patchedHtml = (0, import_react24.useMemo)(() => {
|
|
4255
4026
|
if (puck.isEditing) return html;
|
|
4256
4027
|
return patchHtmlAnnotations(html, props);
|
|
4257
4028
|
}, [html, props, puck.isEditing]);
|
|
4258
|
-
const fieldValueAttrs = (0,
|
|
4029
|
+
const fieldValueAttrs = (0, import_react24.useMemo)(() => {
|
|
4259
4030
|
const attrs = {};
|
|
4260
4031
|
attrs["data-puck-design"] = name;
|
|
4261
4032
|
for (const field of annotations.fields) {
|
|
4262
4033
|
const value = getDeepValue(props, field.name);
|
|
4263
4034
|
if (value === void 0 || value === null) continue;
|
|
4264
4035
|
if (!isValidFieldName(field.name)) continue;
|
|
4265
|
-
if (import_react25.default.isValidElement(value)) continue;
|
|
4266
4036
|
attrs[`data-puck-field-value-${field.name}`] = typeof value === "string" || typeof value === "number" ? String(value) : JSON.stringify(value);
|
|
4267
4037
|
}
|
|
4268
4038
|
return attrs;
|
|
4269
4039
|
}, [annotations, props, puck.isEditing]);
|
|
4270
|
-
const editorEntryNode = (0,
|
|
4271
|
-
() => puck.isEditing ? /* @__PURE__ */ (0,
|
|
4040
|
+
const editorEntryNode = (0, import_react24.useMemo)(
|
|
4041
|
+
() => puck.isEditing ? /* @__PURE__ */ (0, import_jsx_runtime31.jsx)("div", { ref: setEntryEl }) : null,
|
|
4272
4042
|
[puck.isEditing]
|
|
4273
4043
|
);
|
|
4274
|
-
(0,
|
|
4044
|
+
(0, import_react24.useEffect)(() => {
|
|
4275
4045
|
if (!puck.isEditing || !getPuck) return;
|
|
4276
4046
|
getPuck().resolveDataById(id, "force");
|
|
4277
4047
|
}, [reg, puck.isEditing, getPuck, id]);
|
|
4278
|
-
const fieldWiring = (0,
|
|
4279
|
-
const morphed = (0,
|
|
4280
|
-
(0,
|
|
4048
|
+
const fieldWiring = (0, import_react24.useRef)(/* @__PURE__ */ new Map());
|
|
4049
|
+
const morphed = (0, import_react24.useRef)(null);
|
|
4050
|
+
(0, import_react24.useLayoutEffect)(() => {
|
|
4281
4051
|
if (!puck.isEditing || !entryEl) return;
|
|
4282
4052
|
if (morphed.current?.el !== entryEl || morphed.current?.html !== html || morphed.current?.attrSig !== attrSig) {
|
|
4283
4053
|
morphed.current = { el: entryEl, html, attrSig };
|
|
@@ -4288,20 +4058,20 @@ function createDesignComponentConfig(registration) {
|
|
|
4288
4058
|
}
|
|
4289
4059
|
syncFieldValues(entryEl, annotations.fields, props);
|
|
4290
4060
|
if (getPuck) {
|
|
4291
|
-
wireFieldEditing(entryEl,
|
|
4061
|
+
wireFieldEditing(entryEl, annotations.fields, fieldWiring.current, {
|
|
4292
4062
|
componentId: id,
|
|
4293
4063
|
getPuck
|
|
4294
4064
|
});
|
|
4295
4065
|
}
|
|
4296
4066
|
});
|
|
4297
|
-
(0,
|
|
4067
|
+
(0, import_react24.useEffect)(
|
|
4298
4068
|
() => () => {
|
|
4299
4069
|
fieldWiring.current.forEach((cleanup) => cleanup());
|
|
4300
4070
|
fieldWiring.current.clear();
|
|
4301
4071
|
},
|
|
4302
4072
|
[]
|
|
4303
4073
|
);
|
|
4304
|
-
(0,
|
|
4074
|
+
(0, import_react24.useEffect)(() => {
|
|
4305
4075
|
if (!entryEl || !puck.isEditing) return;
|
|
4306
4076
|
for (const attr of Array.from(entryEl.attributes)) {
|
|
4307
4077
|
if ((attr.name === "data-puck-design" || attr.name.startsWith("data-puck-field-value-")) && !(attr.name in fieldValueAttrs)) {
|
|
@@ -4314,10 +4084,10 @@ function createDesignComponentConfig(registration) {
|
|
|
4314
4084
|
}
|
|
4315
4085
|
}
|
|
4316
4086
|
}, [entryEl, fieldValueAttrs]);
|
|
4317
|
-
const appliedArrayHtml = (0,
|
|
4318
|
-
const arrayItemWiring = (0,
|
|
4319
|
-
const appliedArrays = (0,
|
|
4320
|
-
(0,
|
|
4087
|
+
const appliedArrayHtml = (0, import_react24.useRef)(/* @__PURE__ */ new WeakMap());
|
|
4088
|
+
const arrayItemWiring = (0, import_react24.useRef)({});
|
|
4089
|
+
const appliedArrays = (0, import_react24.useRef)(null);
|
|
4090
|
+
(0, import_react24.useEffect)(() => {
|
|
4321
4091
|
if (!puck.isEditing || !entryEl || !getPuck) return;
|
|
4322
4092
|
if (appliedArrays.current?.el === entryEl && appliedArrays.current?.html === html && appliedArrays.current?.sig === arraySig) {
|
|
4323
4093
|
return;
|
|
@@ -4369,7 +4139,7 @@ function createDesignComponentConfig(registration) {
|
|
|
4369
4139
|
id,
|
|
4370
4140
|
getPuck
|
|
4371
4141
|
]);
|
|
4372
|
-
(0,
|
|
4142
|
+
(0, import_react24.useEffect)(
|
|
4373
4143
|
() => () => {
|
|
4374
4144
|
Object.values(arrayItemWiring.current).forEach(
|
|
4375
4145
|
(wiring) => wiring.forEach(({ cleanup }) => cleanup())
|
|
@@ -4377,7 +4147,7 @@ function createDesignComponentConfig(registration) {
|
|
|
4377
4147
|
},
|
|
4378
4148
|
[]
|
|
4379
4149
|
);
|
|
4380
|
-
(0,
|
|
4150
|
+
(0, import_react24.useEffect)(() => {
|
|
4381
4151
|
if (!script || !entryEl) return;
|
|
4382
4152
|
scriptRef.current?.remove();
|
|
4383
4153
|
const doc = entryEl.ownerDocument;
|
|
@@ -4395,7 +4165,7 @@ function createDesignComponentConfig(registration) {
|
|
|
4395
4165
|
for (const slot of annotations.slots) {
|
|
4396
4166
|
const Slot = props[slot.name];
|
|
4397
4167
|
if (typeof Slot === "function") {
|
|
4398
|
-
slotContent[slot.name] = /* @__PURE__ */ (0,
|
|
4168
|
+
slotContent[slot.name] = /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(
|
|
4399
4169
|
Slot,
|
|
4400
4170
|
{
|
|
4401
4171
|
style: slot.style ? parseStyleString(slot.style) : void 0,
|
|
@@ -4404,31 +4174,17 @@ function createDesignComponentConfig(registration) {
|
|
|
4404
4174
|
);
|
|
4405
4175
|
}
|
|
4406
4176
|
}
|
|
4407
|
-
|
|
4408
|
-
|
|
4409
|
-
|
|
4410
|
-
|
|
4411
|
-
return /* @__PURE__ */ (0, import_jsx_runtime32.jsxs)(import_jsx_runtime32.Fragment, { children: [
|
|
4412
|
-
styles && /* @__PURE__ */ (0, import_jsx_runtime32.jsx)("style", { children: styles }),
|
|
4413
|
-
style && /* @__PURE__ */ (0, import_jsx_runtime32.jsx)("style", { children: style }),
|
|
4414
|
-
/* @__PURE__ */ (0, import_jsx_runtime32.jsx)("div", { ref: setEntryEl, ...fieldValueAttrs, children: htmlToReactTree(patchedHtml, slotContent, fieldContent) })
|
|
4177
|
+
return /* @__PURE__ */ (0, import_jsx_runtime31.jsxs)(import_jsx_runtime31.Fragment, { children: [
|
|
4178
|
+
styles && /* @__PURE__ */ (0, import_jsx_runtime31.jsx)("style", { children: styles }),
|
|
4179
|
+
style && /* @__PURE__ */ (0, import_jsx_runtime31.jsx)("style", { children: style }),
|
|
4180
|
+
/* @__PURE__ */ (0, import_jsx_runtime31.jsx)("div", { ref: setEntryEl, ...fieldValueAttrs, children: htmlToReactTree(patchedHtml, slotContent) })
|
|
4415
4181
|
] });
|
|
4416
4182
|
}
|
|
4417
|
-
return /* @__PURE__ */ (0,
|
|
4418
|
-
styles && /* @__PURE__ */ (0,
|
|
4419
|
-
style && /* @__PURE__ */ (0,
|
|
4183
|
+
return /* @__PURE__ */ (0, import_jsx_runtime31.jsxs)(import_jsx_runtime31.Fragment, { children: [
|
|
4184
|
+
styles && /* @__PURE__ */ (0, import_jsx_runtime31.jsx)("style", { children: styles }),
|
|
4185
|
+
style && /* @__PURE__ */ (0, import_jsx_runtime31.jsx)("style", { children: style }),
|
|
4420
4186
|
editorEntryNode,
|
|
4421
|
-
entryEl &&
|
|
4422
|
-
FieldPortal,
|
|
4423
|
-
{
|
|
4424
|
-
entry: entryEl,
|
|
4425
|
-
html,
|
|
4426
|
-
selector,
|
|
4427
|
-
children: node
|
|
4428
|
-
},
|
|
4429
|
-
name2
|
|
4430
|
-
)),
|
|
4431
|
-
entryEl && annotations.slots.map((slot) => /* @__PURE__ */ (0, import_jsx_runtime32.jsx)(
|
|
4187
|
+
entryEl && annotations.slots.map((slot) => /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(
|
|
4432
4188
|
SlotPortal,
|
|
4433
4189
|
{
|
|
4434
4190
|
entry: entryEl,
|
|
@@ -4446,8 +4202,8 @@ function createDesignComponentConfig(registration) {
|
|
|
4446
4202
|
|
|
4447
4203
|
// src/lib/design/globals.tsx
|
|
4448
4204
|
init_react_import();
|
|
4449
|
-
var
|
|
4450
|
-
var
|
|
4205
|
+
var import_react25 = require("react");
|
|
4206
|
+
var import_jsx_runtime32 = require("react/jsx-runtime");
|
|
4451
4207
|
function getDynamicConfigGlobals(dynamicConfig) {
|
|
4452
4208
|
if (typeof dynamicConfig !== "object" || dynamicConfig === null) return {};
|
|
4453
4209
|
const { styles, script } = dynamicConfig;
|
|
@@ -4462,9 +4218,9 @@ function DesignGlobals({
|
|
|
4462
4218
|
script,
|
|
4463
4219
|
isEditing
|
|
4464
4220
|
}) {
|
|
4465
|
-
const scriptRef = (0,
|
|
4466
|
-
const hostRef = (0,
|
|
4467
|
-
(0,
|
|
4221
|
+
const scriptRef = (0, import_react25.useRef)(null);
|
|
4222
|
+
const hostRef = (0, import_react25.useRef)(null);
|
|
4223
|
+
(0, import_react25.useEffect)(() => {
|
|
4468
4224
|
if (!script) return;
|
|
4469
4225
|
scriptRef.current?.remove();
|
|
4470
4226
|
const doc = hostRef.current?.ownerDocument ?? document;
|
|
@@ -4477,10 +4233,10 @@ function DesignGlobals({
|
|
|
4477
4233
|
scriptRef.current = null;
|
|
4478
4234
|
};
|
|
4479
4235
|
}, [script]);
|
|
4480
|
-
return /* @__PURE__ */ (0,
|
|
4481
|
-
isEditing && /* @__PURE__ */ (0,
|
|
4482
|
-
styles && /* @__PURE__ */ (0,
|
|
4483
|
-
script && /* @__PURE__ */ (0,
|
|
4236
|
+
return /* @__PURE__ */ (0, import_jsx_runtime32.jsxs)(import_jsx_runtime32.Fragment, { children: [
|
|
4237
|
+
isEditing && /* @__PURE__ */ (0, import_jsx_runtime32.jsx)("style", { children: INLINE_EDIT_RESET }),
|
|
4238
|
+
styles && /* @__PURE__ */ (0, import_jsx_runtime32.jsx)("style", { children: styles }),
|
|
4239
|
+
script && /* @__PURE__ */ (0, import_jsx_runtime32.jsx)("div", { ref: hostRef, style: { display: "none" } })
|
|
4484
4240
|
] });
|
|
4485
4241
|
}
|
|
4486
4242
|
var WRAPPED = "__puckAiDesignGlobals";
|
|
@@ -4490,8 +4246,8 @@ function withDesignGlobals(root) {
|
|
|
4490
4246
|
const userRender = root?.render;
|
|
4491
4247
|
const render = (props) => {
|
|
4492
4248
|
const { styles, script } = getDynamicConfigGlobals(props._dynamicConfig);
|
|
4493
|
-
return /* @__PURE__ */ (0,
|
|
4494
|
-
/* @__PURE__ */ (0,
|
|
4249
|
+
return /* @__PURE__ */ (0, import_jsx_runtime32.jsxs)(import_jsx_runtime32.Fragment, { children: [
|
|
4250
|
+
/* @__PURE__ */ (0, import_jsx_runtime32.jsx)(
|
|
4495
4251
|
DesignGlobals,
|
|
4496
4252
|
{
|
|
4497
4253
|
styles,
|
|
@@ -4513,7 +4269,7 @@ function ensureDesignGlobalsRoot(config) {
|
|
|
4513
4269
|
}
|
|
4514
4270
|
|
|
4515
4271
|
// src/lib/design/runtime.tsx
|
|
4516
|
-
var
|
|
4272
|
+
var import_jsx_runtime33 = require("react/jsx-runtime");
|
|
4517
4273
|
var cachedFieldMetadata;
|
|
4518
4274
|
function detectFieldMetadata(config) {
|
|
4519
4275
|
for (const comp of Object.values(config.components)) {
|
|
@@ -4552,7 +4308,7 @@ function applyConfigFieldMetadata(config, dynamicComponents) {
|
|
|
4552
4308
|
var DESIGNED_CATEGORY = "dynamic";
|
|
4553
4309
|
var dynamicConfigRootField = {
|
|
4554
4310
|
type: "custom",
|
|
4555
|
-
render: () => /* @__PURE__ */ (0,
|
|
4311
|
+
render: () => /* @__PURE__ */ (0, import_jsx_runtime33.jsx)("div", {}),
|
|
4556
4312
|
ai: {
|
|
4557
4313
|
exclude: true
|
|
4558
4314
|
}
|
|
@@ -4612,7 +4368,7 @@ function syncDesignComponents(getPuck) {
|
|
|
4612
4368
|
ensureDynamicConfigField(config);
|
|
4613
4369
|
for (const [name, persistedReg] of Object.entries(persisted)) {
|
|
4614
4370
|
const prev = lastSynced.get(name);
|
|
4615
|
-
if (registrationStore.has(name) && (prev === persistedReg || registrationContentEqual(prev, persistedReg))) {
|
|
4371
|
+
if (registrationStore.has(name) && config.components[name] && (prev === persistedReg || registrationContentEqual(prev, persistedReg))) {
|
|
4616
4372
|
lastSynced.set(name, persistedReg);
|
|
4617
4373
|
continue;
|
|
4618
4374
|
}
|
|
@@ -4630,25 +4386,23 @@ function syncDesignComponents(getPuck) {
|
|
|
4630
4386
|
} else {
|
|
4631
4387
|
if (registration.label)
|
|
4632
4388
|
config.components[name].label = registration.label;
|
|
4389
|
+
if (isSettled) {
|
|
4390
|
+
config.components[name].defaultProps = {
|
|
4391
|
+
...registration.defaultProps ?? {}
|
|
4392
|
+
};
|
|
4393
|
+
}
|
|
4633
4394
|
}
|
|
4634
|
-
|
|
4635
|
-
...getSlotFields(registration.html ?? ""),
|
|
4636
|
-
...getTransformableFields(registration)
|
|
4637
|
-
};
|
|
4638
|
-
config.components[name].fields = fields;
|
|
4639
|
-
config.components[name].defaultProps = withFieldTypeDefaults(
|
|
4640
|
-
{ ...registration.defaultProps ?? {} },
|
|
4641
|
-
fields,
|
|
4642
|
-
name
|
|
4643
|
-
);
|
|
4395
|
+
config.components[name].fields = getSlotFields(registration.html ?? "");
|
|
4644
4396
|
}
|
|
4645
4397
|
let hasRemovals = false;
|
|
4646
4398
|
for (const [name] of registrationStore.getAll()) {
|
|
4647
4399
|
if (!(name in persisted)) {
|
|
4648
4400
|
registrationStore.delete(name);
|
|
4649
4401
|
lastSynced.delete(name);
|
|
4650
|
-
|
|
4651
|
-
|
|
4402
|
+
if (isDesignComponent(config.components[name])) {
|
|
4403
|
+
delete config.components[name];
|
|
4404
|
+
hasRemovals = true;
|
|
4405
|
+
}
|
|
4652
4406
|
}
|
|
4653
4407
|
}
|
|
4654
4408
|
if (createdSettled) {
|
|
@@ -4804,6 +4558,14 @@ var getDocumentSize = (root) => {
|
|
|
4804
4558
|
};
|
|
4805
4559
|
};
|
|
4806
4560
|
|
|
4561
|
+
// src/lib/screenshot-overflow.ts
|
|
4562
|
+
init_react_import();
|
|
4563
|
+
var applyBrowserOverflowStylesTo = (document2) => {
|
|
4564
|
+
for (const element of [document2.documentElement, document2.body]) {
|
|
4565
|
+
element?.style.setProperty("overflow", "visible", "important");
|
|
4566
|
+
}
|
|
4567
|
+
};
|
|
4568
|
+
|
|
4807
4569
|
// src/lib/capture-screenshot.ts
|
|
4808
4570
|
var editorOnlyClassPrefixes = ["_DraggableComponent--hover", "_ActionBar"];
|
|
4809
4571
|
var releaseCanvas = (canvas) => {
|
|
@@ -4814,14 +4576,14 @@ var drawScaled = (source, ratio) => {
|
|
|
4814
4576
|
const target = document.createElement("canvas");
|
|
4815
4577
|
target.width = scaleDimension(source.width, ratio);
|
|
4816
4578
|
target.height = scaleDimension(source.height, ratio);
|
|
4817
|
-
const
|
|
4818
|
-
if (!
|
|
4579
|
+
const ctx = target.getContext("2d");
|
|
4580
|
+
if (!ctx) {
|
|
4819
4581
|
releaseCanvas(target);
|
|
4820
4582
|
return source;
|
|
4821
4583
|
}
|
|
4822
|
-
|
|
4823
|
-
|
|
4824
|
-
|
|
4584
|
+
ctx.imageSmoothingEnabled = true;
|
|
4585
|
+
ctx.imageSmoothingQuality = "high";
|
|
4586
|
+
ctx.drawImage(source, 0, 0, target.width, target.height);
|
|
4825
4587
|
return target;
|
|
4826
4588
|
};
|
|
4827
4589
|
var fitCanvas = (canvas) => {
|
|
@@ -4872,6 +4634,7 @@ var captureScreenshot = async (root, { scale = CAPTURE_SCALE, quality = 0.8, wid
|
|
|
4872
4634
|
allowTaint: false,
|
|
4873
4635
|
useCORS: true,
|
|
4874
4636
|
scrollY: 0,
|
|
4637
|
+
onclone: applyBrowserOverflowStylesTo,
|
|
4875
4638
|
ignoreElements: (el) => Array.from(el.classList).some(
|
|
4876
4639
|
(c) => editorOnlyClassPrefixes.some((prefix) => c.startsWith(prefix))
|
|
4877
4640
|
)
|
|
@@ -4901,12 +4664,12 @@ async function postClientToolResponse(host, body) {
|
|
|
4901
4664
|
}
|
|
4902
4665
|
|
|
4903
4666
|
// src/components/Chat/index.tsx
|
|
4904
|
-
var
|
|
4667
|
+
var import_jsx_runtime34 = require("react/jsx-runtime");
|
|
4905
4668
|
var q = (0, import_qler.default)();
|
|
4906
4669
|
var DEFAULT_API_VERSION = "v2";
|
|
4907
4670
|
var BUILD_OP_DEBOUNCE_MS = 1e3 / 60;
|
|
4908
4671
|
var CLIENT_TOOL_ENDPOINT_UNAVAILABLE_ERROR_MESSAGE = "Unable to verify the page data. Please enable the `/chat/tool` endpoint on the server and try again.";
|
|
4909
|
-
var PLUGIN_AI_VERSION = true ? "0.9.0-canary.
|
|
4672
|
+
var PLUGIN_AI_VERSION = true ? "0.9.0-canary.53ee4e95" : "unknown";
|
|
4910
4673
|
var BENCHMARK = false;
|
|
4911
4674
|
var prefixedUlid = (prefix = "") => `${prefix ? `${prefix}_` : ""}${(0, import_ulid.ulid)()}`;
|
|
4912
4675
|
var getClassName18 = getClassNameFactory("Chat", styles_module_default);
|
|
@@ -4929,32 +4692,32 @@ function Chat2(props) {
|
|
|
4929
4692
|
} = chat ?? {};
|
|
4930
4693
|
const puckDispatch = usePuck((s) => s.dispatch);
|
|
4931
4694
|
const getPuck = (0, import_core5.useGetPuck)();
|
|
4932
|
-
const localChatId = (0,
|
|
4933
|
-
const inputRef = (0,
|
|
4934
|
-
const pluginRef = (0,
|
|
4935
|
-
const [mode, setMode] = (0,
|
|
4936
|
-
const modeRef = (0,
|
|
4695
|
+
const localChatId = (0, import_react27.useRef)("");
|
|
4696
|
+
const inputRef = (0, import_react27.useRef)(null);
|
|
4697
|
+
const pluginRef = (0, import_react27.useRef)(null);
|
|
4698
|
+
const [mode, setMode] = (0, import_react27.useState)(defaultMode);
|
|
4699
|
+
const modeRef = (0, import_react27.useRef)(mode);
|
|
4937
4700
|
const designModeVisible = typeof designMode === "boolean" ? designMode : designMode.visible ?? false;
|
|
4938
|
-
(0,
|
|
4701
|
+
(0, import_react27.useEffect)(() => {
|
|
4939
4702
|
modeRef.current = mode;
|
|
4940
4703
|
}, [mode]);
|
|
4941
4704
|
const puckData = usePuck((s) => s.appState.data);
|
|
4942
|
-
(0,
|
|
4705
|
+
(0, import_react27.useEffect)(() => {
|
|
4943
4706
|
syncDesignComponents(getPuck);
|
|
4944
4707
|
}, [puckData, getPuck]);
|
|
4945
|
-
const [error, setError] = (0,
|
|
4946
|
-
const [userError, setUserError] = (0,
|
|
4947
|
-
const clientToolEndpointUnavailableRef = (0,
|
|
4948
|
-
const stopChatRef = (0,
|
|
4949
|
-
const [composerAttachments, setComposerAttachments] = (0,
|
|
4950
|
-
const removedAttachmentClientIdsRef = (0,
|
|
4951
|
-
const uploadControllersRef = (0,
|
|
4952
|
-
const pendingBuildOpsRef = (0,
|
|
4953
|
-
const lastStreamActivityRef = (0,
|
|
4954
|
-
const hiddenSinceRef = (0,
|
|
4955
|
-
const [toolStatus, setToolStatus] = (0,
|
|
4956
|
-
const [subagentState, setSubagentState] = (0,
|
|
4957
|
-
const attachmentConfig = (0,
|
|
4708
|
+
const [error, setError] = (0, import_react27.useState)();
|
|
4709
|
+
const [userError, setUserError] = (0, import_react27.useState)();
|
|
4710
|
+
const clientToolEndpointUnavailableRef = (0, import_react27.useRef)(false);
|
|
4711
|
+
const stopChatRef = (0, import_react27.useRef)(null);
|
|
4712
|
+
const [composerAttachments, setComposerAttachments] = (0, import_react27.useState)([]);
|
|
4713
|
+
const removedAttachmentClientIdsRef = (0, import_react27.useRef)(/* @__PURE__ */ new Set());
|
|
4714
|
+
const uploadControllersRef = (0, import_react27.useRef)(/* @__PURE__ */ new Map());
|
|
4715
|
+
const pendingBuildOpsRef = (0, import_react27.useRef)([]);
|
|
4716
|
+
const lastStreamActivityRef = (0, import_react27.useRef)(0);
|
|
4717
|
+
const hiddenSinceRef = (0, import_react27.useRef)(null);
|
|
4718
|
+
const [toolStatus, setToolStatus] = (0, import_react27.useState)({});
|
|
4719
|
+
const [subagentState, setSubagentState] = (0, import_react27.useState)({});
|
|
4720
|
+
const attachmentConfig = (0, import_react27.useMemo)(
|
|
4958
4721
|
() => ({
|
|
4959
4722
|
accept: attachments?.accept ?? defaultAttachmentAccept,
|
|
4960
4723
|
enabled: attachments?.enabled ?? true,
|
|
@@ -4964,14 +4727,14 @@ function Chat2(props) {
|
|
|
4964
4727
|
}),
|
|
4965
4728
|
[attachments, host]
|
|
4966
4729
|
);
|
|
4967
|
-
(0,
|
|
4730
|
+
(0, import_react27.useEffect)(
|
|
4968
4731
|
() => () => {
|
|
4969
4732
|
uploadControllersRef.current.forEach((controller) => controller.abort());
|
|
4970
4733
|
uploadControllersRef.current.clear();
|
|
4971
4734
|
},
|
|
4972
4735
|
[]
|
|
4973
4736
|
);
|
|
4974
|
-
const deleteAttachment = (0,
|
|
4737
|
+
const deleteAttachment = (0, import_react27.useCallback)(
|
|
4975
4738
|
async (attachmentId) => {
|
|
4976
4739
|
try {
|
|
4977
4740
|
await fetch(`${attachmentConfig.endpoint}/${attachmentId}`, {
|
|
@@ -4983,7 +4746,7 @@ function Chat2(props) {
|
|
|
4983
4746
|
},
|
|
4984
4747
|
[attachmentConfig.endpoint]
|
|
4985
4748
|
);
|
|
4986
|
-
const uploadScreenshot = (0,
|
|
4749
|
+
const uploadScreenshot = (0, import_react27.useCallback)(
|
|
4987
4750
|
async (width, bucketUrl) => {
|
|
4988
4751
|
try {
|
|
4989
4752
|
const iframeDocument = document?.getElementById("preview-frame")?.contentDocument?.documentElement ?? null;
|
|
@@ -5038,14 +4801,14 @@ function Chat2(props) {
|
|
|
5038
4801
|
BUILD_OP_DEBOUNCE_MS,
|
|
5039
4802
|
{ maxWait: BUILD_OP_DEBOUNCE_MS }
|
|
5040
4803
|
);
|
|
5041
|
-
const queueBuildOp = (0,
|
|
4804
|
+
const queueBuildOp = (0, import_react27.useCallback)(
|
|
5042
4805
|
(operation) => {
|
|
5043
4806
|
pendingBuildOpsRef.current.push(operation);
|
|
5044
4807
|
debouncedFlushBuildOps();
|
|
5045
4808
|
},
|
|
5046
4809
|
[debouncedFlushBuildOps]
|
|
5047
4810
|
);
|
|
5048
|
-
const handleClientToolEndpointUnavailable = (0,
|
|
4811
|
+
const handleClientToolEndpointUnavailable = (0, import_react27.useCallback)(() => {
|
|
5049
4812
|
if (clientToolEndpointUnavailableRef.current) return;
|
|
5050
4813
|
clientToolEndpointUnavailableRef.current = true;
|
|
5051
4814
|
setError(CLIENT_TOOL_ENDPOINT_UNAVAILABLE_ERROR_MESSAGE);
|
|
@@ -5069,7 +4832,7 @@ function Chat2(props) {
|
|
|
5069
4832
|
});
|
|
5070
4833
|
stopChatRef.current?.();
|
|
5071
4834
|
}, []);
|
|
5072
|
-
const sendClientToolResponse = (0,
|
|
4835
|
+
const sendClientToolResponse = (0, import_react27.useCallback)(
|
|
5073
4836
|
async (body) => {
|
|
5074
4837
|
try {
|
|
5075
4838
|
await postClientToolResponse(host, body);
|
|
@@ -5079,7 +4842,7 @@ function Chat2(props) {
|
|
|
5079
4842
|
},
|
|
5080
4843
|
[handleClientToolEndpointUnavailable, host]
|
|
5081
4844
|
);
|
|
5082
|
-
const processData = (0,
|
|
4845
|
+
const processData = (0, import_react27.useCallback)(
|
|
5083
4846
|
(dataPart) => {
|
|
5084
4847
|
lastStreamActivityRef.current = Date.now();
|
|
5085
4848
|
switch (dataPart.type) {
|
|
@@ -5108,12 +4871,14 @@ function Chat2(props) {
|
|
|
5108
4871
|
}
|
|
5109
4872
|
case "data-client-request": {
|
|
5110
4873
|
const { requestId, action } = dataPart.data;
|
|
4874
|
+
const chatId = localChatId.current || void 0;
|
|
5111
4875
|
if (action === "getPageData") {
|
|
5112
4876
|
debouncedFlushBuildOps.flush();
|
|
5113
4877
|
q.wait().then(() => {
|
|
5114
4878
|
const { appState } = getPuck();
|
|
5115
4879
|
return sendClientToolResponse({
|
|
5116
4880
|
id: requestId,
|
|
4881
|
+
chatId,
|
|
5117
4882
|
responses: [{ action, output: appState.data }]
|
|
5118
4883
|
});
|
|
5119
4884
|
}).catch((e) => {
|
|
@@ -5143,12 +4908,14 @@ function Chat2(props) {
|
|
|
5143
4908
|
}
|
|
5144
4909
|
return sendClientToolResponse({
|
|
5145
4910
|
id: requestId,
|
|
4911
|
+
chatId,
|
|
5146
4912
|
responses: [{ action, output: { sizeBytes: blob.size } }]
|
|
5147
4913
|
});
|
|
5148
4914
|
}).catch((e) => {
|
|
5149
4915
|
console.error("Failed to respond to client request:", e);
|
|
5150
4916
|
return sendClientToolResponse({
|
|
5151
4917
|
id: requestId,
|
|
4918
|
+
chatId,
|
|
5152
4919
|
responses: [{ action, output: { sizeBytes: 0 } }]
|
|
5153
4920
|
});
|
|
5154
4921
|
});
|
|
@@ -5238,7 +5005,6 @@ function Chat2(props) {
|
|
|
5238
5005
|
messages: opts.messages,
|
|
5239
5006
|
pageData: appState.data,
|
|
5240
5007
|
config: configWithRoot,
|
|
5241
|
-
fieldTypes: toWireFieldTypes(getFieldTypes()),
|
|
5242
5008
|
mode: modeRef.current
|
|
5243
5009
|
}
|
|
5244
5010
|
};
|
|
@@ -5287,21 +5053,21 @@ function Chat2(props) {
|
|
|
5287
5053
|
});
|
|
5288
5054
|
}
|
|
5289
5055
|
});
|
|
5290
|
-
(0,
|
|
5056
|
+
(0, import_react27.useEffect)(() => {
|
|
5291
5057
|
stopChatRef.current = stop;
|
|
5292
5058
|
return () => {
|
|
5293
5059
|
stopChatRef.current = null;
|
|
5294
5060
|
stop();
|
|
5295
5061
|
};
|
|
5296
5062
|
}, [stop]);
|
|
5297
|
-
const statusRef = (0,
|
|
5298
|
-
(0,
|
|
5063
|
+
const statusRef = (0, import_react27.useRef)(status);
|
|
5064
|
+
(0, import_react27.useEffect)(() => {
|
|
5299
5065
|
statusRef.current = status;
|
|
5300
5066
|
}, [status]);
|
|
5301
|
-
(0,
|
|
5067
|
+
(0, import_react27.useEffect)(() => {
|
|
5302
5068
|
lastStreamActivityRef.current = Date.now();
|
|
5303
5069
|
}, [messages]);
|
|
5304
|
-
(0,
|
|
5070
|
+
(0, import_react27.useEffect)(() => {
|
|
5305
5071
|
const FROZEN_HIDDEN_MS = 3 * 6e4;
|
|
5306
5072
|
const RESUME_GRACE_MS = 12e3;
|
|
5307
5073
|
const isStreaming = () => statusRef.current === "streaming" || statusRef.current === "submitted";
|
|
@@ -5344,12 +5110,12 @@ function Chat2(props) {
|
|
|
5344
5110
|
if (graceTimer) clearTimeout(graceTimer);
|
|
5345
5111
|
};
|
|
5346
5112
|
}, [stop]);
|
|
5347
|
-
const [forcedStatus, setForcedStatus] = (0,
|
|
5348
|
-
const resolvedStatus = (0,
|
|
5113
|
+
const [forcedStatus, setForcedStatus] = (0, import_react27.useState)();
|
|
5114
|
+
const resolvedStatus = (0, import_react27.useMemo)(
|
|
5349
5115
|
() => forcedStatus ?? status,
|
|
5350
5116
|
[status, forcedStatus]
|
|
5351
5117
|
);
|
|
5352
|
-
(0,
|
|
5118
|
+
(0, import_react27.useEffect)(() => {
|
|
5353
5119
|
if (!scrollTrackingId) return;
|
|
5354
5120
|
dispatchScrollTrackingEvent({
|
|
5355
5121
|
id: scrollTrackingId,
|
|
@@ -5362,7 +5128,7 @@ function Chat2(props) {
|
|
|
5362
5128
|
});
|
|
5363
5129
|
};
|
|
5364
5130
|
}, [resolvedStatus, scrollTrackingId]);
|
|
5365
|
-
(0,
|
|
5131
|
+
(0, import_react27.useEffect)(() => {
|
|
5366
5132
|
window.__PUCK_AI = {
|
|
5367
5133
|
processData,
|
|
5368
5134
|
setMessages,
|
|
@@ -5573,7 +5339,7 @@ function Chat2(props) {
|
|
|
5573
5339
|
if (!target?.attachmentId) return;
|
|
5574
5340
|
await deleteAttachment(target.attachmentId);
|
|
5575
5341
|
};
|
|
5576
|
-
const messagesWithStatuses = (0,
|
|
5342
|
+
const messagesWithStatuses = (0, import_react27.useMemo)(() => {
|
|
5577
5343
|
return messages.map((msg) => {
|
|
5578
5344
|
return {
|
|
5579
5345
|
...msg,
|
|
@@ -5586,13 +5352,13 @@ function Chat2(props) {
|
|
|
5586
5352
|
};
|
|
5587
5353
|
});
|
|
5588
5354
|
}, [messages, toolStatus]);
|
|
5589
|
-
return /* @__PURE__ */ (0,
|
|
5355
|
+
return /* @__PURE__ */ (0, import_jsx_runtime34.jsx)("div", { className: getClassName18(), ref: pluginRef, children: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(HostProvider, { value: host, children: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(ToolStatusProvider, { value: toolStatus, children: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(SubagentStateProvider, { value: subagentState, children: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
|
|
5590
5356
|
ChatBody,
|
|
5591
5357
|
{
|
|
5592
5358
|
messages: messagesWithStatuses,
|
|
5593
5359
|
onFileDrop: attachmentConfig.enabled ? handleFiles : void 0,
|
|
5594
|
-
actions: /* @__PURE__ */ (0,
|
|
5595
|
-
attachmentConfig.enabled ? /* @__PURE__ */ (0,
|
|
5360
|
+
actions: /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)(import_jsx_runtime34.Fragment, { children: [
|
|
5361
|
+
attachmentConfig.enabled ? /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
|
|
5596
5362
|
AttachmentComposer,
|
|
5597
5363
|
{
|
|
5598
5364
|
accept: attachmentConfig.accept,
|
|
@@ -5605,7 +5371,7 @@ function Chat2(props) {
|
|
|
5605
5371
|
typeof chatActions === "function" ? chatActions({
|
|
5606
5372
|
disabled: resolvedStatus === "submitted" || resolvedStatus === "streaming"
|
|
5607
5373
|
}) : chatActions,
|
|
5608
|
-
designModeVisible ? /* @__PURE__ */ (0,
|
|
5374
|
+
designModeVisible ? /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
|
|
5609
5375
|
DesignModeToggle,
|
|
5610
5376
|
{
|
|
5611
5377
|
active: mode === "design",
|
|
@@ -5622,7 +5388,7 @@ function Chat2(props) {
|
|
|
5622
5388
|
inputRef,
|
|
5623
5389
|
status: resolvedStatus,
|
|
5624
5390
|
examplePrompts: examplePrompts?.map(
|
|
5625
|
-
({ label, href, onClick }) => /* @__PURE__ */ (0,
|
|
5391
|
+
({ label, href, onClick }) => /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
|
|
5626
5392
|
ExamplePrompt,
|
|
5627
5393
|
{
|
|
5628
5394
|
label,
|
|
@@ -5641,7 +5407,7 @@ function Chat2(props) {
|
|
|
5641
5407
|
},
|
|
5642
5408
|
userError,
|
|
5643
5409
|
onDismissUserError: () => setUserError(""),
|
|
5644
|
-
children: placeholder ?? /* @__PURE__ */ (0,
|
|
5410
|
+
children: placeholder ?? /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
|
|
5645
5411
|
Placeholder,
|
|
5646
5412
|
{
|
|
5647
5413
|
dispatch: puckDispatch,
|
|
@@ -5758,10 +5524,10 @@ function AttachmentComposer({
|
|
|
5758
5524
|
maxFiles,
|
|
5759
5525
|
onChange
|
|
5760
5526
|
}) {
|
|
5761
|
-
const id = (0,
|
|
5762
|
-
const inputId = (0,
|
|
5763
|
-
return /* @__PURE__ */ (0,
|
|
5764
|
-
/* @__PURE__ */ (0,
|
|
5527
|
+
const id = (0, import_react27.useId)();
|
|
5528
|
+
const inputId = (0, import_react27.useMemo)(() => `attachment-input-${id}`, []);
|
|
5529
|
+
return /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)("div", { className: getClassName18("attachmentControls"), children: [
|
|
5530
|
+
/* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
|
|
5765
5531
|
"input",
|
|
5766
5532
|
{
|
|
5767
5533
|
accept: accept.join(","),
|
|
@@ -5773,7 +5539,7 @@ function AttachmentComposer({
|
|
|
5773
5539
|
type: "file"
|
|
5774
5540
|
}
|
|
5775
5541
|
),
|
|
5776
|
-
/* @__PURE__ */ (0,
|
|
5542
|
+
/* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
|
|
5777
5543
|
"button",
|
|
5778
5544
|
{
|
|
5779
5545
|
"aria-label": "Attach files",
|
|
@@ -5782,7 +5548,7 @@ function AttachmentComposer({
|
|
|
5782
5548
|
onClick: () => document.getElementById(inputId)?.click(),
|
|
5783
5549
|
title: "Attach files",
|
|
5784
5550
|
type: "button",
|
|
5785
|
-
children: /* @__PURE__ */ (0,
|
|
5551
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(Paperclip, { size: 14 })
|
|
5786
5552
|
}
|
|
5787
5553
|
)
|
|
5788
5554
|
] });
|
|
@@ -5805,12 +5571,12 @@ function Placeholder({
|
|
|
5805
5571
|
}
|
|
5806
5572
|
}, 10);
|
|
5807
5573
|
};
|
|
5808
|
-
return /* @__PURE__ */ (0,
|
|
5809
|
-
/* @__PURE__ */ (0,
|
|
5810
|
-
/* @__PURE__ */ (0,
|
|
5811
|
-
/* @__PURE__ */ (0,
|
|
5812
|
-
/* @__PURE__ */ (0,
|
|
5813
|
-
/* @__PURE__ */ (0,
|
|
5574
|
+
return /* @__PURE__ */ (0, import_jsx_runtime34.jsxs)("div", { className: getClassName18("placeholder"), children: [
|
|
5575
|
+
/* @__PURE__ */ (0, import_jsx_runtime34.jsx)("span", { className: getClassName18("placeholderIcon"), children: /* @__PURE__ */ (0, import_jsx_runtime34.jsx)(Sparkles, { "aria-hidden": "true", size: 28 }) }),
|
|
5576
|
+
/* @__PURE__ */ (0, import_jsx_runtime34.jsx)("strong", { className: getClassName18("placeholderTitle"), children: "Build with AI" }),
|
|
5577
|
+
/* @__PURE__ */ (0, import_jsx_runtime34.jsx)("span", { className: getClassName18("placeholderDescription"), children: "Describe what you want to create or change." }),
|
|
5578
|
+
/* @__PURE__ */ (0, import_jsx_runtime34.jsxs)("div", { className: getClassName18("actions"), children: [
|
|
5579
|
+
/* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
|
|
5814
5580
|
"button",
|
|
5815
5581
|
{
|
|
5816
5582
|
className: getClassName18("action"),
|
|
@@ -5819,7 +5585,7 @@ function Placeholder({
|
|
|
5819
5585
|
children: "Write a prompt"
|
|
5820
5586
|
}
|
|
5821
5587
|
),
|
|
5822
|
-
/* @__PURE__ */ (0,
|
|
5588
|
+
/* @__PURE__ */ (0, import_jsx_runtime34.jsx)(
|
|
5823
5589
|
"button",
|
|
5824
5590
|
{
|
|
5825
5591
|
className: getClassName18("actionOutlined"),
|
|
@@ -5859,7 +5625,7 @@ function isScrolledIntoView(el) {
|
|
|
5859
5625
|
|
|
5860
5626
|
// src/components/ScrollTracking/ScrollTracking.tsx
|
|
5861
5627
|
init_react_import();
|
|
5862
|
-
var
|
|
5628
|
+
var import_react29 = require("react");
|
|
5863
5629
|
|
|
5864
5630
|
// src/lib/scroll-into-view-local.ts
|
|
5865
5631
|
init_react_import();
|
|
@@ -5882,9 +5648,9 @@ function scrollIntoViewLocal(el, win, behavior = "smooth") {
|
|
|
5882
5648
|
|
|
5883
5649
|
// src/lib/use-frame-mutation-observer.ts
|
|
5884
5650
|
init_react_import();
|
|
5885
|
-
var
|
|
5651
|
+
var import_react28 = require("react");
|
|
5886
5652
|
function useFrameMutationObserver(callback) {
|
|
5887
|
-
return (0,
|
|
5653
|
+
return (0, import_react28.useCallback)(() => {
|
|
5888
5654
|
const frame = document?.getElementById(
|
|
5889
5655
|
"preview-frame"
|
|
5890
5656
|
);
|
|
@@ -5929,9 +5695,9 @@ var ScrollTracking = ({
|
|
|
5929
5695
|
children,
|
|
5930
5696
|
trackingId
|
|
5931
5697
|
}) => {
|
|
5932
|
-
const followedRefs = (0,
|
|
5933
|
-
const enabledRef = (0,
|
|
5934
|
-
(0,
|
|
5698
|
+
const followedRefs = (0, import_react29.useRef)([]);
|
|
5699
|
+
const enabledRef = (0, import_react29.useRef)(false);
|
|
5700
|
+
(0, import_react29.useEffect)(() => {
|
|
5935
5701
|
return subscribeToScrollTrackingEvents(({ id, enabled }) => {
|
|
5936
5702
|
if (id !== trackingId) return;
|
|
5937
5703
|
enabledRef.current = enabled;
|
|
@@ -5950,7 +5716,7 @@ var ScrollTracking = ({
|
|
|
5950
5716
|
});
|
|
5951
5717
|
}
|
|
5952
5718
|
});
|
|
5953
|
-
(0,
|
|
5719
|
+
(0, import_react29.useEffect)(() => {
|
|
5954
5720
|
follow();
|
|
5955
5721
|
}, [follow]);
|
|
5956
5722
|
return children;
|
|
@@ -5963,16 +5729,16 @@ var import_core7 = require("@puckeditor/core");
|
|
|
5963
5729
|
// src/components/ManageComponents/index.tsx
|
|
5964
5730
|
init_react_import();
|
|
5965
5731
|
var import_core6 = require("@puckeditor/core");
|
|
5966
|
-
var
|
|
5732
|
+
var import_react30 = require("react");
|
|
5967
5733
|
|
|
5968
5734
|
// css-module:/home/runner/work/platform/platform/packages/plugin-ai/src/components/ManageComponents/styles.module.css#css-module
|
|
5969
5735
|
init_react_import();
|
|
5970
5736
|
var styles_module_default10 = { "ManageComponents-cta": "_ManageComponents-cta_xifz3_1", "ManageComponents-list": "_ManageComponents-list_xifz3_22", "ManageComponents-item": "_ManageComponents-item_xifz3_29", "ManageComponents-delete": "_ManageComponents-delete_xifz3_41", "ManageComponents-empty": "_ManageComponents-empty_xifz3_57" };
|
|
5971
5737
|
|
|
5972
5738
|
// src/components/ManageComponents/index.tsx
|
|
5973
|
-
var
|
|
5739
|
+
var import_jsx_runtime35 = require("react/jsx-runtime");
|
|
5974
5740
|
var cx10 = getClassNameFactory2("ManageComponents", styles_module_default10);
|
|
5975
|
-
var useRegistrations = () => (0,
|
|
5741
|
+
var useRegistrations = () => (0, import_react30.useSyncExternalStore)(
|
|
5976
5742
|
registrationStore.subscribe,
|
|
5977
5743
|
() => registrationStore.getAll(),
|
|
5978
5744
|
() => registrationStore.getAll()
|
|
@@ -5980,9 +5746,9 @@ var useRegistrations = () => (0, import_react31.useSyncExternalStore)(
|
|
|
5980
5746
|
function ManageModalContent({ onClose }) {
|
|
5981
5747
|
const getPuck = (0, import_core6.useGetPuck)();
|
|
5982
5748
|
const { visible, setVisible } = useModal();
|
|
5983
|
-
const [confirmTarget, setConfirmTarget] = (0,
|
|
5749
|
+
const [confirmTarget, setConfirmTarget] = (0, import_react30.useState)(null);
|
|
5984
5750
|
const entries = useRegistrations();
|
|
5985
|
-
(0,
|
|
5751
|
+
(0, import_react30.useEffect)(() => {
|
|
5986
5752
|
if (!visible) onClose();
|
|
5987
5753
|
}, [visible, onClose]);
|
|
5988
5754
|
const handleDelete = (name) => {
|
|
@@ -5993,14 +5759,14 @@ function ManageModalContent({ onClose }) {
|
|
|
5993
5759
|
}
|
|
5994
5760
|
};
|
|
5995
5761
|
if (confirmTarget) {
|
|
5996
|
-
return /* @__PURE__ */ (0,
|
|
5762
|
+
return /* @__PURE__ */ (0, import_jsx_runtime35.jsx)(
|
|
5997
5763
|
ActionModal,
|
|
5998
5764
|
{
|
|
5999
5765
|
title: "Delete component",
|
|
6000
5766
|
hideButton: true,
|
|
6001
|
-
actions: /* @__PURE__ */ (0,
|
|
6002
|
-
/* @__PURE__ */ (0,
|
|
6003
|
-
/* @__PURE__ */ (0,
|
|
5767
|
+
actions: /* @__PURE__ */ (0, import_jsx_runtime35.jsxs)(Inline, { children: [
|
|
5768
|
+
/* @__PURE__ */ (0, import_jsx_runtime35.jsx)(Button, { variant: "secondary", onClick: () => setConfirmTarget(null), children: "Cancel" }),
|
|
5769
|
+
/* @__PURE__ */ (0, import_jsx_runtime35.jsx)(
|
|
6004
5770
|
Button,
|
|
6005
5771
|
{
|
|
6006
5772
|
variant: "danger",
|
|
@@ -6009,44 +5775,44 @@ function ManageModalContent({ onClose }) {
|
|
|
6009
5775
|
}
|
|
6010
5776
|
)
|
|
6011
5777
|
] }),
|
|
6012
|
-
children: /* @__PURE__ */ (0,
|
|
5778
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime35.jsxs)("p", { children: [
|
|
6013
5779
|
"Are you sure you want to delete ",
|
|
6014
|
-
/* @__PURE__ */ (0,
|
|
5780
|
+
/* @__PURE__ */ (0, import_jsx_runtime35.jsx)("b", { children: confirmTarget.label }),
|
|
6015
5781
|
"?"
|
|
6016
5782
|
] })
|
|
6017
5783
|
}
|
|
6018
5784
|
);
|
|
6019
5785
|
}
|
|
6020
|
-
return /* @__PURE__ */ (0,
|
|
6021
|
-
entries.map(([name, reg]) => /* @__PURE__ */ (0,
|
|
6022
|
-
/* @__PURE__ */ (0,
|
|
6023
|
-
/* @__PURE__ */ (0,
|
|
5786
|
+
return /* @__PURE__ */ (0, import_jsx_runtime35.jsx)(ActionModal, { title: "Manage components", hideButton: true, children: /* @__PURE__ */ (0, import_jsx_runtime35.jsxs)("div", { className: cx10("list"), children: [
|
|
5787
|
+
entries.map(([name, reg]) => /* @__PURE__ */ (0, import_jsx_runtime35.jsxs)("div", { className: cx10("item"), children: [
|
|
5788
|
+
/* @__PURE__ */ (0, import_jsx_runtime35.jsx)("span", { className: cx10("itemName"), children: reg.label || name }),
|
|
5789
|
+
/* @__PURE__ */ (0, import_jsx_runtime35.jsxs)(
|
|
6024
5790
|
"button",
|
|
6025
5791
|
{
|
|
6026
5792
|
className: cx10("delete"),
|
|
6027
5793
|
onClick: () => setConfirmTarget({ name, label: reg.label || name }),
|
|
6028
5794
|
type: "button",
|
|
6029
5795
|
children: [
|
|
6030
|
-
/* @__PURE__ */ (0,
|
|
5796
|
+
/* @__PURE__ */ (0, import_jsx_runtime35.jsx)(Trash2, { size: 12 }),
|
|
6031
5797
|
"Delete"
|
|
6032
5798
|
]
|
|
6033
5799
|
}
|
|
6034
5800
|
)
|
|
6035
5801
|
] }, name)),
|
|
6036
|
-
entries.length === 0 && /* @__PURE__ */ (0,
|
|
5802
|
+
entries.length === 0 && /* @__PURE__ */ (0, import_jsx_runtime35.jsx)("div", { className: cx10("empty"), children: "No dynamic components" })
|
|
6037
5803
|
] }) });
|
|
6038
5804
|
}
|
|
6039
5805
|
function ManageComponentsCta() {
|
|
6040
|
-
const [open, setOpen] = (0,
|
|
5806
|
+
const [open, setOpen] = (0, import_react30.useState)(false);
|
|
6041
5807
|
const entries = useRegistrations();
|
|
6042
|
-
const handleClose = (0,
|
|
5808
|
+
const handleClose = (0, import_react30.useCallback)(() => setOpen(false), []);
|
|
6043
5809
|
if (entries.length === 0) return null;
|
|
6044
|
-
return /* @__PURE__ */ (0,
|
|
6045
|
-
/* @__PURE__ */ (0,
|
|
6046
|
-
/* @__PURE__ */ (0,
|
|
5810
|
+
return /* @__PURE__ */ (0, import_jsx_runtime35.jsxs)(import_jsx_runtime35.Fragment, { children: [
|
|
5811
|
+
/* @__PURE__ */ (0, import_jsx_runtime35.jsxs)("button", { className: cx10("cta"), onClick: () => setOpen(true), type: "button", children: [
|
|
5812
|
+
/* @__PURE__ */ (0, import_jsx_runtime35.jsx)(Settings, { size: 14 }),
|
|
6047
5813
|
"Manage components"
|
|
6048
5814
|
] }),
|
|
6049
|
-
open && /* @__PURE__ */ (0,
|
|
5815
|
+
open && /* @__PURE__ */ (0, import_jsx_runtime35.jsx)(ModalProvider, { defaultVisible: true, children: /* @__PURE__ */ (0, import_jsx_runtime35.jsx)(ManageModalContent, { onClose: handleClose }) })
|
|
6050
5816
|
] });
|
|
6051
5817
|
}
|
|
6052
5818
|
|
|
@@ -6055,22 +5821,22 @@ init_react_import();
|
|
|
6055
5821
|
var styles_module_default11 = { "Drawer--empty": "_Drawer--empty_8e8cs_1" };
|
|
6056
5822
|
|
|
6057
5823
|
// src/components/Drawer/index.tsx
|
|
6058
|
-
var
|
|
5824
|
+
var import_jsx_runtime36 = require("react/jsx-runtime");
|
|
6059
5825
|
var usePuck2 = (0, import_core7.createUsePuck)();
|
|
6060
5826
|
var cx11 = get_class_name_factory_default("Drawer", styles_module_default11);
|
|
6061
5827
|
var createDrawer = (designModeVisible) => function Drawer({ children }) {
|
|
6062
5828
|
const config = usePuck2((s) => s.config);
|
|
6063
5829
|
if (Object.keys(config.components).length === 0) {
|
|
6064
|
-
return /* @__PURE__ */ (0,
|
|
5830
|
+
return /* @__PURE__ */ (0, import_jsx_runtime36.jsx)("div", { className: cx11({ empty: true }), children: "No blocks" });
|
|
6065
5831
|
}
|
|
6066
|
-
return /* @__PURE__ */ (0,
|
|
5832
|
+
return /* @__PURE__ */ (0, import_jsx_runtime36.jsxs)("div", { className: cx11(), children: [
|
|
6067
5833
|
children,
|
|
6068
|
-
designModeVisible && /* @__PURE__ */ (0,
|
|
5834
|
+
designModeVisible && /* @__PURE__ */ (0, import_jsx_runtime36.jsx)(ManageComponentsCta, {})
|
|
6069
5835
|
] });
|
|
6070
5836
|
};
|
|
6071
5837
|
|
|
6072
5838
|
// src/index.tsx
|
|
6073
|
-
var
|
|
5839
|
+
var import_jsx_runtime37 = require("react/jsx-runtime");
|
|
6074
5840
|
function withDynamicConfig(config, data) {
|
|
6075
5841
|
const registrations = getPersistedRegistrations(data);
|
|
6076
5842
|
const dynamicConfig = {};
|
|
@@ -6101,23 +5867,22 @@ function withDynamicConfig(config, data) {
|
|
|
6101
5867
|
return result;
|
|
6102
5868
|
}
|
|
6103
5869
|
function createAiPlugin(opts) {
|
|
6104
|
-
const { scrollTracking = true,
|
|
6105
|
-
setFieldTypes(fieldTypes);
|
|
5870
|
+
const { scrollTracking = true, ...rest } = opts || {};
|
|
6106
5871
|
const scrollTrackingId = `puck-ai-scroll-${(0, import_ulid2.ulid)()}`;
|
|
6107
5872
|
const designModeVisible = typeof opts?.designMode === "boolean" ? opts.designMode : opts?.designMode?.visible ?? false;
|
|
6108
5873
|
return {
|
|
6109
5874
|
label: "AI",
|
|
6110
5875
|
name: "ai",
|
|
6111
|
-
render: () => /* @__PURE__ */ (0,
|
|
6112
|
-
icon: /* @__PURE__ */ (0,
|
|
5876
|
+
render: () => /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(Chat2, { ...rest, scrollTrackingId }),
|
|
5877
|
+
icon: /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(Bot, {}),
|
|
6113
5878
|
mobilePanelHeight: "min-content",
|
|
6114
5879
|
overrides: {
|
|
6115
5880
|
drawer: createDrawer(designModeVisible),
|
|
6116
5881
|
preview: ({ children }) => {
|
|
6117
5882
|
if (scrollTracking) {
|
|
6118
|
-
return /* @__PURE__ */ (0,
|
|
5883
|
+
return /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(ScrollTracking, { trackingId: scrollTrackingId, children });
|
|
6119
5884
|
}
|
|
6120
|
-
return /* @__PURE__ */ (0,
|
|
5885
|
+
return /* @__PURE__ */ (0, import_jsx_runtime37.jsx)(import_jsx_runtime37.Fragment, { children });
|
|
6121
5886
|
}
|
|
6122
5887
|
}
|
|
6123
5888
|
};
|