@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.mjs
CHANGED
|
@@ -1002,8 +1002,8 @@ import {
|
|
|
1002
1002
|
useEffect as useEffect14,
|
|
1003
1003
|
useId as useId3,
|
|
1004
1004
|
useMemo as useMemo6,
|
|
1005
|
-
useRef as
|
|
1006
|
-
useState as
|
|
1005
|
+
useRef as useRef13,
|
|
1006
|
+
useState as useState16
|
|
1007
1007
|
} from "react";
|
|
1008
1008
|
import { ulid } from "ulid";
|
|
1009
1009
|
|
|
@@ -1048,8 +1048,8 @@ var styles_module_default = { "Chat": "_Chat_1ei0a_1", "Chat-header": "_Chat-hea
|
|
|
1048
1048
|
// src/components/ChatBody/index.tsx
|
|
1049
1049
|
init_react_import();
|
|
1050
1050
|
import {
|
|
1051
|
-
useContext as
|
|
1052
|
-
useEffect as
|
|
1051
|
+
useContext as useContext2,
|
|
1052
|
+
useEffect as useEffect10,
|
|
1053
1053
|
useMemo as useMemo3,
|
|
1054
1054
|
useRef as useRef9,
|
|
1055
1055
|
useState as useState13
|
|
@@ -1112,7 +1112,7 @@ init_react_import();
|
|
|
1112
1112
|
|
|
1113
1113
|
// css-module:/home/runner/work/platform/platform/packages/platform-client/components/Modal/Modal.module.css#css-module
|
|
1114
1114
|
init_react_import();
|
|
1115
|
-
var Modal_module_default = { "Modal-background": "_Modal-
|
|
1115
|
+
var Modal_module_default = { "Modal-background": "_Modal-background_mocy5_1", "Modal--visible": "_Modal--visible_mocy5_16", "Modal-modal": "_Modal-modal_mocy5_22" };
|
|
1116
1116
|
|
|
1117
1117
|
// ../platform-client/components/Modal/Modal.tsx
|
|
1118
1118
|
import { createContext, useContext } from "react";
|
|
@@ -1215,12 +1215,13 @@ var Button = ({
|
|
|
1215
1215
|
secondary: variant === "secondary",
|
|
1216
1216
|
danger: variant === "danger",
|
|
1217
1217
|
ghost: variant === "ghost",
|
|
1218
|
-
|
|
1218
|
+
// Disabled while its click is still running, too.
|
|
1219
|
+
disabled: disabled || loading,
|
|
1219
1220
|
fullWidth,
|
|
1220
1221
|
[size]: true
|
|
1221
1222
|
}),
|
|
1222
1223
|
onClick: (e) => {
|
|
1223
|
-
if (disabled) {
|
|
1224
|
+
if (disabled || loading) {
|
|
1224
1225
|
e.preventDefault();
|
|
1225
1226
|
return;
|
|
1226
1227
|
}
|
|
@@ -1608,7 +1609,7 @@ import { useState as useState9 } from "react";
|
|
|
1608
1609
|
|
|
1609
1610
|
// css-module:/home/runner/work/platform/platform/packages/platform-client/components/Menu/styles.module.css#css-module
|
|
1610
1611
|
init_react_import();
|
|
1611
|
-
var styles_module_default4 = { "Menu": "
|
|
1612
|
+
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" };
|
|
1612
1613
|
|
|
1613
1614
|
// ../platform-client/components/Menu/index.tsx
|
|
1614
1615
|
import { Fragment as Fragment3, jsx as jsx17, jsxs as jsxs10 } from "react/jsx-runtime";
|
|
@@ -1719,7 +1720,7 @@ init_react_import();
|
|
|
1719
1720
|
|
|
1720
1721
|
// css-module:/home/runner/work/platform/platform/packages/platform-client/components/Tag/Tag.module.css#css-module
|
|
1721
1722
|
init_react_import();
|
|
1722
|
-
var Tag_module_default = { "Tag": "
|
|
1723
|
+
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" };
|
|
1723
1724
|
|
|
1724
1725
|
// ../platform-client/components/Tag/Tag.tsx
|
|
1725
1726
|
import { jsx as jsx22, jsxs as jsxs13 } from "react/jsx-runtime";
|
|
@@ -1773,12 +1774,6 @@ var styles_module_default6 = { "Viewport": "_Viewport_1vvhm_3", "Viewport--stand
|
|
|
1773
1774
|
import { jsx as jsx26 } from "react/jsx-runtime";
|
|
1774
1775
|
var cx6 = getClassNameFactory("Viewport", styles_module_default6);
|
|
1775
1776
|
|
|
1776
|
-
// ../platform-client/context/editor.tsx
|
|
1777
|
-
init_react_import();
|
|
1778
|
-
import { createContext as createContext2, useContext as useContext2, useState as useState11 } from "react";
|
|
1779
|
-
import { jsx as jsx27 } from "react/jsx-runtime";
|
|
1780
|
-
var ctx = createContext2({});
|
|
1781
|
-
|
|
1782
1777
|
// css-module:/home/runner/work/platform/platform/packages/plugin-ai/src/components/ChatBody/styles.module.css#css-module
|
|
1783
1778
|
init_react_import();
|
|
1784
1779
|
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" };
|
|
@@ -1789,7 +1784,7 @@ import {
|
|
|
1789
1784
|
useCallback as useCallback4,
|
|
1790
1785
|
useEffect as useEffect8,
|
|
1791
1786
|
useRef as useRef8,
|
|
1792
|
-
useState as
|
|
1787
|
+
useState as useState11
|
|
1793
1788
|
} from "react";
|
|
1794
1789
|
|
|
1795
1790
|
// css-module:/home/runner/work/platform/platform/packages/plugin-ai/src/components/PromptForm/styles.module.css#css-module
|
|
@@ -1834,6 +1829,42 @@ var matchesAccept = (file, accept) => {
|
|
|
1834
1829
|
return file.type === entry;
|
|
1835
1830
|
});
|
|
1836
1831
|
};
|
|
1832
|
+
var documentExtensionByMediaType = {
|
|
1833
|
+
"application/msword": "doc",
|
|
1834
|
+
"application/vnd.openxmlformats-officedocument.wordprocessingml.document": "docx",
|
|
1835
|
+
"text/markdown": "md",
|
|
1836
|
+
"application/pdf": "pdf",
|
|
1837
|
+
"text/plain": "txt"
|
|
1838
|
+
};
|
|
1839
|
+
var mediaTypeToExtension = (mediaType) => {
|
|
1840
|
+
const mapped = documentExtensionByMediaType[mediaType];
|
|
1841
|
+
if (mapped) {
|
|
1842
|
+
return mapped;
|
|
1843
|
+
}
|
|
1844
|
+
const subtype = mediaType.split("/")[1] ?? "";
|
|
1845
|
+
return subtype.split("+")[0] || "bin";
|
|
1846
|
+
};
|
|
1847
|
+
var getFilesFromClipboard = (data) => {
|
|
1848
|
+
const files = [];
|
|
1849
|
+
for (const item of data.items ? Array.from(data.items) : []) {
|
|
1850
|
+
if (item.kind === "file") {
|
|
1851
|
+
const file = item.getAsFile();
|
|
1852
|
+
if (file) {
|
|
1853
|
+
files.push(file);
|
|
1854
|
+
}
|
|
1855
|
+
}
|
|
1856
|
+
}
|
|
1857
|
+
if (files.length === 0 && data.files) {
|
|
1858
|
+
files.push(...Array.from(data.files));
|
|
1859
|
+
}
|
|
1860
|
+
return files.map(
|
|
1861
|
+
(file, index) => file.name ? file : new File(
|
|
1862
|
+
[file],
|
|
1863
|
+
`pasted-${Date.now()}-${index}.${mediaTypeToExtension(file.type)}`,
|
|
1864
|
+
{ type: file.type }
|
|
1865
|
+
)
|
|
1866
|
+
);
|
|
1867
|
+
};
|
|
1837
1868
|
var getAttachmentIdFromRef = (url) => url.startsWith("attachment://") ? url.slice("attachment://".length) : null;
|
|
1838
1869
|
var resolveAttachmentUrl = (url, attachmentEndpoint) => {
|
|
1839
1870
|
if (!attachmentEndpoint) {
|
|
@@ -1845,6 +1876,20 @@ var resolveAttachmentUrl = (url, attachmentEndpoint) => {
|
|
|
1845
1876
|
}
|
|
1846
1877
|
return `${attachmentEndpoint.replace(/\/$/, "")}/${attachmentId}`;
|
|
1847
1878
|
};
|
|
1879
|
+
var fetchAttachmentUrl = async (endpoint, signal) => {
|
|
1880
|
+
const response = await fetch(endpoint, { redirect: "manual", signal });
|
|
1881
|
+
if (response.type === "opaqueredirect" || response.status >= 300 && response.status < 400) {
|
|
1882
|
+
return endpoint;
|
|
1883
|
+
}
|
|
1884
|
+
if (!response.ok) {
|
|
1885
|
+
throw new Error(`Attachment URL request failed with ${response.status}`);
|
|
1886
|
+
}
|
|
1887
|
+
const { url } = await response.json();
|
|
1888
|
+
if (typeof url !== "string" || !url) {
|
|
1889
|
+
throw new Error("Attachment URL response did not include a url");
|
|
1890
|
+
}
|
|
1891
|
+
return url;
|
|
1892
|
+
};
|
|
1848
1893
|
var isInternalMessage = (text) => text.startsWith(INTERNAL_MESSAGE_PREFIX);
|
|
1849
1894
|
var truncateFilename = (name, max = 25) => {
|
|
1850
1895
|
if (name.length <= max) return name;
|
|
@@ -1856,7 +1901,7 @@ var truncateFilename = (name, max = 25) => {
|
|
|
1856
1901
|
};
|
|
1857
1902
|
|
|
1858
1903
|
// src/components/PromptForm/index.tsx
|
|
1859
|
-
import { jsx as
|
|
1904
|
+
import { jsx as jsx27, jsxs as jsxs15 } from "react/jsx-runtime";
|
|
1860
1905
|
var cx7 = getClassNameFactory2("PromptForm", styles_module_default8);
|
|
1861
1906
|
function PromptForm({
|
|
1862
1907
|
actions,
|
|
@@ -1877,9 +1922,9 @@ function PromptForm({
|
|
|
1877
1922
|
value = ""
|
|
1878
1923
|
}) {
|
|
1879
1924
|
const hasSetInitialPrompt = useRef8(false);
|
|
1880
|
-
const [prompt, setPrompt] =
|
|
1925
|
+
const [prompt, setPrompt] = useState11(value);
|
|
1881
1926
|
const internalRef = useRef8(null);
|
|
1882
|
-
const [isDragOver, setIsDragOver] =
|
|
1927
|
+
const [isDragOver, setIsDragOver] = useState11(false);
|
|
1883
1928
|
const dragCounterRef = useRef8(0);
|
|
1884
1929
|
const canDrop = !!onFileDrop && !isDisabled && !isLoading;
|
|
1885
1930
|
const handleDragEnter = useCallback4(
|
|
@@ -1916,6 +1961,16 @@ function PromptForm({
|
|
|
1916
1961
|
},
|
|
1917
1962
|
[canDrop, onFileDrop]
|
|
1918
1963
|
);
|
|
1964
|
+
const handlePaste = useCallback4(
|
|
1965
|
+
(e) => {
|
|
1966
|
+
if (!canDrop) return;
|
|
1967
|
+
const files = getFilesFromClipboard(e.clipboardData);
|
|
1968
|
+
if (files.length === 0) return;
|
|
1969
|
+
e.preventDefault();
|
|
1970
|
+
onFileDrop(files);
|
|
1971
|
+
},
|
|
1972
|
+
[canDrop, onFileDrop]
|
|
1973
|
+
);
|
|
1919
1974
|
useEffect8(() => {
|
|
1920
1975
|
setPrompt(value);
|
|
1921
1976
|
}, [setPrompt, value]);
|
|
@@ -1955,13 +2010,13 @@ function PromptForm({
|
|
|
1955
2010
|
onDrop: onFileDrop ? handleDrop : void 0,
|
|
1956
2011
|
children: [
|
|
1957
2012
|
isDragOver ? /* @__PURE__ */ jsxs15("div", { className: cx7("dropOverlay"), children: [
|
|
1958
|
-
/* @__PURE__ */
|
|
1959
|
-
/* @__PURE__ */
|
|
2013
|
+
/* @__PURE__ */ jsx27(Paperclip, { size: 20 }),
|
|
2014
|
+
/* @__PURE__ */ jsx27("span", { children: "Attach file" })
|
|
1960
2015
|
] }) : null,
|
|
1961
|
-
helperText ? /* @__PURE__ */
|
|
2016
|
+
helperText ? /* @__PURE__ */ jsx27("div", { className: cx7("helper"), children: helperText }) : null,
|
|
1962
2017
|
/* @__PURE__ */ jsxs15("div", { className: cx7("inner"), children: [
|
|
1963
|
-
/* @__PURE__ */
|
|
1964
|
-
/* @__PURE__ */
|
|
2018
|
+
/* @__PURE__ */ jsx27("span", { className: cx7("glow") }),
|
|
2019
|
+
/* @__PURE__ */ jsx27(
|
|
1965
2020
|
"form",
|
|
1966
2021
|
{
|
|
1967
2022
|
onSubmit: (e) => {
|
|
@@ -1969,7 +2024,7 @@ function PromptForm({
|
|
|
1969
2024
|
void sendPrompt();
|
|
1970
2025
|
},
|
|
1971
2026
|
children: /* @__PURE__ */ jsxs15("div", { className: cx7("formInner"), children: [
|
|
1972
|
-
attachments && attachments.length > 0 ? /* @__PURE__ */
|
|
2027
|
+
attachments && attachments.length > 0 ? /* @__PURE__ */ jsx27("div", { className: cx7("attachments"), children: attachments.map((attachment) => /* @__PURE__ */ jsxs15(
|
|
1973
2028
|
"div",
|
|
1974
2029
|
{
|
|
1975
2030
|
className: [
|
|
@@ -1978,29 +2033,29 @@ function PromptForm({
|
|
|
1978
2033
|
attachment.status === "failed" ? cx7("attachmentChipFailed") : ""
|
|
1979
2034
|
].filter(Boolean).join(" "),
|
|
1980
2035
|
children: [
|
|
1981
|
-
attachment.status === "uploading" ? /* @__PURE__ */
|
|
2036
|
+
attachment.status === "uploading" ? /* @__PURE__ */ jsx27(
|
|
1982
2037
|
LoaderCircle,
|
|
1983
2038
|
{
|
|
1984
2039
|
className: cx7("attachmentSpinner"),
|
|
1985
2040
|
size: 14
|
|
1986
2041
|
}
|
|
1987
2042
|
) : null,
|
|
1988
|
-
/* @__PURE__ */
|
|
1989
|
-
attachment.status === "failed" ? /* @__PURE__ */
|
|
1990
|
-
onRemoveAttachment ? /* @__PURE__ */
|
|
2043
|
+
/* @__PURE__ */ jsx27("span", { title: attachment.filename, children: truncateFilename(attachment.filename) }),
|
|
2044
|
+
attachment.status === "failed" ? /* @__PURE__ */ jsx27("span", { className: cx7("attachmentError"), children: "Failed" }) : null,
|
|
2045
|
+
onRemoveAttachment ? /* @__PURE__ */ jsx27(
|
|
1991
2046
|
"button",
|
|
1992
2047
|
{
|
|
1993
2048
|
className: cx7("attachmentRemove"),
|
|
1994
2049
|
onClick: () => onRemoveAttachment(attachment.clientId),
|
|
1995
2050
|
type: "button",
|
|
1996
|
-
children: /* @__PURE__ */
|
|
2051
|
+
children: /* @__PURE__ */ jsx27(X, { size: 12 })
|
|
1997
2052
|
}
|
|
1998
2053
|
) : null
|
|
1999
2054
|
]
|
|
2000
2055
|
},
|
|
2001
2056
|
attachment.clientId
|
|
2002
2057
|
)) }) : null,
|
|
2003
|
-
/* @__PURE__ */
|
|
2058
|
+
/* @__PURE__ */ jsx27(
|
|
2004
2059
|
default2,
|
|
2005
2060
|
{
|
|
2006
2061
|
className: cx7("input"),
|
|
@@ -2017,6 +2072,7 @@ function PromptForm({
|
|
|
2017
2072
|
internalRef.current = node;
|
|
2018
2073
|
},
|
|
2019
2074
|
onChange: (e) => setPrompt(e.target.value),
|
|
2075
|
+
onPaste: onFileDrop ? handlePaste : void 0,
|
|
2020
2076
|
onKeyDown: (e) => {
|
|
2021
2077
|
if (!e.shiftKey && e.key === "Enter") {
|
|
2022
2078
|
e.preventDefault();
|
|
@@ -2038,7 +2094,7 @@ function PromptForm({
|
|
|
2038
2094
|
internalRef?.current?.focus();
|
|
2039
2095
|
},
|
|
2040
2096
|
children: [
|
|
2041
|
-
/* @__PURE__ */
|
|
2097
|
+
/* @__PURE__ */ jsx27(
|
|
2042
2098
|
"div",
|
|
2043
2099
|
{
|
|
2044
2100
|
className: cx7("actionsLeft"),
|
|
@@ -2046,18 +2102,18 @@ function PromptForm({
|
|
|
2046
2102
|
children: actions
|
|
2047
2103
|
}
|
|
2048
2104
|
),
|
|
2049
|
-
/* @__PURE__ */
|
|
2105
|
+
/* @__PURE__ */ jsx27(
|
|
2050
2106
|
"div",
|
|
2051
2107
|
{
|
|
2052
2108
|
className: cx7("actionsRight"),
|
|
2053
2109
|
onClick: (e) => e.stopPropagation(),
|
|
2054
|
-
children: /* @__PURE__ */
|
|
2110
|
+
children: /* @__PURE__ */ jsx27(
|
|
2055
2111
|
"button",
|
|
2056
2112
|
{
|
|
2057
2113
|
className: cx7("actionSubmit"),
|
|
2058
2114
|
type: "submit",
|
|
2059
2115
|
disabled: isLoading,
|
|
2060
|
-
children: isLoading ? /* @__PURE__ */
|
|
2116
|
+
children: isLoading ? /* @__PURE__ */ jsx27(Loader, { size: 18 }) : cta ?? /* @__PURE__ */ jsx27(ArrowUp, { size: 24 })
|
|
2061
2117
|
}
|
|
2062
2118
|
)
|
|
2063
2119
|
}
|
|
@@ -2076,16 +2132,45 @@ function PromptForm({
|
|
|
2076
2132
|
|
|
2077
2133
|
// src/lib/context.ts
|
|
2078
2134
|
init_react_import();
|
|
2079
|
-
import { createContext as
|
|
2080
|
-
var toolStatusContext =
|
|
2135
|
+
import { createContext as createContext2 } from "react";
|
|
2136
|
+
var toolStatusContext = createContext2({});
|
|
2081
2137
|
var ToolStatusProvider = toolStatusContext.Provider;
|
|
2082
|
-
var hostContext =
|
|
2138
|
+
var hostContext = createContext2(void 0);
|
|
2083
2139
|
var HostProvider = hostContext.Provider;
|
|
2084
|
-
var subagentStateContext =
|
|
2140
|
+
var subagentStateContext = createContext2({});
|
|
2085
2141
|
var SubagentStateProvider = subagentStateContext.Provider;
|
|
2086
2142
|
|
|
2143
|
+
// src/lib/use-attachment-url.ts
|
|
2144
|
+
init_react_import();
|
|
2145
|
+
import { useEffect as useEffect9, useState as useState12 } from "react";
|
|
2146
|
+
function useAttachmentUrl(url, endpoint) {
|
|
2147
|
+
const isRef = getAttachmentIdFromRef(url) !== null;
|
|
2148
|
+
const [fetched, setFetched] = useState12();
|
|
2149
|
+
useEffect9(() => {
|
|
2150
|
+
if (!isRef) return;
|
|
2151
|
+
const controller = new AbortController();
|
|
2152
|
+
const loadUrl = async () => {
|
|
2153
|
+
try {
|
|
2154
|
+
const resolved = await fetchAttachmentUrl(
|
|
2155
|
+
resolveAttachmentUrl(url, endpoint),
|
|
2156
|
+
controller.signal
|
|
2157
|
+
);
|
|
2158
|
+
setFetched({ ref: url, url: resolved });
|
|
2159
|
+
} catch (error) {
|
|
2160
|
+
if (!controller.signal.aborted) {
|
|
2161
|
+
console.error("Failed to load attachment:", error);
|
|
2162
|
+
}
|
|
2163
|
+
}
|
|
2164
|
+
};
|
|
2165
|
+
loadUrl();
|
|
2166
|
+
return () => controller.abort();
|
|
2167
|
+
}, [isRef, url, endpoint]);
|
|
2168
|
+
if (!isRef) return url;
|
|
2169
|
+
return fetched?.ref === url ? fetched.url : void 0;
|
|
2170
|
+
}
|
|
2171
|
+
|
|
2087
2172
|
// src/components/ChatBody/index.tsx
|
|
2088
|
-
import { Fragment as Fragment5, jsx as
|
|
2173
|
+
import { Fragment as Fragment5, jsx as jsx28, jsxs as jsxs16 } from "react/jsx-runtime";
|
|
2089
2174
|
var cx8 = getClassNameFactory2("Chat", styles_module_default7);
|
|
2090
2175
|
var cxMessage = getClassNameFactory2("ChatMessage", styles_module_default7);
|
|
2091
2176
|
function ChatBody({
|
|
@@ -2120,22 +2205,22 @@ function ChatBody({
|
|
|
2120
2205
|
isLoading
|
|
2121
2206
|
}),
|
|
2122
2207
|
children: [
|
|
2123
|
-
children ? /* @__PURE__ */
|
|
2208
|
+
children ? /* @__PURE__ */ jsx28("div", { className: cx8("default"), children }) : null,
|
|
2124
2209
|
/* @__PURE__ */ jsxs16("div", { className: cx8("inner"), children: [
|
|
2125
2210
|
/* @__PURE__ */ jsxs16("div", { className: cx8("body"), ref: scrollRef, children: [
|
|
2126
|
-
/* @__PURE__ */
|
|
2211
|
+
/* @__PURE__ */ jsx28("div", { className: cx8("messages"), ref: contentRef, children: messages.toReversed().filter((message) => !shouldHideMessage(message)).map((message) => /* @__PURE__ */ jsx28(ChatMessage, { message }, message.id)) }),
|
|
2127
2212
|
isLoading && /* @__PURE__ */ jsxs16("div", { className: cx8("loader"), children: [
|
|
2128
|
-
/* @__PURE__ */
|
|
2129
|
-
/* @__PURE__ */
|
|
2213
|
+
/* @__PURE__ */ jsx28("div", { className: cx8("loaderIcon"), children: /* @__PURE__ */ jsx28(Loader, { size: 16 }) }),
|
|
2214
|
+
/* @__PURE__ */ jsx28("div", { children: "Thinking..." })
|
|
2130
2215
|
] })
|
|
2131
2216
|
] }),
|
|
2132
2217
|
error && /* @__PURE__ */ jsxs16("div", { className: cx8("error"), children: [
|
|
2133
|
-
/* @__PURE__ */
|
|
2134
|
-
handleRetry && /* @__PURE__ */
|
|
2218
|
+
/* @__PURE__ */ jsx28("div", { className: cx8("errorLabel"), children: "Something went wrong." }),
|
|
2219
|
+
handleRetry && /* @__PURE__ */ jsx28("div", { className: cx8("errorAction"), children: /* @__PURE__ */ jsx28(IconButton, { title: "Retry", onClick: handleRetry, children: /* @__PURE__ */ jsx28(RotateCcw, { size: "14" }) }) })
|
|
2135
2220
|
] }),
|
|
2136
2221
|
userError && /* @__PURE__ */ jsxs16("div", { className: cx8("userError"), children: [
|
|
2137
|
-
/* @__PURE__ */
|
|
2138
|
-
onDismissUserError && /* @__PURE__ */
|
|
2222
|
+
/* @__PURE__ */ jsx28("span", { children: userError }),
|
|
2223
|
+
onDismissUserError && /* @__PURE__ */ jsx28(
|
|
2139
2224
|
"button",
|
|
2140
2225
|
{
|
|
2141
2226
|
"aria-label": "Dismiss",
|
|
@@ -2143,12 +2228,12 @@ function ChatBody({
|
|
|
2143
2228
|
className: cx8("userErrorDismiss"),
|
|
2144
2229
|
onClick: onDismissUserError,
|
|
2145
2230
|
type: "button",
|
|
2146
|
-
children: /* @__PURE__ */
|
|
2231
|
+
children: /* @__PURE__ */ jsx28(X, { size: 14 })
|
|
2147
2232
|
}
|
|
2148
2233
|
)
|
|
2149
2234
|
] }),
|
|
2150
2235
|
/* @__PURE__ */ jsxs16("div", { className: cx8("form"), children: [
|
|
2151
|
-
/* @__PURE__ */
|
|
2236
|
+
/* @__PURE__ */ jsx28(
|
|
2152
2237
|
PromptForm,
|
|
2153
2238
|
{
|
|
2154
2239
|
actions,
|
|
@@ -2162,7 +2247,7 @@ function ChatBody({
|
|
|
2162
2247
|
placeholder: "What do you want to build?"
|
|
2163
2248
|
}
|
|
2164
2249
|
),
|
|
2165
|
-
examplePrompts ? /* @__PURE__ */
|
|
2250
|
+
examplePrompts ? /* @__PURE__ */ jsx28("div", { className: cx8("examplePrompts"), children: examplePrompts }) : null
|
|
2166
2251
|
] })
|
|
2167
2252
|
] })
|
|
2168
2253
|
]
|
|
@@ -2191,13 +2276,13 @@ function ChatMessage({ message }) {
|
|
|
2191
2276
|
if (role === "user") {
|
|
2192
2277
|
const attachmentParts = parts.filter((part) => part.type === "file");
|
|
2193
2278
|
const otherParts = parts.filter((part) => part.type !== "file");
|
|
2194
|
-
return /* @__PURE__ */
|
|
2279
|
+
return /* @__PURE__ */ jsx28(
|
|
2195
2280
|
"div",
|
|
2196
2281
|
{
|
|
2197
2282
|
className: cxMessage({ userRole: true }),
|
|
2198
2283
|
"data-message-id": message.id,
|
|
2199
2284
|
children: /* @__PURE__ */ jsxs16("div", { className: cxMessage("userBubble"), children: [
|
|
2200
|
-
otherParts.map((part, i) => /* @__PURE__ */
|
|
2285
|
+
otherParts.map((part, i) => /* @__PURE__ */ jsx28(
|
|
2201
2286
|
ChatMessagePart,
|
|
2202
2287
|
{
|
|
2203
2288
|
part,
|
|
@@ -2205,7 +2290,7 @@ function ChatMessage({ message }) {
|
|
|
2205
2290
|
},
|
|
2206
2291
|
`${message.id}-${part.type}-${i}`
|
|
2207
2292
|
)),
|
|
2208
|
-
attachmentParts.length > 0 ? /* @__PURE__ */
|
|
2293
|
+
attachmentParts.length > 0 ? /* @__PURE__ */ jsx28("div", { className: cxMessage("userAttachments"), children: attachmentParts.map((part, i) => /* @__PURE__ */ jsx28(
|
|
2209
2294
|
ChatAttachmentThumbnail,
|
|
2210
2295
|
{
|
|
2211
2296
|
filename: part.filename,
|
|
@@ -2218,12 +2303,12 @@ function ChatMessage({ message }) {
|
|
|
2218
2303
|
}
|
|
2219
2304
|
);
|
|
2220
2305
|
}
|
|
2221
|
-
return /* @__PURE__ */
|
|
2306
|
+
return /* @__PURE__ */ jsx28(
|
|
2222
2307
|
"div",
|
|
2223
2308
|
{
|
|
2224
2309
|
className: cxMessage({ [`${role}Role`]: true }),
|
|
2225
2310
|
"data-message-id": message.id,
|
|
2226
|
-
children: parts.map((part, i) => /* @__PURE__ */
|
|
2311
|
+
children: parts.map((part, i) => /* @__PURE__ */ jsx28(
|
|
2227
2312
|
ChatMessagePart,
|
|
2228
2313
|
{
|
|
2229
2314
|
part,
|
|
@@ -2239,9 +2324,9 @@ function ChatAttachmentThumbnail({
|
|
|
2239
2324
|
mediaType,
|
|
2240
2325
|
url
|
|
2241
2326
|
}) {
|
|
2242
|
-
const host =
|
|
2327
|
+
const host = useContext2(hostContext);
|
|
2243
2328
|
const endpoint = host ? `${host.replace(/\/$/, "")}/attachments` : "/api/puck/chat/attachments";
|
|
2244
|
-
const resolvedUrl =
|
|
2329
|
+
const resolvedUrl = useAttachmentUrl(url, endpoint);
|
|
2245
2330
|
const attachmentId = getAttachmentIdFromRef(url);
|
|
2246
2331
|
const label = filename || attachmentId || "Attachment";
|
|
2247
2332
|
const isImage = mediaType.startsWith("image/");
|
|
@@ -2255,8 +2340,8 @@ function ChatAttachmentThumbnail({
|
|
|
2255
2340
|
target: "_blank",
|
|
2256
2341
|
title: label,
|
|
2257
2342
|
children: [
|
|
2258
|
-
isImage ? /* @__PURE__ */
|
|
2259
|
-
/* @__PURE__ */
|
|
2343
|
+
isImage ? resolvedUrl && /* @__PURE__ */ jsx28("img", { alt: label, src: resolvedUrl }) : /* @__PURE__ */ jsx28(FileText, { size: 20 }),
|
|
2344
|
+
/* @__PURE__ */ jsx28("span", { className: cxMessage("thumbnailLabel"), children: label })
|
|
2260
2345
|
]
|
|
2261
2346
|
}
|
|
2262
2347
|
);
|
|
@@ -2271,9 +2356,9 @@ function ChatMessageWrapper({
|
|
|
2271
2356
|
role
|
|
2272
2357
|
}) {
|
|
2273
2358
|
if (role === "assistant" || role === "user") {
|
|
2274
|
-
return /* @__PURE__ */
|
|
2359
|
+
return /* @__PURE__ */ jsx28(Markdown, { children });
|
|
2275
2360
|
}
|
|
2276
|
-
return /* @__PURE__ */
|
|
2361
|
+
return /* @__PURE__ */ jsx28("span", { children });
|
|
2277
2362
|
}
|
|
2278
2363
|
function ReasoningBlock({ part }) {
|
|
2279
2364
|
const startTimeRef = useRef9(null);
|
|
@@ -2281,14 +2366,14 @@ function ReasoningBlock({ part }) {
|
|
|
2281
2366
|
if (part.state !== "done" && startTimeRef.current === null) {
|
|
2282
2367
|
startTimeRef.current = Date.now();
|
|
2283
2368
|
}
|
|
2284
|
-
|
|
2369
|
+
useEffect10(() => {
|
|
2285
2370
|
if (part.state === "done" && startTimeRef.current !== null) {
|
|
2286
2371
|
setDurationSecs(Math.round((Date.now() - startTimeRef.current) / 1e3));
|
|
2287
2372
|
}
|
|
2288
2373
|
}, [part.state]);
|
|
2289
2374
|
const loading = part.state ? part.state !== "done" : false;
|
|
2290
2375
|
const label = durationSecs !== null ? `Thought for ${durationSecs}s` : !loading ? "Thought for a while" : "Thinking...";
|
|
2291
|
-
return /* @__PURE__ */
|
|
2376
|
+
return /* @__PURE__ */ jsx28(
|
|
2292
2377
|
ChatEvent,
|
|
2293
2378
|
{
|
|
2294
2379
|
status: {
|
|
@@ -2296,7 +2381,7 @@ function ReasoningBlock({ part }) {
|
|
|
2296
2381
|
loading,
|
|
2297
2382
|
summary: part.text
|
|
2298
2383
|
},
|
|
2299
|
-
icon: /* @__PURE__ */
|
|
2384
|
+
icon: /* @__PURE__ */ jsx28(Brain, { size: 18 })
|
|
2300
2385
|
}
|
|
2301
2386
|
);
|
|
2302
2387
|
}
|
|
@@ -2305,19 +2390,19 @@ function ChatMessagePart({
|
|
|
2305
2390
|
role
|
|
2306
2391
|
}) {
|
|
2307
2392
|
if (part.type === "text") {
|
|
2308
|
-
return /* @__PURE__ */
|
|
2393
|
+
return /* @__PURE__ */ jsx28("div", { className: cxMessage("text"), children: /* @__PURE__ */ jsx28(ChatMessageWrapper, { role, children: part.text }) });
|
|
2309
2394
|
}
|
|
2310
2395
|
if (part.type === "reasoning") {
|
|
2311
|
-
return /* @__PURE__ */
|
|
2396
|
+
return /* @__PURE__ */ jsx28(ReasoningBlock, { part });
|
|
2312
2397
|
}
|
|
2313
2398
|
if (part.type === "tool-subagent") {
|
|
2314
|
-
return /* @__PURE__ */
|
|
2399
|
+
return /* @__PURE__ */ jsx28(SubagentBlock, { toolCallId: part.toolCallId });
|
|
2315
2400
|
}
|
|
2316
2401
|
if (part.type.startsWith("tool-")) {
|
|
2317
|
-
return /* @__PURE__ */
|
|
2402
|
+
return /* @__PURE__ */ jsx28(PuckTool, { ...part });
|
|
2318
2403
|
}
|
|
2319
2404
|
if (part.type === "file") {
|
|
2320
|
-
return /* @__PURE__ */
|
|
2405
|
+
return /* @__PURE__ */ jsx28(
|
|
2321
2406
|
ChatAttachment,
|
|
2322
2407
|
{
|
|
2323
2408
|
filename: part.filename,
|
|
@@ -2333,17 +2418,17 @@ function ChatAttachment({
|
|
|
2333
2418
|
mediaType,
|
|
2334
2419
|
url
|
|
2335
2420
|
}) {
|
|
2336
|
-
const host =
|
|
2421
|
+
const host = useContext2(hostContext);
|
|
2337
2422
|
const endpoint = host ? `${host.replace(/\/$/, "")}/attachments` : "/api/puck/chat/attachments";
|
|
2338
|
-
const resolvedUrl =
|
|
2423
|
+
const resolvedUrl = useAttachmentUrl(url, endpoint);
|
|
2339
2424
|
const attachmentId = getAttachmentIdFromRef(url);
|
|
2340
2425
|
const label = filename || attachmentId || "Attachment";
|
|
2341
2426
|
if (mediaType.startsWith("image/")) {
|
|
2342
|
-
return /* @__PURE__ */
|
|
2427
|
+
return /* @__PURE__ */ jsx28("div", { className: cxMessage("attachmentImage"), children: /* @__PURE__ */ jsx28("a", { href: resolvedUrl, target: "_blank", rel: "noreferrer", children: resolvedUrl && /* @__PURE__ */ jsx28("img", { alt: label, src: resolvedUrl }) }) });
|
|
2343
2428
|
}
|
|
2344
|
-
return /* @__PURE__ */
|
|
2345
|
-
/* @__PURE__ */
|
|
2346
|
-
/* @__PURE__ */
|
|
2429
|
+
return /* @__PURE__ */ jsx28("div", { className: cxMessage("attachmentFile"), children: /* @__PURE__ */ jsxs16("a", { href: resolvedUrl, target: "_blank", rel: "noreferrer", children: [
|
|
2430
|
+
/* @__PURE__ */ jsx28(FileText, { size: 16 }),
|
|
2431
|
+
/* @__PURE__ */ jsx28("span", { children: label })
|
|
2347
2432
|
] }) });
|
|
2348
2433
|
}
|
|
2349
2434
|
function PuckTool({
|
|
@@ -2352,29 +2437,29 @@ function PuckTool({
|
|
|
2352
2437
|
defaultLabel = "Thinking...",
|
|
2353
2438
|
type
|
|
2354
2439
|
}) {
|
|
2355
|
-
const toolStatus =
|
|
2440
|
+
const toolStatus = useContext2(toolStatusContext)[toolCallId];
|
|
2356
2441
|
const outputObj = output;
|
|
2357
2442
|
const status = outputObj && "status" in outputObj ? outputObj.status : toolStatus ?? { loading: true, label: defaultLabel };
|
|
2358
2443
|
let icon = useMemo3(() => {
|
|
2359
2444
|
if (type === "tool-write") {
|
|
2360
|
-
return /* @__PURE__ */
|
|
2445
|
+
return /* @__PURE__ */ jsx28(Pen, { size: 18 });
|
|
2361
2446
|
} else if (type === "tool-refreshPageData") {
|
|
2362
|
-
return /* @__PURE__ */
|
|
2447
|
+
return /* @__PURE__ */ jsx28(GitPullRequest, { size: 18 });
|
|
2363
2448
|
} else if (type === "tool-takeScreenshot") {
|
|
2364
|
-
return /* @__PURE__ */
|
|
2449
|
+
return /* @__PURE__ */ jsx28(Camera, { size: 18 });
|
|
2365
2450
|
} else if (type === "tool-fetchUrl") {
|
|
2366
|
-
return /* @__PURE__ */
|
|
2451
|
+
return /* @__PURE__ */ jsx28(CloudDownload, { size: 18 });
|
|
2367
2452
|
} else if (type === "tool-screenshotUrl") {
|
|
2368
|
-
return /* @__PURE__ */
|
|
2453
|
+
return /* @__PURE__ */ jsx28(Camera, { size: 18 });
|
|
2369
2454
|
}
|
|
2370
|
-
return /* @__PURE__ */
|
|
2455
|
+
return /* @__PURE__ */ jsx28(Check, { size: 18 });
|
|
2371
2456
|
}, [type]);
|
|
2372
|
-
return /* @__PURE__ */
|
|
2457
|
+
return /* @__PURE__ */ jsx28(ChatEvent, { status, icon });
|
|
2373
2458
|
}
|
|
2374
2459
|
function SubagentBlock({ toolCallId }) {
|
|
2375
|
-
const subagentState =
|
|
2460
|
+
const subagentState = useContext2(subagentStateContext);
|
|
2376
2461
|
const state = subagentState[toolCallId];
|
|
2377
|
-
const toolStatusMap =
|
|
2462
|
+
const toolStatusMap = useContext2(toolStatusContext);
|
|
2378
2463
|
const toolStatus = toolStatusMap[toolCallId];
|
|
2379
2464
|
const fallbackLabel = toolStatus?.label ?? "Running subagent";
|
|
2380
2465
|
const label = state?.label ? state.state === "done" ? `${state.agentType} subagent complete` : state.label : fallbackLabel;
|
|
@@ -2394,26 +2479,26 @@ function SubagentBlock({ toolCallId }) {
|
|
|
2394
2479
|
className: cxMessage("eventHeader"),
|
|
2395
2480
|
style: hasBody ? {} : { color: "var(--puck-color-grey-05) !important", cursor: "unset" },
|
|
2396
2481
|
children: [
|
|
2397
|
-
/* @__PURE__ */
|
|
2398
|
-
/* @__PURE__ */
|
|
2482
|
+
/* @__PURE__ */ jsx28("div", { className: cxMessage("eventIcon"), children: loading ? /* @__PURE__ */ jsx28(Loader, { size: 16 }) : /* @__PURE__ */ jsx28(Bot, { size: 18 }) }),
|
|
2483
|
+
/* @__PURE__ */ jsx28("div", { className: cxMessage("eventLabel"), children: label }),
|
|
2399
2484
|
hasBody && /* @__PURE__ */ jsxs16(Fragment5, { children: [
|
|
2400
|
-
/* @__PURE__ */
|
|
2401
|
-
/* @__PURE__ */
|
|
2485
|
+
/* @__PURE__ */ jsx28("div", { className: cxMessage("eventExpand"), children: /* @__PURE__ */ jsx28(Plus, { size: 12 }) }),
|
|
2486
|
+
/* @__PURE__ */ jsx28("div", { className: cxMessage("eventCollapse"), children: /* @__PURE__ */ jsx28(Minus, { size: 12 }) })
|
|
2402
2487
|
] })
|
|
2403
2488
|
]
|
|
2404
2489
|
}
|
|
2405
2490
|
),
|
|
2406
|
-
hasBody && isOpen && /* @__PURE__ */
|
|
2491
|
+
hasBody && isOpen && /* @__PURE__ */ jsx28("div", { className: cxMessage("eventBody"), children: parts.map((part, i) => /* @__PURE__ */ jsx28(SubagentChildPartRenderer, { part }, `${toolCallId}-${i}`)) })
|
|
2407
2492
|
]
|
|
2408
2493
|
}
|
|
2409
2494
|
);
|
|
2410
2495
|
}
|
|
2411
2496
|
function SubagentChildPartRenderer({ part }) {
|
|
2412
2497
|
if (part.kind === "text") {
|
|
2413
|
-
return /* @__PURE__ */
|
|
2498
|
+
return /* @__PURE__ */ jsx28("div", { className: cxMessage("text"), children: /* @__PURE__ */ jsx28(Markdown, { children: part.text }) });
|
|
2414
2499
|
}
|
|
2415
2500
|
if (part.kind === "reasoning") {
|
|
2416
|
-
return /* @__PURE__ */
|
|
2501
|
+
return /* @__PURE__ */ jsx28(
|
|
2417
2502
|
ReasoningBlock,
|
|
2418
2503
|
{
|
|
2419
2504
|
part: {
|
|
@@ -2425,7 +2510,7 @@ function SubagentChildPartRenderer({ part }) {
|
|
|
2425
2510
|
);
|
|
2426
2511
|
}
|
|
2427
2512
|
if (part.toolName === "subagent") {
|
|
2428
|
-
return /* @__PURE__ */
|
|
2513
|
+
return /* @__PURE__ */ jsx28(SubagentBlock, { toolCallId: part.childToolCallId });
|
|
2429
2514
|
}
|
|
2430
2515
|
const synthesized = {
|
|
2431
2516
|
toolCallId: part.childToolCallId,
|
|
@@ -2434,11 +2519,11 @@ function SubagentChildPartRenderer({ part }) {
|
|
|
2434
2519
|
input: part.input,
|
|
2435
2520
|
output: part.output
|
|
2436
2521
|
};
|
|
2437
|
-
return /* @__PURE__ */
|
|
2522
|
+
return /* @__PURE__ */ jsx28(PuckTool, { ...synthesized });
|
|
2438
2523
|
}
|
|
2439
2524
|
function ChatEvent({
|
|
2440
2525
|
status,
|
|
2441
|
-
icon = /* @__PURE__ */
|
|
2526
|
+
icon = /* @__PURE__ */ jsx28(Check, { size: 18 })
|
|
2442
2527
|
}) {
|
|
2443
2528
|
const [isOpen, setIsOpen] = useState13(false);
|
|
2444
2529
|
return /* @__PURE__ */ jsxs16(
|
|
@@ -2453,16 +2538,16 @@ function ChatEvent({
|
|
|
2453
2538
|
className: cxMessage("eventHeader"),
|
|
2454
2539
|
style: status.summary ? {} : { color: "var(--puck-color-grey-05) !important", cursor: "unset" },
|
|
2455
2540
|
children: [
|
|
2456
|
-
/* @__PURE__ */
|
|
2457
|
-
/* @__PURE__ */
|
|
2541
|
+
/* @__PURE__ */ jsx28("div", { className: cxMessage("eventIcon"), children: status.error ? /* @__PURE__ */ jsx28(TriangleAlert, { size: 18 }) : status.loading ? /* @__PURE__ */ jsx28(Loader, { size: 16 }) : icon }),
|
|
2542
|
+
/* @__PURE__ */ jsx28("div", { children: status.label }),
|
|
2458
2543
|
status.summary && /* @__PURE__ */ jsxs16(Fragment5, { children: [
|
|
2459
|
-
/* @__PURE__ */
|
|
2460
|
-
/* @__PURE__ */
|
|
2544
|
+
/* @__PURE__ */ jsx28("div", { className: cxMessage("eventExpand"), children: /* @__PURE__ */ jsx28(Plus, { size: 12 }) }),
|
|
2545
|
+
/* @__PURE__ */ jsx28("div", { className: cxMessage("eventCollapse"), children: /* @__PURE__ */ jsx28(Minus, { size: 12 }) })
|
|
2461
2546
|
] })
|
|
2462
2547
|
]
|
|
2463
2548
|
}
|
|
2464
2549
|
),
|
|
2465
|
-
status.summary && isOpen && /* @__PURE__ */
|
|
2550
|
+
status.summary && isOpen && /* @__PURE__ */ jsx28("div", { className: cxMessage("eventBody"), children: /* @__PURE__ */ jsx28(Markdown, { children: status.summary }) })
|
|
2466
2551
|
]
|
|
2467
2552
|
}
|
|
2468
2553
|
);
|
|
@@ -2474,11 +2559,11 @@ function ExamplePrompt({
|
|
|
2474
2559
|
disabled
|
|
2475
2560
|
}) {
|
|
2476
2561
|
const content = /* @__PURE__ */ jsxs16(Fragment5, { children: [
|
|
2477
|
-
/* @__PURE__ */
|
|
2478
|
-
/* @__PURE__ */
|
|
2562
|
+
/* @__PURE__ */ jsx28("div", { children: label }),
|
|
2563
|
+
/* @__PURE__ */ jsx28("div", { className: cx8("examplePromptArrow"), children: /* @__PURE__ */ jsx28(ArrowUp, { size: "16" }) })
|
|
2479
2564
|
] });
|
|
2480
2565
|
if (href) {
|
|
2481
|
-
return /* @__PURE__ */
|
|
2566
|
+
return /* @__PURE__ */ jsx28(
|
|
2482
2567
|
"a",
|
|
2483
2568
|
{
|
|
2484
2569
|
className: cx8("examplePrompt"),
|
|
@@ -2495,7 +2580,7 @@ function ExamplePrompt({
|
|
|
2495
2580
|
}
|
|
2496
2581
|
);
|
|
2497
2582
|
}
|
|
2498
|
-
return /* @__PURE__ */
|
|
2583
|
+
return /* @__PURE__ */ jsx28(
|
|
2499
2584
|
"button",
|
|
2500
2585
|
{
|
|
2501
2586
|
className: cx8("examplePrompt"),
|
|
@@ -2535,14 +2620,14 @@ init_react_import();
|
|
|
2535
2620
|
var styles_module_default9 = { "DesignModeToggle": "_DesignModeToggle_o5uty_1", "DesignModeToggle-button": "_DesignModeToggle-button_o5uty_8", "DesignModeToggle-button--active": "_DesignModeToggle-button--active_o5uty_28" };
|
|
2536
2621
|
|
|
2537
2622
|
// src/components/DesignModeToggle/index.tsx
|
|
2538
|
-
import { jsx as
|
|
2623
|
+
import { jsx as jsx29, jsxs as jsxs17 } from "react/jsx-runtime";
|
|
2539
2624
|
var cx9 = getClassNameFactory2("DesignModeToggle", styles_module_default9);
|
|
2540
2625
|
function DesignModeToggle({
|
|
2541
2626
|
active,
|
|
2542
2627
|
onToggle,
|
|
2543
2628
|
disabled
|
|
2544
2629
|
}) {
|
|
2545
|
-
return /* @__PURE__ */
|
|
2630
|
+
return /* @__PURE__ */ jsx29("div", { className: cx9(), children: /* @__PURE__ */ jsxs17(
|
|
2546
2631
|
"button",
|
|
2547
2632
|
{
|
|
2548
2633
|
className: `${cx9("button")} ${active ? cx9("button--active") : ""}`,
|
|
@@ -2551,7 +2636,7 @@ function DesignModeToggle({
|
|
|
2551
2636
|
type: "button",
|
|
2552
2637
|
title: active ? "Disable design mode" : "Enable design mode",
|
|
2553
2638
|
children: [
|
|
2554
|
-
/* @__PURE__ */
|
|
2639
|
+
/* @__PURE__ */ jsx29(WandSparkles, { size: 12 }),
|
|
2555
2640
|
"Design"
|
|
2556
2641
|
]
|
|
2557
2642
|
}
|
|
@@ -2569,171 +2654,28 @@ init_react_import();
|
|
|
2569
2654
|
import {
|
|
2570
2655
|
useGetPuck as useGetPuck2
|
|
2571
2656
|
} from "@puckeditor/core";
|
|
2572
|
-
import
|
|
2657
|
+
import {
|
|
2573
2658
|
useCallback as useCallback5,
|
|
2574
2659
|
useEffect as useEffect12,
|
|
2575
2660
|
useLayoutEffect,
|
|
2576
2661
|
useMemo as useMemo5,
|
|
2577
|
-
useRef as
|
|
2578
|
-
useState as
|
|
2662
|
+
useRef as useRef11,
|
|
2663
|
+
useState as useState15,
|
|
2579
2664
|
useSyncExternalStore as useSyncExternalStore2
|
|
2580
2665
|
} from "react";
|
|
2581
2666
|
|
|
2582
2667
|
// src/lib/morph-html.ts
|
|
2583
2668
|
init_react_import();
|
|
2584
|
-
var PROTECTED_ATTRS = /* @__PURE__ */ new Set([
|
|
2585
|
-
"contenteditable",
|
|
2586
|
-
"data-puck-overlay-portal"
|
|
2587
|
-
]);
|
|
2588
|
-
var SLOT_OWNED_ATTRS = /* @__PURE__ */ new Set(["style", "class"]);
|
|
2589
|
-
var isEventHandlerAttr = (name) => /^on/i.test(name);
|
|
2590
|
-
var FIELD_ATTR_PREFIX = "data-puck-field-";
|
|
2591
|
-
var hasJsonFieldBinding = (el) => {
|
|
2592
|
-
const attrBoundNames = /* @__PURE__ */ new Set();
|
|
2593
|
-
const jsonFieldNames = [];
|
|
2594
|
-
for (const attr of Array.from(el.attributes)) {
|
|
2595
|
-
if (!attr.name.startsWith(FIELD_ATTR_PREFIX)) continue;
|
|
2596
|
-
if (attr.name.startsWith("data-puck-field-value-")) continue;
|
|
2597
|
-
const target = attr.name.slice(FIELD_ATTR_PREFIX.length);
|
|
2598
|
-
const dotted = target.includes(".");
|
|
2599
|
-
const attrTarget = dotted ? target.split(".").pop() : target;
|
|
2600
|
-
const placementOnly = !attr.value || dotted && !el.hasAttribute(attrTarget);
|
|
2601
|
-
if (attr.value.trimStart().startsWith("{") || placementOnly) {
|
|
2602
|
-
if (target && target !== "name") jsonFieldNames.push(target);
|
|
2603
|
-
} else {
|
|
2604
|
-
const fieldName = attr.value.trim();
|
|
2605
|
-
if (fieldName) attrBoundNames.add(fieldName);
|
|
2606
|
-
}
|
|
2607
|
-
}
|
|
2608
|
-
return jsonFieldNames.some((name) => !attrBoundNames.has(name));
|
|
2609
|
-
};
|
|
2610
|
-
var ownsItsChildren = (el) => el.hasAttribute("data-puck-slot") || el.hasAttribute("data-puck-field-name") || el.hasAttribute("data-puck-array") || hasJsonFieldBinding(el);
|
|
2611
|
-
var syncAttributes = (target, source) => {
|
|
2612
|
-
const isSlot = target.hasAttribute("data-puck-slot");
|
|
2613
|
-
for (const attr of Array.from(target.attributes)) {
|
|
2614
|
-
if (PROTECTED_ATTRS.has(attr.name)) continue;
|
|
2615
|
-
if (isSlot && SLOT_OWNED_ATTRS.has(attr.name)) continue;
|
|
2616
|
-
if (isEventHandlerAttr(attr.name) || !source.hasAttribute(attr.name)) {
|
|
2617
|
-
target.removeAttribute(attr.name);
|
|
2618
|
-
}
|
|
2619
|
-
}
|
|
2620
|
-
for (const attr of Array.from(source.attributes)) {
|
|
2621
|
-
if (PROTECTED_ATTRS.has(attr.name)) continue;
|
|
2622
|
-
if (isSlot && SLOT_OWNED_ATTRS.has(attr.name)) continue;
|
|
2623
|
-
if (isEventHandlerAttr(attr.name)) continue;
|
|
2624
|
-
if (target.getAttribute(attr.name) !== attr.value) {
|
|
2625
|
-
target.setAttribute(attr.name, attr.value);
|
|
2626
|
-
}
|
|
2627
|
-
}
|
|
2628
|
-
};
|
|
2629
|
-
var isSameKind = (a, b) => a.nodeType === b.nodeType && (a.nodeType !== Node.ELEMENT_NODE || a.tagName === b.tagName);
|
|
2630
|
-
var isIncompleteTagArtifact = (node) => node.nodeType === Node.TEXT_NODE && /^<\/?[a-zA-Z]*$/.test(node.nodeValue ?? "");
|
|
2631
|
-
var stripIncompleteTagArtifacts = (root) => {
|
|
2632
|
-
for (const child of Array.from(root.childNodes)) {
|
|
2633
|
-
if (isIncompleteTagArtifact(child)) {
|
|
2634
|
-
root.removeChild(child);
|
|
2635
|
-
} else if (child.nodeType === Node.ELEMENT_NODE) {
|
|
2636
|
-
stripIncompleteTagArtifacts(child);
|
|
2637
|
-
}
|
|
2638
|
-
}
|
|
2639
|
-
};
|
|
2640
|
-
var stripEventHandlerAttrs = (root) => {
|
|
2641
|
-
root.querySelectorAll("*").forEach((el) => {
|
|
2642
|
-
for (const attr of Array.from(el.attributes)) {
|
|
2643
|
-
if (isEventHandlerAttr(attr.name)) el.removeAttribute(attr.name);
|
|
2644
|
-
}
|
|
2645
|
-
});
|
|
2646
|
-
};
|
|
2647
|
-
var morphChildren = (target, source, skipChildrenOf = ownsItsChildren) => {
|
|
2648
|
-
const sourceChildren = Array.from(source.childNodes);
|
|
2649
|
-
for (let i = 0; i < sourceChildren.length; i++) {
|
|
2650
|
-
const sourceChild = sourceChildren[i];
|
|
2651
|
-
const targetChild = target.childNodes[i];
|
|
2652
|
-
if (!targetChild) {
|
|
2653
|
-
target.appendChild(sourceChild);
|
|
2654
|
-
continue;
|
|
2655
|
-
}
|
|
2656
|
-
if (!isSameKind(targetChild, sourceChild)) {
|
|
2657
|
-
target.replaceChild(sourceChild, targetChild);
|
|
2658
|
-
continue;
|
|
2659
|
-
}
|
|
2660
|
-
if (sourceChild.nodeType !== Node.ELEMENT_NODE) {
|
|
2661
|
-
if (targetChild.nodeValue !== sourceChild.nodeValue) {
|
|
2662
|
-
targetChild.nodeValue = sourceChild.nodeValue;
|
|
2663
|
-
}
|
|
2664
|
-
continue;
|
|
2665
|
-
}
|
|
2666
|
-
const targetEl = targetChild;
|
|
2667
|
-
syncAttributes(targetEl, sourceChild);
|
|
2668
|
-
if (!skipChildrenOf(targetEl)) {
|
|
2669
|
-
morphChildren(targetEl, sourceChild, skipChildrenOf);
|
|
2670
|
-
}
|
|
2671
|
-
}
|
|
2672
|
-
while (target.childNodes.length > sourceChildren.length) {
|
|
2673
|
-
target.removeChild(target.lastChild);
|
|
2674
|
-
}
|
|
2675
|
-
};
|
|
2676
|
-
function morphHtml(container, html, attrOverrides = [], skipChildrenOf = ownsItsChildren) {
|
|
2677
|
-
const template = container.ownerDocument.createElement("template");
|
|
2678
|
-
template.innerHTML = html;
|
|
2679
|
-
stripIncompleteTagArtifacts(template.content);
|
|
2680
|
-
stripEventHandlerAttrs(template.content);
|
|
2681
|
-
if (attrOverrides.length > 0) {
|
|
2682
|
-
const overridesByAttr = /* @__PURE__ */ new Map();
|
|
2683
|
-
for (const override of attrOverrides) {
|
|
2684
|
-
if (isEventHandlerAttr(override.attr)) continue;
|
|
2685
|
-
const bindingAttr = `${FIELD_ATTR_PREFIX}${override.attr}`;
|
|
2686
|
-
const fields = overridesByAttr.get(bindingAttr) ?? /* @__PURE__ */ new Map();
|
|
2687
|
-
fields.set(override.name, override);
|
|
2688
|
-
overridesByAttr.set(bindingAttr, fields);
|
|
2689
|
-
}
|
|
2690
|
-
template.content.querySelectorAll("*").forEach((el) => {
|
|
2691
|
-
for (const attr of Array.from(el.attributes)) {
|
|
2692
|
-
const override = overridesByAttr.get(attr.name)?.get(attr.value.trim());
|
|
2693
|
-
if (!override) continue;
|
|
2694
|
-
if (el.closest("[data-puck-array]")) return;
|
|
2695
|
-
el.setAttribute(override.attr, override.value);
|
|
2696
|
-
}
|
|
2697
|
-
});
|
|
2698
|
-
}
|
|
2699
|
-
morphChildren(container, template.content, skipChildrenOf);
|
|
2700
|
-
}
|
|
2701
2669
|
|
|
2702
|
-
// src/lib/design/
|
|
2670
|
+
// src/lib/design/annotations.ts
|
|
2703
2671
|
init_react_import();
|
|
2704
|
-
var wrapScriptWithObserverGuard = (script) => {
|
|
2705
|
-
if (!script.includes("MutationObserver")) return script;
|
|
2706
|
-
return `(function () {
|
|
2707
|
-
var __NativeMutationObserver = window.MutationObserver;
|
|
2708
|
-
function MutationObserver(callback) {
|
|
2709
|
-
var observed = [];
|
|
2710
|
-
var inner = new __NativeMutationObserver(function (records) {
|
|
2711
|
-
inner.disconnect();
|
|
2712
|
-
try {
|
|
2713
|
-
callback(records, inner);
|
|
2714
|
-
} finally {
|
|
2715
|
-
for (var i = 0; i < observed.length; i++) {
|
|
2716
|
-
__nativeObserve.call(inner, observed[i][0], observed[i][1]);
|
|
2717
|
-
}
|
|
2718
|
-
}
|
|
2719
|
-
});
|
|
2720
|
-
var __nativeObserve = inner.observe;
|
|
2721
|
-
inner.observe = function (target, options) {
|
|
2722
|
-
observed.push([target, options]);
|
|
2723
|
-
return __nativeObserve.call(inner, target, options);
|
|
2724
|
-
};
|
|
2725
|
-
return inner;
|
|
2726
|
-
}
|
|
2727
|
-
${script}
|
|
2728
|
-
})();`;
|
|
2729
|
-
};
|
|
2730
2672
|
|
|
2731
2673
|
// src/lib/html-annotations.ts
|
|
2732
2674
|
init_react_import();
|
|
2733
2675
|
import { parseDocument } from "htmlparser2";
|
|
2734
2676
|
import { appendChild, getInnerHTML, getOuterHTML, textContent } from "domutils";
|
|
2735
2677
|
import { Text } from "domhandler";
|
|
2736
|
-
var
|
|
2678
|
+
var FIELD_ATTR_PREFIX = "data-puck-field-";
|
|
2737
2679
|
var OPTIONS_ATTR_PREFIX = "data-puck-options-";
|
|
2738
2680
|
var BIND_ATTR_PREFIX = "data-puck-bind-";
|
|
2739
2681
|
var BIND_INPUT_ATTR_PREFIX = "data-puck-bind-input-";
|
|
@@ -2743,26 +2685,21 @@ var MAX_ATTR_PREFIX = "data-puck-max-";
|
|
|
2743
2685
|
var STEP_ATTR_PREFIX = "data-puck-step-";
|
|
2744
2686
|
var SLOT_ATTR = "data-puck-slot";
|
|
2745
2687
|
var ARRAY_ATTR = "data-puck-array";
|
|
2746
|
-
var
|
|
2688
|
+
var RECOGNIZED_FIELD_TYPES = /* @__PURE__ */ new Set([
|
|
2747
2689
|
"text",
|
|
2748
2690
|
"textarea",
|
|
2749
2691
|
"number",
|
|
2750
2692
|
"richtext",
|
|
2751
2693
|
"radio",
|
|
2752
2694
|
"select",
|
|
2753
|
-
"slot"
|
|
2754
|
-
"array",
|
|
2755
|
-
"object",
|
|
2756
|
-
"external",
|
|
2757
|
-
"custom"
|
|
2695
|
+
"slot"
|
|
2758
2696
|
]);
|
|
2759
|
-
var
|
|
2760
|
-
|
|
2761
|
-
const trimmed = attrValue.trimStart();
|
|
2697
|
+
var tryParseFieldShape = (value) => {
|
|
2698
|
+
const trimmed = value.trimStart();
|
|
2762
2699
|
if (!trimmed.startsWith("{")) return null;
|
|
2763
2700
|
try {
|
|
2764
2701
|
const parsed = JSON.parse(trimmed);
|
|
2765
|
-
if (isRecord(parsed) && typeof parsed.type === "string" && parsed.type) {
|
|
2702
|
+
if (isRecord(parsed) && typeof parsed.type === "string" && RECOGNIZED_FIELD_TYPES.has(parsed.type)) {
|
|
2766
2703
|
return parsed;
|
|
2767
2704
|
}
|
|
2768
2705
|
} catch {
|
|
@@ -2786,6 +2723,19 @@ var textContentWithBreaks = (node) => {
|
|
|
2786
2723
|
var isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2787
2724
|
var FIELD_NAME_RE = /^[A-Za-z0-9_]+(?:[-.][A-Za-z0-9_]+)*$/;
|
|
2788
2725
|
var isValidFieldName = (name) => FIELD_NAME_RE.test(name);
|
|
2726
|
+
var isFieldNameClaimed = (name, claimed, includeExact = true) => {
|
|
2727
|
+
for (const entry of claimed) {
|
|
2728
|
+
if (includeExact && entry === name || entry.startsWith(`${name}.`) || name.startsWith(`${entry}.`)) {
|
|
2729
|
+
return true;
|
|
2730
|
+
}
|
|
2731
|
+
}
|
|
2732
|
+
return false;
|
|
2733
|
+
};
|
|
2734
|
+
var attrBoundFieldNames = (attribs) => new Set(
|
|
2735
|
+
Object.entries(attribs).filter(
|
|
2736
|
+
([name, value]) => name.startsWith(FIELD_ATTR_PREFIX) && name !== `${FIELD_ATTR_PREFIX}name` && !name.startsWith(`${FIELD_ATTR_PREFIX}value-`) && !tryParseFieldShape(value)
|
|
2737
|
+
).map(([, value]) => value.trim()).filter(isValidFieldName)
|
|
2738
|
+
);
|
|
2789
2739
|
var getDeepValue = (source, path) => {
|
|
2790
2740
|
if (!path.includes(".")) return source[path];
|
|
2791
2741
|
let current = source;
|
|
@@ -2850,8 +2800,7 @@ var getNumberConstraints = (attribs, name) => {
|
|
|
2850
2800
|
if (step !== void 0) constraints.step = step;
|
|
2851
2801
|
return constraints;
|
|
2852
2802
|
};
|
|
2853
|
-
var createAccumulator = (
|
|
2854
|
-
known,
|
|
2803
|
+
var createAccumulator = () => ({
|
|
2855
2804
|
fields: [],
|
|
2856
2805
|
values: {},
|
|
2857
2806
|
seenFields: /* @__PURE__ */ new Set(),
|
|
@@ -2887,6 +2836,7 @@ var collectElementFields = (element, acc) => {
|
|
|
2887
2836
|
return true;
|
|
2888
2837
|
}
|
|
2889
2838
|
let skipChildren = false;
|
|
2839
|
+
const attrBound = attrBoundFieldNames(attribs);
|
|
2890
2840
|
for (const [attrName, attrValue] of Object.entries(attribs)) {
|
|
2891
2841
|
if (attrName.startsWith(OPTIONS_ATTR_PREFIX)) {
|
|
2892
2842
|
const fieldName = attrName.slice(OPTIONS_ATTR_PREFIX.length);
|
|
@@ -2915,11 +2865,9 @@ var collectElementFields = (element, acc) => {
|
|
|
2915
2865
|
}
|
|
2916
2866
|
continue;
|
|
2917
2867
|
}
|
|
2918
|
-
if (!attrName.startsWith(
|
|
2919
|
-
const target = attrName.slice(
|
|
2868
|
+
if (!attrName.startsWith(FIELD_ATTR_PREFIX)) continue;
|
|
2869
|
+
const target = attrName.slice(FIELD_ATTR_PREFIX.length);
|
|
2920
2870
|
if (!target) continue;
|
|
2921
|
-
const dotted = target.includes(".");
|
|
2922
|
-
const attrTarget = dotted ? target.split(".").pop() : target;
|
|
2923
2871
|
const shape = tryParseFieldShape(attrValue);
|
|
2924
2872
|
if (shape) {
|
|
2925
2873
|
if (shape.type === "slot") continue;
|
|
@@ -2932,17 +2880,11 @@ var collectElementFields = (element, acc) => {
|
|
|
2932
2880
|
if (existing) existing.shape = shape;
|
|
2933
2881
|
continue;
|
|
2934
2882
|
}
|
|
2883
|
+
if (isFieldNameClaimed(name2, attrBound, false) || isFieldNameClaimed(name2, acc.seenFields)) {
|
|
2884
|
+
continue;
|
|
2885
|
+
}
|
|
2935
2886
|
acc.seenFields.add(name2);
|
|
2936
|
-
if (
|
|
2937
|
-
const { type, ...value } = shape;
|
|
2938
|
-
acc.fields.push({
|
|
2939
|
-
name: name2,
|
|
2940
|
-
binding: "text",
|
|
2941
|
-
shape: { type },
|
|
2942
|
-
format: "json"
|
|
2943
|
-
});
|
|
2944
|
-
setExtractedValue(acc.values, name2, value);
|
|
2945
|
-
} else if (shape.type === "richtext") {
|
|
2887
|
+
if (shape.type === "richtext") {
|
|
2946
2888
|
acc.fields.push({ name: name2, binding: "text", shape, format: "json" });
|
|
2947
2889
|
setExtractedValue(acc.values, name2, getInnerHTML(element).trim());
|
|
2948
2890
|
skipChildren = true;
|
|
@@ -2964,26 +2906,6 @@ var collectElementFields = (element, acc) => {
|
|
|
2964
2906
|
}
|
|
2965
2907
|
continue;
|
|
2966
2908
|
}
|
|
2967
|
-
if ((!attrValue || dotted && !(attrTarget in attribs)) && isValidFieldName(target)) {
|
|
2968
|
-
if (acc.seenFields.has(target)) continue;
|
|
2969
|
-
acc.seenFields.add(target);
|
|
2970
|
-
const knownShape = getFieldShapeAt(acc.known, target);
|
|
2971
|
-
acc.fields.push({
|
|
2972
|
-
name: target,
|
|
2973
|
-
binding: "text",
|
|
2974
|
-
format: "json",
|
|
2975
|
-
...knownShape ? { shape: knownShape } : {}
|
|
2976
|
-
});
|
|
2977
|
-
const asHtml = knownShape ? knownShape.type === "richtext" : element.children.some(isElement);
|
|
2978
|
-
if (asHtml) {
|
|
2979
|
-
setExtractedValue(acc.values, target, getInnerHTML(element).trim());
|
|
2980
|
-
skipChildren = true;
|
|
2981
|
-
} else {
|
|
2982
|
-
const text = collapseWhitespace(textContentWithBreaks(element));
|
|
2983
|
-
if (text) setExtractedValue(acc.values, target, text);
|
|
2984
|
-
}
|
|
2985
|
-
continue;
|
|
2986
|
-
}
|
|
2987
2909
|
const name = attrValue.trim();
|
|
2988
2910
|
if (!name) continue;
|
|
2989
2911
|
if (!isValidFieldName(name)) continue;
|
|
@@ -2997,7 +2919,7 @@ var collectElementFields = (element, acc) => {
|
|
|
2997
2919
|
acc.fields[idx] = {
|
|
2998
2920
|
name,
|
|
2999
2921
|
binding: "attr",
|
|
3000
|
-
attr:
|
|
2922
|
+
attr: target,
|
|
3001
2923
|
shape: prev.shape
|
|
3002
2924
|
};
|
|
3003
2925
|
const segments = name.split(".");
|
|
@@ -3010,11 +2932,14 @@ var collectElementFields = (element, acc) => {
|
|
|
3010
2932
|
break;
|
|
3011
2933
|
}
|
|
3012
2934
|
}
|
|
3013
|
-
current[segments[segments.length - 1]] = attribs[
|
|
2935
|
+
current[segments[segments.length - 1]] = attribs[target] ?? "";
|
|
3014
2936
|
}
|
|
3015
2937
|
}
|
|
3016
2938
|
continue;
|
|
3017
2939
|
}
|
|
2940
|
+
if (target === "name" && isFieldNameClaimed(name, attrBound) || isFieldNameClaimed(name, acc.seenFields)) {
|
|
2941
|
+
continue;
|
|
2942
|
+
}
|
|
3018
2943
|
acc.seenFields.add(name);
|
|
3019
2944
|
const fieldType = getTypeModifier(attribs, name);
|
|
3020
2945
|
const constraints = fieldType === "number" ? getNumberConstraints(attribs, name) : {};
|
|
@@ -3048,11 +2973,11 @@ var collectElementFields = (element, acc) => {
|
|
|
3048
2973
|
acc.fields.push({
|
|
3049
2974
|
name,
|
|
3050
2975
|
binding: "attr",
|
|
3051
|
-
attr:
|
|
2976
|
+
attr: target,
|
|
3052
2977
|
fieldType,
|
|
3053
2978
|
...constraints
|
|
3054
2979
|
});
|
|
3055
|
-
const value = parseNumber(attribs[
|
|
2980
|
+
const value = parseNumber(attribs[target]);
|
|
3056
2981
|
if (value !== void 0) {
|
|
3057
2982
|
setExtractedValue(acc.values, name, value);
|
|
3058
2983
|
}
|
|
@@ -3060,10 +2985,10 @@ var collectElementFields = (element, acc) => {
|
|
|
3060
2985
|
acc.fields.push({
|
|
3061
2986
|
name,
|
|
3062
2987
|
binding: "attr",
|
|
3063
|
-
attr:
|
|
2988
|
+
attr: target,
|
|
3064
2989
|
...fieldType && fieldType !== "richtext" ? { fieldType } : {}
|
|
3065
2990
|
});
|
|
3066
|
-
setExtractedValue(acc.values, name, attribs[
|
|
2991
|
+
setExtractedValue(acc.values, name, attribs[target] ?? "");
|
|
3067
2992
|
}
|
|
3068
2993
|
}
|
|
3069
2994
|
}
|
|
@@ -3088,16 +3013,7 @@ var attachOptions = (acc) => {
|
|
|
3088
3013
|
return options ? { ...field, options } : field;
|
|
3089
3014
|
});
|
|
3090
3015
|
};
|
|
3091
|
-
var
|
|
3092
|
-
const segments = name.split(".");
|
|
3093
|
-
let cursor = shapes;
|
|
3094
|
-
for (let i = 0; i < segments.length - 1; i++) {
|
|
3095
|
-
cursor = cursor?.[segments[i]]?.objectFields;
|
|
3096
|
-
}
|
|
3097
|
-
const shape = cursor?.[segments[segments.length - 1]];
|
|
3098
|
-
return shape && shape.type !== "object" ? shape : void 0;
|
|
3099
|
-
};
|
|
3100
|
-
var parseHtmlAnnotations = (html, known) => {
|
|
3016
|
+
var parseHtmlAnnotations = (html) => {
|
|
3101
3017
|
const annotations = {
|
|
3102
3018
|
fields: [],
|
|
3103
3019
|
slots: [],
|
|
@@ -3106,7 +3022,7 @@ var parseHtmlAnnotations = (html, known) => {
|
|
|
3106
3022
|
bindInputs: {}
|
|
3107
3023
|
};
|
|
3108
3024
|
if (!html) return annotations;
|
|
3109
|
-
const acc = createAccumulator(
|
|
3025
|
+
const acc = createAccumulator();
|
|
3110
3026
|
const seenSlots = /* @__PURE__ */ new Set();
|
|
3111
3027
|
const walk = (nodes) => {
|
|
3112
3028
|
for (const node of nodes) {
|
|
@@ -3117,7 +3033,7 @@ var parseHtmlAnnotations = (html, known) => {
|
|
|
3117
3033
|
if (slotName && isValidFieldName(slotName) && !seenSlots.has(slotName)) {
|
|
3118
3034
|
seenSlots.add(slotName);
|
|
3119
3035
|
const shape = tryParseFieldShape(
|
|
3120
|
-
attribs[
|
|
3036
|
+
attribs[FIELD_ATTR_PREFIX + slotName.toLowerCase()] ?? ""
|
|
3121
3037
|
);
|
|
3122
3038
|
const allow = shape?.type === "slot" ? sanitizeStringArray(shape.allow) : void 0;
|
|
3123
3039
|
const disallow = shape?.type === "slot" ? sanitizeStringArray(shape.disallow) : void 0;
|
|
@@ -3266,21 +3182,16 @@ var patchElement = (element, props) => {
|
|
|
3266
3182
|
}
|
|
3267
3183
|
return { didPatch, skipChildren: true };
|
|
3268
3184
|
}
|
|
3269
|
-
const attrBoundFields =
|
|
3270
|
-
for (const [an, av] of Object.entries(attribs)) {
|
|
3271
|
-
if (an.startsWith(FIELD_ATTR_PREFIX2) && an !== `${FIELD_ATTR_PREFIX2}name` && !tryParseFieldShape(av)) {
|
|
3272
|
-
attrBoundFields.add(av.trim());
|
|
3273
|
-
}
|
|
3274
|
-
}
|
|
3185
|
+
const attrBoundFields = attrBoundFieldNames(attribs);
|
|
3275
3186
|
for (const [attrName, attrValue] of Object.entries(attribs)) {
|
|
3276
|
-
if (!attrName.startsWith(
|
|
3277
|
-
const target = attrName.slice(
|
|
3187
|
+
if (!attrName.startsWith(FIELD_ATTR_PREFIX)) continue;
|
|
3188
|
+
const target = attrName.slice(FIELD_ATTR_PREFIX.length);
|
|
3278
3189
|
if (!target) continue;
|
|
3279
3190
|
const shape = tryParseFieldShape(attrValue);
|
|
3280
3191
|
if (shape) {
|
|
3281
3192
|
if (shape.type === "slot") continue;
|
|
3282
3193
|
const name2 = target;
|
|
3283
|
-
if (
|
|
3194
|
+
if (isFieldNameClaimed(name2, attrBoundFields)) continue;
|
|
3284
3195
|
const value2 = getDeepValue(props, name2);
|
|
3285
3196
|
if (shape.type === "richtext") {
|
|
3286
3197
|
if (typeof value2 !== "string") continue;
|
|
@@ -3296,27 +3207,11 @@ var patchElement = (element, props) => {
|
|
|
3296
3207
|
element.children = [text];
|
|
3297
3208
|
continue;
|
|
3298
3209
|
}
|
|
3299
|
-
const dotted = target.includes(".");
|
|
3300
|
-
const attrTarget = dotted ? target.split(".").pop() : target;
|
|
3301
|
-
if (!attrValue || dotted && !(attrTarget in attribs)) {
|
|
3302
|
-
if (attrBoundFields.has(target)) continue;
|
|
3303
|
-
const value2 = getDeepValue(props, target);
|
|
3304
|
-
if (element.children.some(isElement)) {
|
|
3305
|
-
if (typeof value2 !== "string") continue;
|
|
3306
|
-
replaceChildrenWithHtml(element, value2);
|
|
3307
|
-
didPatch = true;
|
|
3308
|
-
skipChildren = true;
|
|
3309
|
-
continue;
|
|
3310
|
-
}
|
|
3311
|
-
if (!isPatchablePrimitive(value2)) continue;
|
|
3312
|
-
didPatch = true;
|
|
3313
|
-
const text = new Text(String(value2));
|
|
3314
|
-
text.parent = element;
|
|
3315
|
-
element.children = [text];
|
|
3316
|
-
continue;
|
|
3317
|
-
}
|
|
3318
3210
|
const name = attrValue.trim();
|
|
3319
3211
|
if (!name) continue;
|
|
3212
|
+
if (target === "name" && isFieldNameClaimed(name, attrBoundFields)) {
|
|
3213
|
+
continue;
|
|
3214
|
+
}
|
|
3320
3215
|
const value = getDeepValue(props, name);
|
|
3321
3216
|
if (target === "name" && getTypeModifier(attribs, name) === "richtext") {
|
|
3322
3217
|
if (typeof value !== "string") continue;
|
|
@@ -3332,7 +3227,7 @@ var patchElement = (element, props) => {
|
|
|
3332
3227
|
text.parent = element;
|
|
3333
3228
|
element.children = [text];
|
|
3334
3229
|
} else {
|
|
3335
|
-
attribs[
|
|
3230
|
+
attribs[target] = String(value);
|
|
3336
3231
|
}
|
|
3337
3232
|
}
|
|
3338
3233
|
return { didPatch, skipChildren };
|
|
@@ -3389,188 +3284,175 @@ var renderHtmlArrayItems = (html, arrayName, items) => {
|
|
|
3389
3284
|
};
|
|
3390
3285
|
|
|
3391
3286
|
// src/lib/design/annotations.ts
|
|
3392
|
-
init_react_import();
|
|
3393
3287
|
var cache = /* @__PURE__ */ new Map();
|
|
3394
|
-
var shapeSignature = (shapes) => Object.entries(shapes).map(([name, shape]) => `${name}:${shape?.type ?? ""}`).join(",");
|
|
3395
3288
|
var MAX_CACHE_ENTRIES = 32;
|
|
3396
|
-
var getAnnotations = (html
|
|
3397
|
-
const
|
|
3398
|
-
const cached = cache.get(key);
|
|
3289
|
+
var getAnnotations = (html) => {
|
|
3290
|
+
const cached = cache.get(html);
|
|
3399
3291
|
if (cached) return cached;
|
|
3400
|
-
const parsed = parseHtmlAnnotations(html
|
|
3292
|
+
const parsed = parseHtmlAnnotations(html);
|
|
3401
3293
|
if (cache.size >= MAX_CACHE_ENTRIES) {
|
|
3402
3294
|
cache.delete(cache.keys().next().value);
|
|
3403
3295
|
}
|
|
3404
|
-
cache.set(
|
|
3296
|
+
cache.set(html, parsed);
|
|
3405
3297
|
return parsed;
|
|
3406
3298
|
};
|
|
3407
3299
|
var getSlotFields = (html) => Object.fromEntries(
|
|
3408
3300
|
getAnnotations(html).slots.map((slot) => [slot.name, toSlotField(slot)])
|
|
3409
3301
|
);
|
|
3410
|
-
var UNTRANSFORMABLE_FIELD_TYPES = /* @__PURE__ */ new Set(["richtext", "array", "slot"]);
|
|
3411
|
-
var isTransformable = (field) => {
|
|
3412
|
-
if (!field?.type) return false;
|
|
3413
|
-
if (UNTRANSFORMABLE_FIELD_TYPES.has(field.type)) return false;
|
|
3414
|
-
const nested = field.objectFields ?? field.arrayFields;
|
|
3415
|
-
return nested ? Object.values(nested).every(isTransformable) : true;
|
|
3416
|
-
};
|
|
3417
|
-
var getTransformableFields = (reg) => {
|
|
3418
|
-
const annotations = getAnnotations(reg.html ?? "", reg.fields);
|
|
3419
|
-
const source = {
|
|
3420
|
-
...toPuckFields(annotations.fields, annotations.values),
|
|
3421
|
-
...reg.fields ?? {}
|
|
3422
|
-
};
|
|
3423
|
-
return Object.fromEntries(
|
|
3424
|
-
Object.entries(source).filter(([, field]) => isTransformable(field))
|
|
3425
|
-
);
|
|
3426
|
-
};
|
|
3427
|
-
|
|
3428
|
-
// src/lib/field-types.ts
|
|
3429
|
-
init_react_import();
|
|
3430
3302
|
|
|
3431
|
-
// src/lib/
|
|
3432
|
-
|
|
3433
|
-
|
|
3434
|
-
"
|
|
3435
|
-
|
|
3436
|
-
|
|
3437
|
-
|
|
3438
|
-
|
|
3439
|
-
|
|
3440
|
-
|
|
3441
|
-
|
|
3442
|
-
|
|
3303
|
+
// src/lib/morph-html.ts
|
|
3304
|
+
var PROTECTED_ATTRS = /* @__PURE__ */ new Set([
|
|
3305
|
+
"contenteditable",
|
|
3306
|
+
"data-puck-overlay-portal"
|
|
3307
|
+
]);
|
|
3308
|
+
var SLOT_OWNED_ATTRS = /* @__PURE__ */ new Set(["style", "class"]);
|
|
3309
|
+
var isEventHandlerAttr = (name) => /^on/i.test(name);
|
|
3310
|
+
var FIELD_ATTR_PREFIX2 = "data-puck-field-";
|
|
3311
|
+
var LEGACY_TEXT_ATTR = `${FIELD_ATTR_PREFIX2}name`;
|
|
3312
|
+
var VALUE_ATTR_PREFIX = `${FIELD_ATTR_PREFIX2}value-`;
|
|
3313
|
+
var hasTextBinding = (el, parsedTextFields) => {
|
|
3314
|
+
for (const attr of Array.from(el.attributes)) {
|
|
3315
|
+
if (!attr.name.startsWith(FIELD_ATTR_PREFIX2)) continue;
|
|
3316
|
+
if (attr.name.startsWith(VALUE_ATTR_PREFIX)) continue;
|
|
3317
|
+
const isShape = attr.value.trimStart().startsWith("{");
|
|
3318
|
+
const fieldName = isShape ? attr.name.slice(FIELD_ATTR_PREFIX2.length) : attr.value.trim();
|
|
3319
|
+
if (isValidFieldName(fieldName) && (attr.name === LEGACY_TEXT_ATTR || isShape) && (!parsedTextFields || parsedTextFields.has(fieldName))) {
|
|
3320
|
+
return true;
|
|
3321
|
+
}
|
|
3322
|
+
}
|
|
3323
|
+
return false;
|
|
3443
3324
|
};
|
|
3444
|
-
var
|
|
3445
|
-
|
|
3446
|
-
|
|
3447
|
-
|
|
3448
|
-
|
|
3449
|
-
|
|
3325
|
+
var ownsItsChildren = (el, parsedTextFields) => el.hasAttribute("data-puck-slot") || el.hasAttribute("data-puck-array") || hasTextBinding(el, parsedTextFields);
|
|
3326
|
+
var syncAttributes = (target, source) => {
|
|
3327
|
+
const isSlot = target.hasAttribute("data-puck-slot");
|
|
3328
|
+
for (const attr of Array.from(target.attributes)) {
|
|
3329
|
+
if (PROTECTED_ATTRS.has(attr.name)) continue;
|
|
3330
|
+
if (isSlot && SLOT_OWNED_ATTRS.has(attr.name)) continue;
|
|
3331
|
+
if (isEventHandlerAttr(attr.name) || !source.hasAttribute(attr.name)) {
|
|
3332
|
+
target.removeAttribute(attr.name);
|
|
3333
|
+
}
|
|
3334
|
+
}
|
|
3335
|
+
for (const attr of Array.from(source.attributes)) {
|
|
3336
|
+
if (PROTECTED_ATTRS.has(attr.name)) continue;
|
|
3337
|
+
if (isSlot && SLOT_OWNED_ATTRS.has(attr.name)) continue;
|
|
3338
|
+
if (isEventHandlerAttr(attr.name)) continue;
|
|
3339
|
+
if (target.getAttribute(attr.name) !== attr.value) {
|
|
3340
|
+
target.setAttribute(attr.name, attr.value);
|
|
3341
|
+
}
|
|
3342
|
+
}
|
|
3450
3343
|
};
|
|
3451
|
-
var
|
|
3452
|
-
|
|
3453
|
-
|
|
3344
|
+
var isSameKind = (a, b) => a.nodeType === b.nodeType && (a.nodeType !== Node.ELEMENT_NODE || a.tagName === b.tagName);
|
|
3345
|
+
var isIncompleteTagArtifact = (node) => node.nodeType === Node.TEXT_NODE && /^<\/?[a-zA-Z]*$/.test(node.nodeValue ?? "");
|
|
3346
|
+
var stripIncompleteTagArtifacts = (root) => {
|
|
3347
|
+
for (const child of Array.from(root.childNodes)) {
|
|
3348
|
+
if (isIncompleteTagArtifact(child)) {
|
|
3349
|
+
root.removeChild(child);
|
|
3350
|
+
} else if (child.nodeType === Node.ELEMENT_NODE) {
|
|
3351
|
+
stripIncompleteTagArtifacts(child);
|
|
3352
|
+
}
|
|
3454
3353
|
}
|
|
3455
|
-
if (key && NAME_EXAMPLES[key]) return NAME_EXAMPLES[key];
|
|
3456
|
-
if (typeof schema.pattern === "string") return `<matching ${schema.pattern}>`;
|
|
3457
|
-
return "Example";
|
|
3458
3354
|
};
|
|
3459
|
-
var
|
|
3460
|
-
|
|
3461
|
-
|
|
3462
|
-
|
|
3463
|
-
|
|
3464
|
-
|
|
3465
|
-
value = Math.ceil(value / multipleOf) * multipleOf;
|
|
3466
|
-
}
|
|
3467
|
-
if (typeof maximum === "number" && value > maximum) value = maximum;
|
|
3468
|
-
if (typeof exclusiveMaximum === "number" && value >= exclusiveMaximum) {
|
|
3469
|
-
value = exclusiveMaximum - (isInteger ? 1 : step);
|
|
3470
|
-
}
|
|
3471
|
-
return isInteger ? Math.round(value) : value;
|
|
3355
|
+
var stripEventHandlerAttrs = (root) => {
|
|
3356
|
+
root.querySelectorAll("*").forEach((el) => {
|
|
3357
|
+
for (const attr of Array.from(el.attributes)) {
|
|
3358
|
+
if (isEventHandlerAttr(attr.name)) el.removeAttribute(attr.name);
|
|
3359
|
+
}
|
|
3360
|
+
});
|
|
3472
3361
|
};
|
|
3473
|
-
var
|
|
3474
|
-
|
|
3475
|
-
|
|
3476
|
-
|
|
3477
|
-
|
|
3478
|
-
|
|
3479
|
-
|
|
3480
|
-
|
|
3481
|
-
if (Array.isArray(schema.anyOf) && schema.anyOf.length > 0) {
|
|
3482
|
-
return jsonSchemaExample(schema.anyOf[0]);
|
|
3483
|
-
}
|
|
3484
|
-
switch (schema.type) {
|
|
3485
|
-
case "string":
|
|
3486
|
-
return stringExample(schema, key);
|
|
3487
|
-
case "number":
|
|
3488
|
-
case "integer":
|
|
3489
|
-
return numberExample(schema);
|
|
3490
|
-
case "boolean":
|
|
3491
|
-
return true;
|
|
3492
|
-
case "array": {
|
|
3493
|
-
const min = typeof schema.minItems === "number" ? schema.minItems : 1;
|
|
3494
|
-
const max = typeof schema.maxItems === "number" ? schema.maxItems : Infinity;
|
|
3495
|
-
const count = Math.max(Math.min(min || 1, max), 0);
|
|
3496
|
-
return Array.from(
|
|
3497
|
-
{ length: count },
|
|
3498
|
-
() => jsonSchemaExample(schema.items, key)
|
|
3499
|
-
);
|
|
3362
|
+
var morphChildren = (target, source, skipChildrenOf = ownsItsChildren) => {
|
|
3363
|
+
const sourceChildren = Array.from(source.childNodes);
|
|
3364
|
+
for (let i = 0; i < sourceChildren.length; i++) {
|
|
3365
|
+
const sourceChild = sourceChildren[i];
|
|
3366
|
+
const targetChild = target.childNodes[i];
|
|
3367
|
+
if (!targetChild) {
|
|
3368
|
+
target.appendChild(sourceChild);
|
|
3369
|
+
continue;
|
|
3500
3370
|
}
|
|
3501
|
-
|
|
3502
|
-
|
|
3503
|
-
|
|
3504
|
-
Object.entries(properties).map(([name, value]) => [
|
|
3505
|
-
name,
|
|
3506
|
-
jsonSchemaExample(value, name)
|
|
3507
|
-
])
|
|
3508
|
-
);
|
|
3371
|
+
if (!isSameKind(targetChild, sourceChild)) {
|
|
3372
|
+
target.replaceChild(sourceChild, targetChild);
|
|
3373
|
+
continue;
|
|
3509
3374
|
}
|
|
3510
|
-
|
|
3511
|
-
|
|
3375
|
+
if (sourceChild.nodeType !== Node.ELEMENT_NODE) {
|
|
3376
|
+
if (targetChild.nodeValue !== sourceChild.nodeValue) {
|
|
3377
|
+
targetChild.nodeValue = sourceChild.nodeValue;
|
|
3378
|
+
}
|
|
3379
|
+
continue;
|
|
3380
|
+
}
|
|
3381
|
+
const targetEl = targetChild;
|
|
3382
|
+
syncAttributes(targetEl, sourceChild);
|
|
3383
|
+
if (!skipChildrenOf(targetEl)) {
|
|
3384
|
+
morphChildren(targetEl, sourceChild, skipChildrenOf);
|
|
3385
|
+
}
|
|
3386
|
+
}
|
|
3387
|
+
while (target.childNodes.length > sourceChildren.length) {
|
|
3388
|
+
target.removeChild(target.lastChild);
|
|
3512
3389
|
}
|
|
3513
3390
|
};
|
|
3391
|
+
function morphHtml(container, html, attrOverrides = [], skipChildrenOf) {
|
|
3392
|
+
const template = container.ownerDocument.createElement("template");
|
|
3393
|
+
template.innerHTML = html;
|
|
3394
|
+
stripIncompleteTagArtifacts(template.content);
|
|
3395
|
+
stripEventHandlerAttrs(template.content);
|
|
3396
|
+
if (attrOverrides.length > 0) {
|
|
3397
|
+
const overridesByAttr = /* @__PURE__ */ new Map();
|
|
3398
|
+
for (const override of attrOverrides) {
|
|
3399
|
+
if (isEventHandlerAttr(override.attr)) continue;
|
|
3400
|
+
const bindingAttr = `${FIELD_ATTR_PREFIX2}${override.attr}`;
|
|
3401
|
+
const fields = overridesByAttr.get(bindingAttr) ?? /* @__PURE__ */ new Map();
|
|
3402
|
+
fields.set(override.name, override);
|
|
3403
|
+
overridesByAttr.set(bindingAttr, fields);
|
|
3404
|
+
}
|
|
3405
|
+
template.content.querySelectorAll("*").forEach((el) => {
|
|
3406
|
+
for (const attr of Array.from(el.attributes)) {
|
|
3407
|
+
const override = overridesByAttr.get(attr.name)?.get(attr.value.trim());
|
|
3408
|
+
if (!override) continue;
|
|
3409
|
+
if (el.closest("[data-puck-array]")) return;
|
|
3410
|
+
el.setAttribute(override.attr, override.value);
|
|
3411
|
+
}
|
|
3412
|
+
});
|
|
3413
|
+
}
|
|
3414
|
+
if (skipChildrenOf) {
|
|
3415
|
+
morphChildren(container, template.content, skipChildrenOf);
|
|
3416
|
+
return;
|
|
3417
|
+
}
|
|
3418
|
+
const parsedTextFields = new Set(
|
|
3419
|
+
getAnnotations(html).fields.filter((field) => field.binding === "text").map((field) => field.name)
|
|
3420
|
+
);
|
|
3421
|
+
morphChildren(
|
|
3422
|
+
container,
|
|
3423
|
+
template.content,
|
|
3424
|
+
(el) => ownsItsChildren(el, parsedTextFields)
|
|
3425
|
+
);
|
|
3426
|
+
}
|
|
3514
3427
|
|
|
3515
|
-
// src/lib/
|
|
3516
|
-
|
|
3517
|
-
|
|
3518
|
-
|
|
3519
|
-
|
|
3520
|
-
|
|
3521
|
-
|
|
3522
|
-
|
|
3523
|
-
|
|
3428
|
+
// src/lib/design/observer-guard.ts
|
|
3429
|
+
init_react_import();
|
|
3430
|
+
var wrapScriptWithObserverGuard = (script) => {
|
|
3431
|
+
if (!script.includes("MutationObserver")) return script;
|
|
3432
|
+
return `(function () {
|
|
3433
|
+
var __NativeMutationObserver = window.MutationObserver;
|
|
3434
|
+
function MutationObserver(callback) {
|
|
3435
|
+
var observed = [];
|
|
3436
|
+
var inner = new __NativeMutationObserver(function (records) {
|
|
3437
|
+
inner.disconnect();
|
|
3438
|
+
try {
|
|
3439
|
+
callback(records, inner);
|
|
3440
|
+
} finally {
|
|
3441
|
+
for (var i = 0; i < observed.length; i++) {
|
|
3442
|
+
__nativeObserve.call(inner, observed[i][0], observed[i][1]);
|
|
3443
|
+
}
|
|
3524
3444
|
}
|
|
3525
|
-
|
|
3526
|
-
|
|
3527
|
-
)
|
|
3528
|
-
|
|
3529
|
-
|
|
3530
|
-
|
|
3531
|
-
|
|
3532
|
-
var getFieldTypes = () => registry;
|
|
3533
|
-
var getFieldTypeDefault = (type, ctx2) => {
|
|
3534
|
-
const fieldType = registry[type];
|
|
3535
|
-
if (!fieldType) return void 0;
|
|
3536
|
-
if (fieldType.defaultValue !== void 0) {
|
|
3537
|
-
return typeof fieldType.defaultValue === "function" ? fieldType.defaultValue(ctx2) : fieldType.defaultValue;
|
|
3538
|
-
}
|
|
3539
|
-
return jsonSchemaExample(fieldType.schema);
|
|
3540
|
-
};
|
|
3541
|
-
var isUnvalued = (value) => value === void 0 || !!value && typeof value === "object" && !Array.isArray(value) && Object.keys(value).length === 0;
|
|
3542
|
-
var fill = (values, fields, componentName, declared, path) => {
|
|
3543
|
-
let out = values;
|
|
3544
|
-
for (const [fieldName, field] of Object.entries(fields ?? {})) {
|
|
3545
|
-
const type = field?.type;
|
|
3546
|
-
if (!type) continue;
|
|
3547
|
-
const qualified = path ? `${path}.${fieldName}` : fieldName;
|
|
3548
|
-
if (registry[type]) {
|
|
3549
|
-
if (!isUnvalued(out[fieldName])) continue;
|
|
3550
|
-
const declaredValue = declared?.[fieldName];
|
|
3551
|
-
const value = isUnvalued(declaredValue) ? getFieldTypeDefault(type, { componentName, fieldName: qualified }) : declaredValue;
|
|
3552
|
-
if (isUnvalued(value)) continue;
|
|
3553
|
-
if (out === values) out = { ...values };
|
|
3554
|
-
out[fieldName] = value;
|
|
3555
|
-
continue;
|
|
3556
|
-
}
|
|
3557
|
-
if (!field.objectFields) continue;
|
|
3558
|
-
const group = out[fieldName];
|
|
3559
|
-
const declaredGroup = declared?.[fieldName];
|
|
3560
|
-
const filled = fill(
|
|
3561
|
-
group && typeof group === "object" ? group : {},
|
|
3562
|
-
field.objectFields,
|
|
3563
|
-
componentName,
|
|
3564
|
-
declaredGroup && typeof declaredGroup === "object" ? declaredGroup : void 0,
|
|
3565
|
-
qualified
|
|
3566
|
-
);
|
|
3567
|
-
if (filled === group) continue;
|
|
3568
|
-
if (out === values) out = { ...values };
|
|
3569
|
-
out[fieldName] = filled;
|
|
3445
|
+
});
|
|
3446
|
+
var __nativeObserve = inner.observe;
|
|
3447
|
+
inner.observe = function (target, options) {
|
|
3448
|
+
observed.push([target, options]);
|
|
3449
|
+
return __nativeObserve.call(inner, target, options);
|
|
3450
|
+
};
|
|
3451
|
+
return inner;
|
|
3570
3452
|
}
|
|
3571
|
-
|
|
3453
|
+
${script}
|
|
3454
|
+
})();`;
|
|
3572
3455
|
};
|
|
3573
|
-
var withFieldTypeDefaults = (values, fields, componentName, declared) => fill(values, fields, componentName, declared, "");
|
|
3574
3456
|
|
|
3575
3457
|
// src/lib/design/registration-store.ts
|
|
3576
3458
|
init_react_import();
|
|
@@ -3645,12 +3527,7 @@ init_react_import();
|
|
|
3645
3527
|
import { registerOverlayPortal, setDeep } from "@puckeditor/core";
|
|
3646
3528
|
var CONTENT_EDITABLE_ATTR = "data-puck-content-editable";
|
|
3647
3529
|
var isInlineEditingDisabled = (el) => el.closest(`[${CONTENT_EDITABLE_ATTR}="false"]`) !== null;
|
|
3648
|
-
var cssEscape = (value) => typeof CSS !== "undefined" && CSS.escape ? CSS.escape(value) : (
|
|
3649
|
-
// Escapes for an IDENTIFIER, not just a quoted value: a dotted field name
|
|
3650
|
-
// sits in the attribute-name slot too, where an unescaped `.` reads as a
|
|
3651
|
-
// class selector and throws. Over-escaping inside quotes is harmless.
|
|
3652
|
-
value.replace(/[^\w-]/g, "\\$&")
|
|
3653
|
-
);
|
|
3530
|
+
var cssEscape = (value) => typeof CSS !== "undefined" && CSS.escape ? CSS.escape(value) : value.replace(/["\\]/g, "\\$&");
|
|
3654
3531
|
var queryScopedFields = (entry, selector) => Array.from(entry.querySelectorAll(selector)).filter((el) => {
|
|
3655
3532
|
if (el.closest("[data-puck-array]")) return false;
|
|
3656
3533
|
const closestSlot = el.closest("[data-puck-slot]");
|
|
@@ -3944,15 +3821,7 @@ var parseStyleString = (cssText) => {
|
|
|
3944
3821
|
return style;
|
|
3945
3822
|
};
|
|
3946
3823
|
var isEventHandlerAttr2 = (name) => /^on/i.test(name);
|
|
3947
|
-
var
|
|
3948
|
-
var fieldContentFor = (attribs, fields) => {
|
|
3949
|
-
for (const name of Object.keys(fields)) {
|
|
3950
|
-
if (attribs[`${FIELD_ATTR_PREFIX3}${name}`] !== void 0) return name;
|
|
3951
|
-
if (attribs["data-puck-field-name"] === name) return name;
|
|
3952
|
-
}
|
|
3953
|
-
return void 0;
|
|
3954
|
-
};
|
|
3955
|
-
var nodeToReact = (node, slots, fields, key) => {
|
|
3824
|
+
var nodeToReact = (node, slots, key) => {
|
|
3956
3825
|
if (node.type === "text") {
|
|
3957
3826
|
return node.data;
|
|
3958
3827
|
}
|
|
@@ -3983,17 +3852,13 @@ var nodeToReact = (node, slots, fields, key) => {
|
|
|
3983
3852
|
if (VOID_ELEMENTS.has(tag)) {
|
|
3984
3853
|
return createElement3(tag, props);
|
|
3985
3854
|
}
|
|
3986
|
-
const
|
|
3987
|
-
if (fieldName !== void 0) {
|
|
3988
|
-
return createElement3(tag, props, fields[fieldName]);
|
|
3989
|
-
}
|
|
3990
|
-
const children = el.children.map((child, i) => nodeToReact(child, slots, fields, i)).filter((c) => c !== null);
|
|
3855
|
+
const children = el.children.map((child, i) => nodeToReact(child, slots, i)).filter((c) => c !== null);
|
|
3991
3856
|
return createElement3(tag, props, ...children);
|
|
3992
3857
|
};
|
|
3993
|
-
var htmlToReactTree = (html, slots
|
|
3858
|
+
var htmlToReactTree = (html, slots) => {
|
|
3994
3859
|
if (!html) return null;
|
|
3995
3860
|
const doc = parseDocument2(html);
|
|
3996
|
-
const children = doc.children.map((child, i) => nodeToReact(child, slots,
|
|
3861
|
+
const children = doc.children.map((child, i) => nodeToReact(child, slots, i)).filter((c) => c !== null);
|
|
3997
3862
|
if (children.length === 0) return null;
|
|
3998
3863
|
if (children.length === 1) return children[0];
|
|
3999
3864
|
return createElement3(Fragment6, null, ...children);
|
|
@@ -4001,9 +3866,9 @@ var htmlToReactTree = (html, slots, fields = {}) => {
|
|
|
4001
3866
|
|
|
4002
3867
|
// src/lib/design/slot-portal.tsx
|
|
4003
3868
|
init_react_import();
|
|
4004
|
-
import { useEffect as
|
|
3869
|
+
import { useEffect as useEffect11, useMemo as useMemo4, useRef as useRef10, useState as useState14 } from "react";
|
|
4005
3870
|
import { createPortal } from "react-dom";
|
|
4006
|
-
import { jsx as
|
|
3871
|
+
import { jsx as jsx30 } from "react/jsx-runtime";
|
|
4007
3872
|
var parseInlineStyle = (cssText) => {
|
|
4008
3873
|
const style = {};
|
|
4009
3874
|
for (const declaration of cssText.split(";")) {
|
|
@@ -4031,7 +3896,7 @@ var SlotPortal = ({
|
|
|
4031
3896
|
() => slotStyle ? parseInlineStyle(slotStyle) : void 0,
|
|
4032
3897
|
[slotStyle]
|
|
4033
3898
|
);
|
|
4034
|
-
|
|
3899
|
+
useEffect11(() => {
|
|
4035
3900
|
const el = entry.querySelector(`[data-puck-slot="${cssEscape(slotName)}"]`);
|
|
4036
3901
|
if (el !== lastTarget.current) {
|
|
4037
3902
|
el?.replaceChildren();
|
|
@@ -4045,37 +3910,15 @@ var SlotPortal = ({
|
|
|
4045
3910
|
}, [entry, html, slotName]);
|
|
4046
3911
|
if (!target || typeof SlotContent !== "function") return null;
|
|
4047
3912
|
return createPortal(
|
|
4048
|
-
/* @__PURE__ */
|
|
3913
|
+
/* @__PURE__ */ jsx30(SlotContent, { style, className: slotClassName || void 0 }),
|
|
4049
3914
|
target
|
|
4050
3915
|
);
|
|
4051
3916
|
};
|
|
4052
3917
|
|
|
4053
|
-
// src/lib/design/field-portal.tsx
|
|
4054
|
-
init_react_import();
|
|
4055
|
-
import { useEffect as useEffect11, useRef as useRef11, useState as useState15 } from "react";
|
|
4056
|
-
import { createPortal as createPortal2 } from "react-dom";
|
|
4057
|
-
var FieldPortal = ({
|
|
4058
|
-
entry,
|
|
4059
|
-
html,
|
|
4060
|
-
selector,
|
|
4061
|
-
children
|
|
4062
|
-
}) => {
|
|
4063
|
-
const [target, setTarget] = useState15(null);
|
|
4064
|
-
const lastTarget = useRef11(null);
|
|
4065
|
-
useEffect11(() => {
|
|
4066
|
-
const el = queryScopedFields(entry, selector)[0] ?? null;
|
|
4067
|
-
if (el !== lastTarget.current) {
|
|
4068
|
-
el?.replaceChildren();
|
|
4069
|
-
lastTarget.current = el;
|
|
4070
|
-
setTarget(el);
|
|
4071
|
-
}
|
|
4072
|
-
}, [entry, html, selector]);
|
|
4073
|
-
if (!target) return null;
|
|
4074
|
-
return createPortal2(children, target);
|
|
4075
|
-
};
|
|
4076
|
-
|
|
4077
3918
|
// src/lib/design/component.tsx
|
|
4078
|
-
import { Fragment as Fragment7, jsx as
|
|
3919
|
+
import { Fragment as Fragment7, jsx as jsx31, jsxs as jsxs18 } from "react/jsx-runtime";
|
|
3920
|
+
var DESIGN_COMPONENT = Symbol("puck-ai.designComponent");
|
|
3921
|
+
var isDesignComponent = (config) => !!config?.[DESIGN_COMPONENT];
|
|
4079
3922
|
var streamingValues = /* @__PURE__ */ new Map();
|
|
4080
3923
|
var instanceKey = (name, instanceId) => `${name}:${typeof instanceId === "string" ? instanceId : ""}`;
|
|
4081
3924
|
var getRegistrationSlotFields = (reg) => {
|
|
@@ -4094,43 +3937,16 @@ var getRegistrationSlotFields = (reg) => {
|
|
|
4094
3937
|
])
|
|
4095
3938
|
);
|
|
4096
3939
|
};
|
|
4097
|
-
var hasPendingUserField = (field, value) => {
|
|
4098
|
-
if (!field?.type || field.type === "slot") return false;
|
|
4099
|
-
if (!isBuiltInFieldType(field.type)) return value === void 0;
|
|
4100
|
-
if (field.objectFields) {
|
|
4101
|
-
const group = value && typeof value === "object" ? value : {};
|
|
4102
|
-
return Object.entries(field.objectFields).some(
|
|
4103
|
-
([key, child]) => hasPendingUserField(child, group[key])
|
|
4104
|
-
);
|
|
4105
|
-
}
|
|
4106
|
-
if (field.arrayFields) {
|
|
4107
|
-
const items = Array.isArray(value) ? value : [];
|
|
4108
|
-
return items.some(
|
|
4109
|
-
(item) => Object.entries(field.arrayFields).some(
|
|
4110
|
-
([key, child]) => hasPendingUserField(child, item?.[key])
|
|
4111
|
-
)
|
|
4112
|
-
);
|
|
4113
|
-
}
|
|
4114
|
-
return false;
|
|
4115
|
-
};
|
|
4116
3940
|
function createDesignComponentConfig(registration) {
|
|
4117
3941
|
const name = registration.name;
|
|
4118
3942
|
if (registrationStore.get(name) !== registration) {
|
|
4119
3943
|
registrationStore.apply(registration);
|
|
4120
3944
|
}
|
|
4121
3945
|
const slotFields = getRegistrationSlotFields(registration);
|
|
4122
|
-
const
|
|
4123
|
-
...slotFields,
|
|
4124
|
-
...getTransformableFields(registration)
|
|
4125
|
-
};
|
|
4126
|
-
return {
|
|
3946
|
+
const componentConfig = {
|
|
4127
3947
|
...registration.label ? { label: registration.label } : {},
|
|
4128
|
-
fields:
|
|
4129
|
-
defaultProps:
|
|
4130
|
-
{ ...registration.defaultProps ?? {} },
|
|
4131
|
-
staticFields,
|
|
4132
|
-
name
|
|
4133
|
-
),
|
|
3948
|
+
fields: { ...slotFields },
|
|
3949
|
+
defaultProps: { ...registration.defaultProps ?? {} },
|
|
4134
3950
|
resolveData: (data, { trigger }) => {
|
|
4135
3951
|
if (trigger !== "replace" && trigger !== "insert" && trigger !== "force") {
|
|
4136
3952
|
return data;
|
|
@@ -4138,22 +3954,22 @@ function createDesignComponentConfig(registration) {
|
|
|
4138
3954
|
const reg = registrationStore.get(name) ?? registration;
|
|
4139
3955
|
const markup = reg.html ?? "";
|
|
4140
3956
|
if (!markup) return { props: {} };
|
|
4141
|
-
const annotations = getAnnotations(markup
|
|
4142
|
-
const fieldSet = getTransformableFields(reg);
|
|
4143
|
-
const extracted = withFieldTypeDefaults(
|
|
4144
|
-
annotations.values,
|
|
4145
|
-
fieldSet,
|
|
4146
|
-
name,
|
|
4147
|
-
reg.defaultProps
|
|
4148
|
-
);
|
|
3957
|
+
const annotations = getAnnotations(markup);
|
|
4149
3958
|
const cacheKey = instanceKey(name, data.props.id);
|
|
4150
3959
|
let newProps;
|
|
4151
3960
|
if (reg.streaming) {
|
|
4152
3961
|
const previous = streamingValues.get(cacheKey) ?? registrationStore.getPreviousValues(name);
|
|
4153
|
-
newProps = resolveStreamingProps(
|
|
4154
|
-
|
|
3962
|
+
newProps = resolveStreamingProps(
|
|
3963
|
+
data.props,
|
|
3964
|
+
annotations.values,
|
|
3965
|
+
previous
|
|
3966
|
+
);
|
|
3967
|
+
streamingValues.set(cacheKey, annotations.values);
|
|
4155
3968
|
} else {
|
|
4156
|
-
const values = {
|
|
3969
|
+
const values = {
|
|
3970
|
+
...annotations.values,
|
|
3971
|
+
...reg.defaultProps ?? {}
|
|
3972
|
+
};
|
|
4157
3973
|
const previous = streamingValues.get(cacheKey);
|
|
4158
3974
|
if (previous) {
|
|
4159
3975
|
newProps = resolveStreamingProps(data.props, values, previous);
|
|
@@ -4167,46 +3983,32 @@ function createDesignComponentConfig(registration) {
|
|
|
4167
3983
|
}
|
|
4168
3984
|
streamingValues.delete(cacheKey);
|
|
4169
3985
|
}
|
|
4170
|
-
const merged = { ...data.props, ...newProps };
|
|
4171
|
-
const filled = withFieldTypeDefaults(
|
|
4172
|
-
merged,
|
|
4173
|
-
fieldSet,
|
|
4174
|
-
name,
|
|
4175
|
-
reg.defaultProps
|
|
4176
|
-
);
|
|
4177
|
-
if (filled !== merged) {
|
|
4178
|
-
for (const [key, value] of Object.entries(filled)) {
|
|
4179
|
-
if (value !== merged[key]) newProps[key] = value;
|
|
4180
|
-
}
|
|
4181
|
-
}
|
|
4182
3986
|
if (Object.keys(newProps).length === 0) return { props: {} };
|
|
4183
3987
|
return { props: newProps };
|
|
4184
3988
|
},
|
|
4185
|
-
resolveFields: (
|
|
3989
|
+
resolveFields: () => {
|
|
4186
3990
|
const reg = registrationStore.get(name) ?? registration;
|
|
4187
3991
|
const fields = reg.fields ?? {};
|
|
4188
|
-
let resolvedFields;
|
|
4189
3992
|
if (Object.keys(fields).length > 0) {
|
|
4190
|
-
|
|
4191
|
-
} else {
|
|
4192
|
-
const annotations = getAnnotations(reg.html ?? "");
|
|
4193
|
-
resolvedFields = toPuckFields(annotations.fields, annotations.values);
|
|
4194
|
-
for (const slot of annotations.slots) {
|
|
4195
|
-
resolvedFields[slot.name] = toSlotField(slot);
|
|
4196
|
-
}
|
|
3993
|
+
return { ...fields };
|
|
4197
3994
|
}
|
|
4198
|
-
|
|
4199
|
-
|
|
4200
|
-
|
|
4201
|
-
|
|
4202
|
-
)
|
|
3995
|
+
const annotations = getAnnotations(reg.html ?? "");
|
|
3996
|
+
const resolvedFields = toPuckFields(
|
|
3997
|
+
annotations.fields,
|
|
3998
|
+
annotations.values
|
|
4203
3999
|
);
|
|
4000
|
+
for (const slot of annotations.slots) {
|
|
4001
|
+
resolvedFields[slot.name] = toSlotField(slot);
|
|
4002
|
+
}
|
|
4003
|
+
return resolvedFields;
|
|
4204
4004
|
},
|
|
4205
|
-
render: (renderProps) => renderProps.puck?.isEditing ? /* @__PURE__ */
|
|
4005
|
+
render: (renderProps) => renderProps.puck?.isEditing ? /* @__PURE__ */ jsx31(EditorEntry, { ...renderProps }) : /* @__PURE__ */ jsx31(Entry, { ...renderProps, getPuck: null })
|
|
4206
4006
|
};
|
|
4007
|
+
componentConfig[DESIGN_COMPONENT] = true;
|
|
4008
|
+
return componentConfig;
|
|
4207
4009
|
function EditorEntry(renderProps) {
|
|
4208
4010
|
const getPuck = useGetPuck2();
|
|
4209
|
-
return /* @__PURE__ */
|
|
4011
|
+
return /* @__PURE__ */ jsx31(Entry, { ...renderProps, getPuck });
|
|
4210
4012
|
}
|
|
4211
4013
|
function Entry({
|
|
4212
4014
|
getPuck,
|
|
@@ -4227,12 +4029,9 @@ function createDesignComponentConfig(registration) {
|
|
|
4227
4029
|
const html = reg.html ?? "";
|
|
4228
4030
|
const styles = reg.styles;
|
|
4229
4031
|
const script = reg.script;
|
|
4230
|
-
const [entryEl, setEntryEl] =
|
|
4231
|
-
const scriptRef =
|
|
4232
|
-
const annotations = useMemo5(
|
|
4233
|
-
() => getAnnotations(html, reg.fields),
|
|
4234
|
-
[html, reg.fields]
|
|
4235
|
-
);
|
|
4032
|
+
const [entryEl, setEntryEl] = useState15(null);
|
|
4033
|
+
const scriptRef = useRef11(null);
|
|
4034
|
+
const annotations = useMemo5(() => getAnnotations(html), [html]);
|
|
4236
4035
|
const { attrFields, arrayFields, attrSig, arraySig } = useMemo5(() => {
|
|
4237
4036
|
const attr = [];
|
|
4238
4037
|
const arrays = [];
|
|
@@ -4255,34 +4054,6 @@ function createDesignComponentConfig(registration) {
|
|
|
4255
4054
|
arraySig: JSON.stringify(arrays)
|
|
4256
4055
|
};
|
|
4257
4056
|
}, [props, annotations]);
|
|
4258
|
-
const nodeFields = useMemo5(() => {
|
|
4259
|
-
const out = [];
|
|
4260
|
-
for (const field of annotations.fields) {
|
|
4261
|
-
if (field.binding !== "text") continue;
|
|
4262
|
-
const value = getDeepValue(props, field.name);
|
|
4263
|
-
if (!React3.isValidElement(value)) continue;
|
|
4264
|
-
out.push({
|
|
4265
|
-
name: field.name,
|
|
4266
|
-
selector: textFieldSelector(field),
|
|
4267
|
-
node: value
|
|
4268
|
-
});
|
|
4269
|
-
}
|
|
4270
|
-
return out;
|
|
4271
|
-
}, [annotations, props]);
|
|
4272
|
-
const storedProps = useMemo5(
|
|
4273
|
-
() => getPuck ? getPuck().getItemById(id)?.props : void 0,
|
|
4274
|
-
[getPuck, id, props]
|
|
4275
|
-
);
|
|
4276
|
-
const editableFields = useMemo5(() => {
|
|
4277
|
-
const mounted = new Set(nodeFields.map((f) => f.name));
|
|
4278
|
-
return annotations.fields.filter((field) => {
|
|
4279
|
-
if (mounted.has(field.name)) return false;
|
|
4280
|
-
if (field.binding === "array") return true;
|
|
4281
|
-
if (field.shape && !isBuiltInFieldType(field.shape.type)) return false;
|
|
4282
|
-
if (!storedProps) return true;
|
|
4283
|
-
return getDeepValue(props, field.name) === getDeepValue(storedProps, field.name);
|
|
4284
|
-
});
|
|
4285
|
-
}, [annotations, nodeFields, props, storedProps]);
|
|
4286
4057
|
const patchedHtml = useMemo5(() => {
|
|
4287
4058
|
if (puck.isEditing) return html;
|
|
4288
4059
|
return patchHtmlAnnotations(html, props);
|
|
@@ -4294,21 +4065,20 @@ function createDesignComponentConfig(registration) {
|
|
|
4294
4065
|
const value = getDeepValue(props, field.name);
|
|
4295
4066
|
if (value === void 0 || value === null) continue;
|
|
4296
4067
|
if (!isValidFieldName(field.name)) continue;
|
|
4297
|
-
if (React3.isValidElement(value)) continue;
|
|
4298
4068
|
attrs[`data-puck-field-value-${field.name}`] = typeof value === "string" || typeof value === "number" ? String(value) : JSON.stringify(value);
|
|
4299
4069
|
}
|
|
4300
4070
|
return attrs;
|
|
4301
4071
|
}, [annotations, props, puck.isEditing]);
|
|
4302
4072
|
const editorEntryNode = useMemo5(
|
|
4303
|
-
() => puck.isEditing ? /* @__PURE__ */
|
|
4073
|
+
() => puck.isEditing ? /* @__PURE__ */ jsx31("div", { ref: setEntryEl }) : null,
|
|
4304
4074
|
[puck.isEditing]
|
|
4305
4075
|
);
|
|
4306
4076
|
useEffect12(() => {
|
|
4307
4077
|
if (!puck.isEditing || !getPuck) return;
|
|
4308
4078
|
getPuck().resolveDataById(id, "force");
|
|
4309
4079
|
}, [reg, puck.isEditing, getPuck, id]);
|
|
4310
|
-
const fieldWiring =
|
|
4311
|
-
const morphed =
|
|
4080
|
+
const fieldWiring = useRef11(/* @__PURE__ */ new Map());
|
|
4081
|
+
const morphed = useRef11(null);
|
|
4312
4082
|
useLayoutEffect(() => {
|
|
4313
4083
|
if (!puck.isEditing || !entryEl) return;
|
|
4314
4084
|
if (morphed.current?.el !== entryEl || morphed.current?.html !== html || morphed.current?.attrSig !== attrSig) {
|
|
@@ -4320,7 +4090,7 @@ function createDesignComponentConfig(registration) {
|
|
|
4320
4090
|
}
|
|
4321
4091
|
syncFieldValues(entryEl, annotations.fields, props);
|
|
4322
4092
|
if (getPuck) {
|
|
4323
|
-
wireFieldEditing(entryEl,
|
|
4093
|
+
wireFieldEditing(entryEl, annotations.fields, fieldWiring.current, {
|
|
4324
4094
|
componentId: id,
|
|
4325
4095
|
getPuck
|
|
4326
4096
|
});
|
|
@@ -4346,9 +4116,9 @@ function createDesignComponentConfig(registration) {
|
|
|
4346
4116
|
}
|
|
4347
4117
|
}
|
|
4348
4118
|
}, [entryEl, fieldValueAttrs]);
|
|
4349
|
-
const appliedArrayHtml =
|
|
4350
|
-
const arrayItemWiring =
|
|
4351
|
-
const appliedArrays =
|
|
4119
|
+
const appliedArrayHtml = useRef11(/* @__PURE__ */ new WeakMap());
|
|
4120
|
+
const arrayItemWiring = useRef11({});
|
|
4121
|
+
const appliedArrays = useRef11(null);
|
|
4352
4122
|
useEffect12(() => {
|
|
4353
4123
|
if (!puck.isEditing || !entryEl || !getPuck) return;
|
|
4354
4124
|
if (appliedArrays.current?.el === entryEl && appliedArrays.current?.html === html && appliedArrays.current?.sig === arraySig) {
|
|
@@ -4427,7 +4197,7 @@ function createDesignComponentConfig(registration) {
|
|
|
4427
4197
|
for (const slot of annotations.slots) {
|
|
4428
4198
|
const Slot = props[slot.name];
|
|
4429
4199
|
if (typeof Slot === "function") {
|
|
4430
|
-
slotContent[slot.name] = /* @__PURE__ */
|
|
4200
|
+
slotContent[slot.name] = /* @__PURE__ */ jsx31(
|
|
4431
4201
|
Slot,
|
|
4432
4202
|
{
|
|
4433
4203
|
style: slot.style ? parseStyleString(slot.style) : void 0,
|
|
@@ -4436,31 +4206,17 @@ function createDesignComponentConfig(registration) {
|
|
|
4436
4206
|
);
|
|
4437
4207
|
}
|
|
4438
4208
|
}
|
|
4439
|
-
const fieldContent = {};
|
|
4440
|
-
for (const { name: name2, node } of nodeFields) {
|
|
4441
|
-
fieldContent[name2] = node;
|
|
4442
|
-
}
|
|
4443
4209
|
return /* @__PURE__ */ jsxs18(Fragment7, { children: [
|
|
4444
|
-
styles && /* @__PURE__ */
|
|
4445
|
-
style && /* @__PURE__ */
|
|
4446
|
-
/* @__PURE__ */
|
|
4210
|
+
styles && /* @__PURE__ */ jsx31("style", { children: styles }),
|
|
4211
|
+
style && /* @__PURE__ */ jsx31("style", { children: style }),
|
|
4212
|
+
/* @__PURE__ */ jsx31("div", { ref: setEntryEl, ...fieldValueAttrs, children: htmlToReactTree(patchedHtml, slotContent) })
|
|
4447
4213
|
] });
|
|
4448
4214
|
}
|
|
4449
4215
|
return /* @__PURE__ */ jsxs18(Fragment7, { children: [
|
|
4450
|
-
styles && /* @__PURE__ */
|
|
4451
|
-
style && /* @__PURE__ */
|
|
4216
|
+
styles && /* @__PURE__ */ jsx31("style", { children: styles }),
|
|
4217
|
+
style && /* @__PURE__ */ jsx31("style", { children: style }),
|
|
4452
4218
|
editorEntryNode,
|
|
4453
|
-
entryEl &&
|
|
4454
|
-
FieldPortal,
|
|
4455
|
-
{
|
|
4456
|
-
entry: entryEl,
|
|
4457
|
-
html,
|
|
4458
|
-
selector,
|
|
4459
|
-
children: node
|
|
4460
|
-
},
|
|
4461
|
-
name2
|
|
4462
|
-
)),
|
|
4463
|
-
entryEl && annotations.slots.map((slot) => /* @__PURE__ */ jsx32(
|
|
4219
|
+
entryEl && annotations.slots.map((slot) => /* @__PURE__ */ jsx31(
|
|
4464
4220
|
SlotPortal,
|
|
4465
4221
|
{
|
|
4466
4222
|
entry: entryEl,
|
|
@@ -4478,8 +4234,8 @@ function createDesignComponentConfig(registration) {
|
|
|
4478
4234
|
|
|
4479
4235
|
// src/lib/design/globals.tsx
|
|
4480
4236
|
init_react_import();
|
|
4481
|
-
import { useEffect as useEffect13, useRef as
|
|
4482
|
-
import { Fragment as Fragment8, jsx as
|
|
4237
|
+
import { useEffect as useEffect13, useRef as useRef12 } from "react";
|
|
4238
|
+
import { Fragment as Fragment8, jsx as jsx32, jsxs as jsxs19 } from "react/jsx-runtime";
|
|
4483
4239
|
function getDynamicConfigGlobals(dynamicConfig) {
|
|
4484
4240
|
if (typeof dynamicConfig !== "object" || dynamicConfig === null) return {};
|
|
4485
4241
|
const { styles, script } = dynamicConfig;
|
|
@@ -4494,8 +4250,8 @@ function DesignGlobals({
|
|
|
4494
4250
|
script,
|
|
4495
4251
|
isEditing
|
|
4496
4252
|
}) {
|
|
4497
|
-
const scriptRef =
|
|
4498
|
-
const hostRef =
|
|
4253
|
+
const scriptRef = useRef12(null);
|
|
4254
|
+
const hostRef = useRef12(null);
|
|
4499
4255
|
useEffect13(() => {
|
|
4500
4256
|
if (!script) return;
|
|
4501
4257
|
scriptRef.current?.remove();
|
|
@@ -4510,9 +4266,9 @@ function DesignGlobals({
|
|
|
4510
4266
|
};
|
|
4511
4267
|
}, [script]);
|
|
4512
4268
|
return /* @__PURE__ */ jsxs19(Fragment8, { children: [
|
|
4513
|
-
isEditing && /* @__PURE__ */
|
|
4514
|
-
styles && /* @__PURE__ */
|
|
4515
|
-
script && /* @__PURE__ */
|
|
4269
|
+
isEditing && /* @__PURE__ */ jsx32("style", { children: INLINE_EDIT_RESET }),
|
|
4270
|
+
styles && /* @__PURE__ */ jsx32("style", { children: styles }),
|
|
4271
|
+
script && /* @__PURE__ */ jsx32("div", { ref: hostRef, style: { display: "none" } })
|
|
4516
4272
|
] });
|
|
4517
4273
|
}
|
|
4518
4274
|
var WRAPPED = "__puckAiDesignGlobals";
|
|
@@ -4523,7 +4279,7 @@ function withDesignGlobals(root) {
|
|
|
4523
4279
|
const render = (props) => {
|
|
4524
4280
|
const { styles, script } = getDynamicConfigGlobals(props._dynamicConfig);
|
|
4525
4281
|
return /* @__PURE__ */ jsxs19(Fragment8, { children: [
|
|
4526
|
-
/* @__PURE__ */
|
|
4282
|
+
/* @__PURE__ */ jsx32(
|
|
4527
4283
|
DesignGlobals,
|
|
4528
4284
|
{
|
|
4529
4285
|
styles,
|
|
@@ -4545,7 +4301,7 @@ function ensureDesignGlobalsRoot(config) {
|
|
|
4545
4301
|
}
|
|
4546
4302
|
|
|
4547
4303
|
// src/lib/design/runtime.tsx
|
|
4548
|
-
import { jsx as
|
|
4304
|
+
import { jsx as jsx33 } from "react/jsx-runtime";
|
|
4549
4305
|
var cachedFieldMetadata;
|
|
4550
4306
|
function detectFieldMetadata(config) {
|
|
4551
4307
|
for (const comp of Object.values(config.components)) {
|
|
@@ -4584,7 +4340,7 @@ function applyConfigFieldMetadata(config, dynamicComponents) {
|
|
|
4584
4340
|
var DESIGNED_CATEGORY = "dynamic";
|
|
4585
4341
|
var dynamicConfigRootField = {
|
|
4586
4342
|
type: "custom",
|
|
4587
|
-
render: () => /* @__PURE__ */
|
|
4343
|
+
render: () => /* @__PURE__ */ jsx33("div", {}),
|
|
4588
4344
|
ai: {
|
|
4589
4345
|
exclude: true
|
|
4590
4346
|
}
|
|
@@ -4644,7 +4400,7 @@ function syncDesignComponents(getPuck) {
|
|
|
4644
4400
|
ensureDynamicConfigField(config);
|
|
4645
4401
|
for (const [name, persistedReg] of Object.entries(persisted)) {
|
|
4646
4402
|
const prev = lastSynced.get(name);
|
|
4647
|
-
if (registrationStore.has(name) && (prev === persistedReg || registrationContentEqual(prev, persistedReg))) {
|
|
4403
|
+
if (registrationStore.has(name) && config.components[name] && (prev === persistedReg || registrationContentEqual(prev, persistedReg))) {
|
|
4648
4404
|
lastSynced.set(name, persistedReg);
|
|
4649
4405
|
continue;
|
|
4650
4406
|
}
|
|
@@ -4662,25 +4418,23 @@ function syncDesignComponents(getPuck) {
|
|
|
4662
4418
|
} else {
|
|
4663
4419
|
if (registration.label)
|
|
4664
4420
|
config.components[name].label = registration.label;
|
|
4421
|
+
if (isSettled) {
|
|
4422
|
+
config.components[name].defaultProps = {
|
|
4423
|
+
...registration.defaultProps ?? {}
|
|
4424
|
+
};
|
|
4425
|
+
}
|
|
4665
4426
|
}
|
|
4666
|
-
|
|
4667
|
-
...getSlotFields(registration.html ?? ""),
|
|
4668
|
-
...getTransformableFields(registration)
|
|
4669
|
-
};
|
|
4670
|
-
config.components[name].fields = fields;
|
|
4671
|
-
config.components[name].defaultProps = withFieldTypeDefaults(
|
|
4672
|
-
{ ...registration.defaultProps ?? {} },
|
|
4673
|
-
fields,
|
|
4674
|
-
name
|
|
4675
|
-
);
|
|
4427
|
+
config.components[name].fields = getSlotFields(registration.html ?? "");
|
|
4676
4428
|
}
|
|
4677
4429
|
let hasRemovals = false;
|
|
4678
4430
|
for (const [name] of registrationStore.getAll()) {
|
|
4679
4431
|
if (!(name in persisted)) {
|
|
4680
4432
|
registrationStore.delete(name);
|
|
4681
4433
|
lastSynced.delete(name);
|
|
4682
|
-
|
|
4683
|
-
|
|
4434
|
+
if (isDesignComponent(config.components[name])) {
|
|
4435
|
+
delete config.components[name];
|
|
4436
|
+
hasRemovals = true;
|
|
4437
|
+
}
|
|
4684
4438
|
}
|
|
4685
4439
|
}
|
|
4686
4440
|
if (createdSettled) {
|
|
@@ -4836,6 +4590,14 @@ var getDocumentSize = (root) => {
|
|
|
4836
4590
|
};
|
|
4837
4591
|
};
|
|
4838
4592
|
|
|
4593
|
+
// src/lib/screenshot-overflow.ts
|
|
4594
|
+
init_react_import();
|
|
4595
|
+
var applyBrowserOverflowStylesTo = (document2) => {
|
|
4596
|
+
for (const element of [document2.documentElement, document2.body]) {
|
|
4597
|
+
element?.style.setProperty("overflow", "visible", "important");
|
|
4598
|
+
}
|
|
4599
|
+
};
|
|
4600
|
+
|
|
4839
4601
|
// src/lib/capture-screenshot.ts
|
|
4840
4602
|
var editorOnlyClassPrefixes = ["_DraggableComponent--hover", "_ActionBar"];
|
|
4841
4603
|
var releaseCanvas = (canvas) => {
|
|
@@ -4846,14 +4608,14 @@ var drawScaled = (source, ratio) => {
|
|
|
4846
4608
|
const target = document.createElement("canvas");
|
|
4847
4609
|
target.width = scaleDimension(source.width, ratio);
|
|
4848
4610
|
target.height = scaleDimension(source.height, ratio);
|
|
4849
|
-
const
|
|
4850
|
-
if (!
|
|
4611
|
+
const ctx = target.getContext("2d");
|
|
4612
|
+
if (!ctx) {
|
|
4851
4613
|
releaseCanvas(target);
|
|
4852
4614
|
return source;
|
|
4853
4615
|
}
|
|
4854
|
-
|
|
4855
|
-
|
|
4856
|
-
|
|
4616
|
+
ctx.imageSmoothingEnabled = true;
|
|
4617
|
+
ctx.imageSmoothingQuality = "high";
|
|
4618
|
+
ctx.drawImage(source, 0, 0, target.width, target.height);
|
|
4857
4619
|
return target;
|
|
4858
4620
|
};
|
|
4859
4621
|
var fitCanvas = (canvas) => {
|
|
@@ -4904,6 +4666,7 @@ var captureScreenshot = async (root, { scale = CAPTURE_SCALE, quality = 0.8, wid
|
|
|
4904
4666
|
allowTaint: false,
|
|
4905
4667
|
useCORS: true,
|
|
4906
4668
|
scrollY: 0,
|
|
4669
|
+
onclone: applyBrowserOverflowStylesTo,
|
|
4907
4670
|
ignoreElements: (el) => Array.from(el.classList).some(
|
|
4908
4671
|
(c) => editorOnlyClassPrefixes.some((prefix) => c.startsWith(prefix))
|
|
4909
4672
|
)
|
|
@@ -4933,12 +4696,12 @@ async function postClientToolResponse(host, body) {
|
|
|
4933
4696
|
}
|
|
4934
4697
|
|
|
4935
4698
|
// src/components/Chat/index.tsx
|
|
4936
|
-
import { Fragment as Fragment9, jsx as
|
|
4699
|
+
import { Fragment as Fragment9, jsx as jsx34, jsxs as jsxs20 } from "react/jsx-runtime";
|
|
4937
4700
|
var q = qler();
|
|
4938
4701
|
var DEFAULT_API_VERSION = "v2";
|
|
4939
4702
|
var BUILD_OP_DEBOUNCE_MS = 1e3 / 60;
|
|
4940
4703
|
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.";
|
|
4941
|
-
var PLUGIN_AI_VERSION = true ? "0.9.0-canary.
|
|
4704
|
+
var PLUGIN_AI_VERSION = true ? "0.9.0-canary.53ee4e95" : "unknown";
|
|
4942
4705
|
var BENCHMARK = false;
|
|
4943
4706
|
var prefixedUlid = (prefix = "") => `${prefix ? `${prefix}_` : ""}${ulid()}`;
|
|
4944
4707
|
var getClassName18 = getClassNameFactory("Chat", styles_module_default);
|
|
@@ -4961,11 +4724,11 @@ function Chat2(props) {
|
|
|
4961
4724
|
} = chat ?? {};
|
|
4962
4725
|
const puckDispatch = usePuck((s) => s.dispatch);
|
|
4963
4726
|
const getPuck = useGetPuck4();
|
|
4964
|
-
const localChatId =
|
|
4965
|
-
const inputRef =
|
|
4966
|
-
const pluginRef =
|
|
4967
|
-
const [mode, setMode] =
|
|
4968
|
-
const modeRef =
|
|
4727
|
+
const localChatId = useRef13("");
|
|
4728
|
+
const inputRef = useRef13(null);
|
|
4729
|
+
const pluginRef = useRef13(null);
|
|
4730
|
+
const [mode, setMode] = useState16(defaultMode);
|
|
4731
|
+
const modeRef = useRef13(mode);
|
|
4969
4732
|
const designModeVisible = typeof designMode === "boolean" ? designMode : designMode.visible ?? false;
|
|
4970
4733
|
useEffect14(() => {
|
|
4971
4734
|
modeRef.current = mode;
|
|
@@ -4974,18 +4737,18 @@ function Chat2(props) {
|
|
|
4974
4737
|
useEffect14(() => {
|
|
4975
4738
|
syncDesignComponents(getPuck);
|
|
4976
4739
|
}, [puckData, getPuck]);
|
|
4977
|
-
const [error, setError] =
|
|
4978
|
-
const [userError, setUserError] =
|
|
4979
|
-
const clientToolEndpointUnavailableRef =
|
|
4980
|
-
const stopChatRef =
|
|
4981
|
-
const [composerAttachments, setComposerAttachments] =
|
|
4982
|
-
const removedAttachmentClientIdsRef =
|
|
4983
|
-
const uploadControllersRef =
|
|
4984
|
-
const pendingBuildOpsRef =
|
|
4985
|
-
const lastStreamActivityRef =
|
|
4986
|
-
const hiddenSinceRef =
|
|
4987
|
-
const [toolStatus, setToolStatus] =
|
|
4988
|
-
const [subagentState, setSubagentState] =
|
|
4740
|
+
const [error, setError] = useState16();
|
|
4741
|
+
const [userError, setUserError] = useState16();
|
|
4742
|
+
const clientToolEndpointUnavailableRef = useRef13(false);
|
|
4743
|
+
const stopChatRef = useRef13(null);
|
|
4744
|
+
const [composerAttachments, setComposerAttachments] = useState16([]);
|
|
4745
|
+
const removedAttachmentClientIdsRef = useRef13(/* @__PURE__ */ new Set());
|
|
4746
|
+
const uploadControllersRef = useRef13(/* @__PURE__ */ new Map());
|
|
4747
|
+
const pendingBuildOpsRef = useRef13([]);
|
|
4748
|
+
const lastStreamActivityRef = useRef13(0);
|
|
4749
|
+
const hiddenSinceRef = useRef13(null);
|
|
4750
|
+
const [toolStatus, setToolStatus] = useState16({});
|
|
4751
|
+
const [subagentState, setSubagentState] = useState16({});
|
|
4989
4752
|
const attachmentConfig = useMemo6(
|
|
4990
4753
|
() => ({
|
|
4991
4754
|
accept: attachments?.accept ?? defaultAttachmentAccept,
|
|
@@ -5140,12 +4903,14 @@ function Chat2(props) {
|
|
|
5140
4903
|
}
|
|
5141
4904
|
case "data-client-request": {
|
|
5142
4905
|
const { requestId, action } = dataPart.data;
|
|
4906
|
+
const chatId = localChatId.current || void 0;
|
|
5143
4907
|
if (action === "getPageData") {
|
|
5144
4908
|
debouncedFlushBuildOps.flush();
|
|
5145
4909
|
q.wait().then(() => {
|
|
5146
4910
|
const { appState } = getPuck();
|
|
5147
4911
|
return sendClientToolResponse({
|
|
5148
4912
|
id: requestId,
|
|
4913
|
+
chatId,
|
|
5149
4914
|
responses: [{ action, output: appState.data }]
|
|
5150
4915
|
});
|
|
5151
4916
|
}).catch((e) => {
|
|
@@ -5175,12 +4940,14 @@ function Chat2(props) {
|
|
|
5175
4940
|
}
|
|
5176
4941
|
return sendClientToolResponse({
|
|
5177
4942
|
id: requestId,
|
|
4943
|
+
chatId,
|
|
5178
4944
|
responses: [{ action, output: { sizeBytes: blob.size } }]
|
|
5179
4945
|
});
|
|
5180
4946
|
}).catch((e) => {
|
|
5181
4947
|
console.error("Failed to respond to client request:", e);
|
|
5182
4948
|
return sendClientToolResponse({
|
|
5183
4949
|
id: requestId,
|
|
4950
|
+
chatId,
|
|
5184
4951
|
responses: [{ action, output: { sizeBytes: 0 } }]
|
|
5185
4952
|
});
|
|
5186
4953
|
});
|
|
@@ -5270,7 +5037,6 @@ function Chat2(props) {
|
|
|
5270
5037
|
messages: opts.messages,
|
|
5271
5038
|
pageData: appState.data,
|
|
5272
5039
|
config: configWithRoot,
|
|
5273
|
-
fieldTypes: toWireFieldTypes(getFieldTypes()),
|
|
5274
5040
|
mode: modeRef.current
|
|
5275
5041
|
}
|
|
5276
5042
|
};
|
|
@@ -5326,7 +5092,7 @@ function Chat2(props) {
|
|
|
5326
5092
|
stop();
|
|
5327
5093
|
};
|
|
5328
5094
|
}, [stop]);
|
|
5329
|
-
const statusRef =
|
|
5095
|
+
const statusRef = useRef13(status);
|
|
5330
5096
|
useEffect14(() => {
|
|
5331
5097
|
statusRef.current = status;
|
|
5332
5098
|
}, [status]);
|
|
@@ -5376,7 +5142,7 @@ function Chat2(props) {
|
|
|
5376
5142
|
if (graceTimer) clearTimeout(graceTimer);
|
|
5377
5143
|
};
|
|
5378
5144
|
}, [stop]);
|
|
5379
|
-
const [forcedStatus, setForcedStatus] =
|
|
5145
|
+
const [forcedStatus, setForcedStatus] = useState16();
|
|
5380
5146
|
const resolvedStatus = useMemo6(
|
|
5381
5147
|
() => forcedStatus ?? status,
|
|
5382
5148
|
[status, forcedStatus]
|
|
@@ -5618,13 +5384,13 @@ function Chat2(props) {
|
|
|
5618
5384
|
};
|
|
5619
5385
|
});
|
|
5620
5386
|
}, [messages, toolStatus]);
|
|
5621
|
-
return /* @__PURE__ */
|
|
5387
|
+
return /* @__PURE__ */ jsx34("div", { className: getClassName18(), ref: pluginRef, children: /* @__PURE__ */ jsx34(HostProvider, { value: host, children: /* @__PURE__ */ jsx34(ToolStatusProvider, { value: toolStatus, children: /* @__PURE__ */ jsx34(SubagentStateProvider, { value: subagentState, children: /* @__PURE__ */ jsx34(
|
|
5622
5388
|
ChatBody,
|
|
5623
5389
|
{
|
|
5624
5390
|
messages: messagesWithStatuses,
|
|
5625
5391
|
onFileDrop: attachmentConfig.enabled ? handleFiles : void 0,
|
|
5626
5392
|
actions: /* @__PURE__ */ jsxs20(Fragment9, { children: [
|
|
5627
|
-
attachmentConfig.enabled ? /* @__PURE__ */
|
|
5393
|
+
attachmentConfig.enabled ? /* @__PURE__ */ jsx34(
|
|
5628
5394
|
AttachmentComposer,
|
|
5629
5395
|
{
|
|
5630
5396
|
accept: attachmentConfig.accept,
|
|
@@ -5637,7 +5403,7 @@ function Chat2(props) {
|
|
|
5637
5403
|
typeof chatActions === "function" ? chatActions({
|
|
5638
5404
|
disabled: resolvedStatus === "submitted" || resolvedStatus === "streaming"
|
|
5639
5405
|
}) : chatActions,
|
|
5640
|
-
designModeVisible ? /* @__PURE__ */
|
|
5406
|
+
designModeVisible ? /* @__PURE__ */ jsx34(
|
|
5641
5407
|
DesignModeToggle,
|
|
5642
5408
|
{
|
|
5643
5409
|
active: mode === "design",
|
|
@@ -5654,7 +5420,7 @@ function Chat2(props) {
|
|
|
5654
5420
|
inputRef,
|
|
5655
5421
|
status: resolvedStatus,
|
|
5656
5422
|
examplePrompts: examplePrompts?.map(
|
|
5657
|
-
({ label, href, onClick }) => /* @__PURE__ */
|
|
5423
|
+
({ label, href, onClick }) => /* @__PURE__ */ jsx34(
|
|
5658
5424
|
ExamplePrompt,
|
|
5659
5425
|
{
|
|
5660
5426
|
label,
|
|
@@ -5673,7 +5439,7 @@ function Chat2(props) {
|
|
|
5673
5439
|
},
|
|
5674
5440
|
userError,
|
|
5675
5441
|
onDismissUserError: () => setUserError(""),
|
|
5676
|
-
children: placeholder ?? /* @__PURE__ */
|
|
5442
|
+
children: placeholder ?? /* @__PURE__ */ jsx34(
|
|
5677
5443
|
Placeholder,
|
|
5678
5444
|
{
|
|
5679
5445
|
dispatch: puckDispatch,
|
|
@@ -5793,7 +5559,7 @@ function AttachmentComposer({
|
|
|
5793
5559
|
const id = useId3();
|
|
5794
5560
|
const inputId = useMemo6(() => `attachment-input-${id}`, []);
|
|
5795
5561
|
return /* @__PURE__ */ jsxs20("div", { className: getClassName18("attachmentControls"), children: [
|
|
5796
|
-
/* @__PURE__ */
|
|
5562
|
+
/* @__PURE__ */ jsx34(
|
|
5797
5563
|
"input",
|
|
5798
5564
|
{
|
|
5799
5565
|
accept: accept.join(","),
|
|
@@ -5805,7 +5571,7 @@ function AttachmentComposer({
|
|
|
5805
5571
|
type: "file"
|
|
5806
5572
|
}
|
|
5807
5573
|
),
|
|
5808
|
-
/* @__PURE__ */
|
|
5574
|
+
/* @__PURE__ */ jsx34(
|
|
5809
5575
|
"button",
|
|
5810
5576
|
{
|
|
5811
5577
|
"aria-label": "Attach files",
|
|
@@ -5814,7 +5580,7 @@ function AttachmentComposer({
|
|
|
5814
5580
|
onClick: () => document.getElementById(inputId)?.click(),
|
|
5815
5581
|
title: "Attach files",
|
|
5816
5582
|
type: "button",
|
|
5817
|
-
children: /* @__PURE__ */
|
|
5583
|
+
children: /* @__PURE__ */ jsx34(Paperclip, { size: 14 })
|
|
5818
5584
|
}
|
|
5819
5585
|
)
|
|
5820
5586
|
] });
|
|
@@ -5838,11 +5604,11 @@ function Placeholder({
|
|
|
5838
5604
|
}, 10);
|
|
5839
5605
|
};
|
|
5840
5606
|
return /* @__PURE__ */ jsxs20("div", { className: getClassName18("placeholder"), children: [
|
|
5841
|
-
/* @__PURE__ */
|
|
5842
|
-
/* @__PURE__ */
|
|
5843
|
-
/* @__PURE__ */
|
|
5607
|
+
/* @__PURE__ */ jsx34("span", { className: getClassName18("placeholderIcon"), children: /* @__PURE__ */ jsx34(Sparkles, { "aria-hidden": "true", size: 28 }) }),
|
|
5608
|
+
/* @__PURE__ */ jsx34("strong", { className: getClassName18("placeholderTitle"), children: "Build with AI" }),
|
|
5609
|
+
/* @__PURE__ */ jsx34("span", { className: getClassName18("placeholderDescription"), children: "Describe what you want to create or change." }),
|
|
5844
5610
|
/* @__PURE__ */ jsxs20("div", { className: getClassName18("actions"), children: [
|
|
5845
|
-
/* @__PURE__ */
|
|
5611
|
+
/* @__PURE__ */ jsx34(
|
|
5846
5612
|
"button",
|
|
5847
5613
|
{
|
|
5848
5614
|
className: getClassName18("action"),
|
|
@@ -5851,7 +5617,7 @@ function Placeholder({
|
|
|
5851
5617
|
children: "Write a prompt"
|
|
5852
5618
|
}
|
|
5853
5619
|
),
|
|
5854
|
-
/* @__PURE__ */
|
|
5620
|
+
/* @__PURE__ */ jsx34(
|
|
5855
5621
|
"button",
|
|
5856
5622
|
{
|
|
5857
5623
|
className: getClassName18("actionOutlined"),
|
|
@@ -5891,7 +5657,7 @@ function isScrolledIntoView(el) {
|
|
|
5891
5657
|
|
|
5892
5658
|
// src/components/ScrollTracking/ScrollTracking.tsx
|
|
5893
5659
|
init_react_import();
|
|
5894
|
-
import { useEffect as useEffect15, useRef as
|
|
5660
|
+
import { useEffect as useEffect15, useRef as useRef14 } from "react";
|
|
5895
5661
|
|
|
5896
5662
|
// src/lib/scroll-into-view-local.ts
|
|
5897
5663
|
init_react_import();
|
|
@@ -5961,8 +5727,8 @@ var ScrollTracking = ({
|
|
|
5961
5727
|
children,
|
|
5962
5728
|
trackingId
|
|
5963
5729
|
}) => {
|
|
5964
|
-
const followedRefs =
|
|
5965
|
-
const enabledRef =
|
|
5730
|
+
const followedRefs = useRef14([]);
|
|
5731
|
+
const enabledRef = useRef14(false);
|
|
5966
5732
|
useEffect15(() => {
|
|
5967
5733
|
return subscribeToScrollTrackingEvents(({ id, enabled }) => {
|
|
5968
5734
|
if (id !== trackingId) return;
|
|
@@ -5995,14 +5761,14 @@ import { createUsePuck as createUsePuck2 } from "@puckeditor/core";
|
|
|
5995
5761
|
// src/components/ManageComponents/index.tsx
|
|
5996
5762
|
init_react_import();
|
|
5997
5763
|
import { useGetPuck as useGetPuck5 } from "@puckeditor/core";
|
|
5998
|
-
import { useCallback as useCallback8, useEffect as useEffect16, useState as
|
|
5764
|
+
import { useCallback as useCallback8, useEffect as useEffect16, useState as useState17, useSyncExternalStore as useSyncExternalStore3 } from "react";
|
|
5999
5765
|
|
|
6000
5766
|
// css-module:/home/runner/work/platform/platform/packages/plugin-ai/src/components/ManageComponents/styles.module.css#css-module
|
|
6001
5767
|
init_react_import();
|
|
6002
5768
|
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" };
|
|
6003
5769
|
|
|
6004
5770
|
// src/components/ManageComponents/index.tsx
|
|
6005
|
-
import { Fragment as Fragment10, jsx as
|
|
5771
|
+
import { Fragment as Fragment10, jsx as jsx35, jsxs as jsxs21 } from "react/jsx-runtime";
|
|
6006
5772
|
var cx10 = getClassNameFactory2("ManageComponents", styles_module_default10);
|
|
6007
5773
|
var useRegistrations = () => useSyncExternalStore3(
|
|
6008
5774
|
registrationStore.subscribe,
|
|
@@ -6012,7 +5778,7 @@ var useRegistrations = () => useSyncExternalStore3(
|
|
|
6012
5778
|
function ManageModalContent({ onClose }) {
|
|
6013
5779
|
const getPuck = useGetPuck5();
|
|
6014
5780
|
const { visible, setVisible } = useModal();
|
|
6015
|
-
const [confirmTarget, setConfirmTarget] =
|
|
5781
|
+
const [confirmTarget, setConfirmTarget] = useState17(null);
|
|
6016
5782
|
const entries = useRegistrations();
|
|
6017
5783
|
useEffect16(() => {
|
|
6018
5784
|
if (!visible) onClose();
|
|
@@ -6025,14 +5791,14 @@ function ManageModalContent({ onClose }) {
|
|
|
6025
5791
|
}
|
|
6026
5792
|
};
|
|
6027
5793
|
if (confirmTarget) {
|
|
6028
|
-
return /* @__PURE__ */
|
|
5794
|
+
return /* @__PURE__ */ jsx35(
|
|
6029
5795
|
ActionModal,
|
|
6030
5796
|
{
|
|
6031
5797
|
title: "Delete component",
|
|
6032
5798
|
hideButton: true,
|
|
6033
5799
|
actions: /* @__PURE__ */ jsxs21(Inline, { children: [
|
|
6034
|
-
/* @__PURE__ */
|
|
6035
|
-
/* @__PURE__ */
|
|
5800
|
+
/* @__PURE__ */ jsx35(Button, { variant: "secondary", onClick: () => setConfirmTarget(null), children: "Cancel" }),
|
|
5801
|
+
/* @__PURE__ */ jsx35(
|
|
6036
5802
|
Button,
|
|
6037
5803
|
{
|
|
6038
5804
|
variant: "danger",
|
|
@@ -6043,15 +5809,15 @@ function ManageModalContent({ onClose }) {
|
|
|
6043
5809
|
] }),
|
|
6044
5810
|
children: /* @__PURE__ */ jsxs21("p", { children: [
|
|
6045
5811
|
"Are you sure you want to delete ",
|
|
6046
|
-
/* @__PURE__ */
|
|
5812
|
+
/* @__PURE__ */ jsx35("b", { children: confirmTarget.label }),
|
|
6047
5813
|
"?"
|
|
6048
5814
|
] })
|
|
6049
5815
|
}
|
|
6050
5816
|
);
|
|
6051
5817
|
}
|
|
6052
|
-
return /* @__PURE__ */
|
|
5818
|
+
return /* @__PURE__ */ jsx35(ActionModal, { title: "Manage components", hideButton: true, children: /* @__PURE__ */ jsxs21("div", { className: cx10("list"), children: [
|
|
6053
5819
|
entries.map(([name, reg]) => /* @__PURE__ */ jsxs21("div", { className: cx10("item"), children: [
|
|
6054
|
-
/* @__PURE__ */
|
|
5820
|
+
/* @__PURE__ */ jsx35("span", { className: cx10("itemName"), children: reg.label || name }),
|
|
6055
5821
|
/* @__PURE__ */ jsxs21(
|
|
6056
5822
|
"button",
|
|
6057
5823
|
{
|
|
@@ -6059,26 +5825,26 @@ function ManageModalContent({ onClose }) {
|
|
|
6059
5825
|
onClick: () => setConfirmTarget({ name, label: reg.label || name }),
|
|
6060
5826
|
type: "button",
|
|
6061
5827
|
children: [
|
|
6062
|
-
/* @__PURE__ */
|
|
5828
|
+
/* @__PURE__ */ jsx35(Trash2, { size: 12 }),
|
|
6063
5829
|
"Delete"
|
|
6064
5830
|
]
|
|
6065
5831
|
}
|
|
6066
5832
|
)
|
|
6067
5833
|
] }, name)),
|
|
6068
|
-
entries.length === 0 && /* @__PURE__ */
|
|
5834
|
+
entries.length === 0 && /* @__PURE__ */ jsx35("div", { className: cx10("empty"), children: "No dynamic components" })
|
|
6069
5835
|
] }) });
|
|
6070
5836
|
}
|
|
6071
5837
|
function ManageComponentsCta() {
|
|
6072
|
-
const [open, setOpen] =
|
|
5838
|
+
const [open, setOpen] = useState17(false);
|
|
6073
5839
|
const entries = useRegistrations();
|
|
6074
5840
|
const handleClose = useCallback8(() => setOpen(false), []);
|
|
6075
5841
|
if (entries.length === 0) return null;
|
|
6076
5842
|
return /* @__PURE__ */ jsxs21(Fragment10, { children: [
|
|
6077
5843
|
/* @__PURE__ */ jsxs21("button", { className: cx10("cta"), onClick: () => setOpen(true), type: "button", children: [
|
|
6078
|
-
/* @__PURE__ */
|
|
5844
|
+
/* @__PURE__ */ jsx35(Settings, { size: 14 }),
|
|
6079
5845
|
"Manage components"
|
|
6080
5846
|
] }),
|
|
6081
|
-
open && /* @__PURE__ */
|
|
5847
|
+
open && /* @__PURE__ */ jsx35(ModalProvider, { defaultVisible: true, children: /* @__PURE__ */ jsx35(ManageModalContent, { onClose: handleClose }) })
|
|
6082
5848
|
] });
|
|
6083
5849
|
}
|
|
6084
5850
|
|
|
@@ -6087,22 +5853,22 @@ init_react_import();
|
|
|
6087
5853
|
var styles_module_default11 = { "Drawer--empty": "_Drawer--empty_8e8cs_1" };
|
|
6088
5854
|
|
|
6089
5855
|
// src/components/Drawer/index.tsx
|
|
6090
|
-
import { jsx as
|
|
5856
|
+
import { jsx as jsx36, jsxs as jsxs22 } from "react/jsx-runtime";
|
|
6091
5857
|
var usePuck2 = createUsePuck2();
|
|
6092
5858
|
var cx11 = get_class_name_factory_default("Drawer", styles_module_default11);
|
|
6093
5859
|
var createDrawer = (designModeVisible) => function Drawer({ children }) {
|
|
6094
5860
|
const config = usePuck2((s) => s.config);
|
|
6095
5861
|
if (Object.keys(config.components).length === 0) {
|
|
6096
|
-
return /* @__PURE__ */
|
|
5862
|
+
return /* @__PURE__ */ jsx36("div", { className: cx11({ empty: true }), children: "No blocks" });
|
|
6097
5863
|
}
|
|
6098
5864
|
return /* @__PURE__ */ jsxs22("div", { className: cx11(), children: [
|
|
6099
5865
|
children,
|
|
6100
|
-
designModeVisible && /* @__PURE__ */
|
|
5866
|
+
designModeVisible && /* @__PURE__ */ jsx36(ManageComponentsCta, {})
|
|
6101
5867
|
] });
|
|
6102
5868
|
};
|
|
6103
5869
|
|
|
6104
5870
|
// src/index.tsx
|
|
6105
|
-
import { Fragment as Fragment11, jsx as
|
|
5871
|
+
import { Fragment as Fragment11, jsx as jsx37 } from "react/jsx-runtime";
|
|
6106
5872
|
function withDynamicConfig(config, data) {
|
|
6107
5873
|
const registrations = getPersistedRegistrations(data);
|
|
6108
5874
|
const dynamicConfig = {};
|
|
@@ -6133,23 +5899,22 @@ function withDynamicConfig(config, data) {
|
|
|
6133
5899
|
return result;
|
|
6134
5900
|
}
|
|
6135
5901
|
function createAiPlugin(opts) {
|
|
6136
|
-
const { scrollTracking = true,
|
|
6137
|
-
setFieldTypes(fieldTypes);
|
|
5902
|
+
const { scrollTracking = true, ...rest } = opts || {};
|
|
6138
5903
|
const scrollTrackingId = `puck-ai-scroll-${ulid2()}`;
|
|
6139
5904
|
const designModeVisible = typeof opts?.designMode === "boolean" ? opts.designMode : opts?.designMode?.visible ?? false;
|
|
6140
5905
|
return {
|
|
6141
5906
|
label: "AI",
|
|
6142
5907
|
name: "ai",
|
|
6143
|
-
render: () => /* @__PURE__ */
|
|
6144
|
-
icon: /* @__PURE__ */
|
|
5908
|
+
render: () => /* @__PURE__ */ jsx37(Chat2, { ...rest, scrollTrackingId }),
|
|
5909
|
+
icon: /* @__PURE__ */ jsx37(Bot, {}),
|
|
6145
5910
|
mobilePanelHeight: "min-content",
|
|
6146
5911
|
overrides: {
|
|
6147
5912
|
drawer: createDrawer(designModeVisible),
|
|
6148
5913
|
preview: ({ children }) => {
|
|
6149
5914
|
if (scrollTracking) {
|
|
6150
|
-
return /* @__PURE__ */
|
|
5915
|
+
return /* @__PURE__ */ jsx37(ScrollTracking, { trackingId: scrollTrackingId, children });
|
|
6151
5916
|
}
|
|
6152
|
-
return /* @__PURE__ */
|
|
5917
|
+
return /* @__PURE__ */ jsx37(Fragment11, { children });
|
|
6153
5918
|
}
|
|
6154
5919
|
}
|
|
6155
5920
|
};
|