@puckeditor/plugin-ai 0.6.1-canary.b83b09a1 → 0.6.1-canary.cf5294c7
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.js +51 -4
- package/dist/index.mjs +51 -4
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -271,6 +271,9 @@ var TriangleAlert = createLucideIcon("TriangleAlert", [
|
|
|
271
271
|
["path", { d: "M12 17h.01", key: "p32p05" }]
|
|
272
272
|
]);
|
|
273
273
|
|
|
274
|
+
// src/index.tsx
|
|
275
|
+
var import_ulid2 = require("ulid");
|
|
276
|
+
|
|
274
277
|
// src/components/Chat/index.tsx
|
|
275
278
|
init_react_import();
|
|
276
279
|
|
|
@@ -6605,6 +6608,23 @@ var dispatchOp = (operation, {
|
|
|
6605
6608
|
|
|
6606
6609
|
// src/components/Chat/index.tsx
|
|
6607
6610
|
var import_html2canvas_pro = __toESM(require("html2canvas-pro"));
|
|
6611
|
+
|
|
6612
|
+
// src/lib/scroll-tracking-events.ts
|
|
6613
|
+
init_react_import();
|
|
6614
|
+
var listeners = /* @__PURE__ */ new Set();
|
|
6615
|
+
function dispatchScrollTrackingEvent(detail) {
|
|
6616
|
+
listeners.forEach((listener) => {
|
|
6617
|
+
listener(detail);
|
|
6618
|
+
});
|
|
6619
|
+
}
|
|
6620
|
+
function subscribeToScrollTrackingEvents(listener) {
|
|
6621
|
+
listeners.add(listener);
|
|
6622
|
+
return () => {
|
|
6623
|
+
listeners.delete(listener);
|
|
6624
|
+
};
|
|
6625
|
+
}
|
|
6626
|
+
|
|
6627
|
+
// src/components/Chat/index.tsx
|
|
6608
6628
|
var import_jsx_runtime30 = require("react/jsx-runtime");
|
|
6609
6629
|
var q2 = (0, import_qler.default)();
|
|
6610
6630
|
var BENCHMARK = false;
|
|
@@ -6614,7 +6634,8 @@ var usePuck = (0, import_core2.createUsePuck)();
|
|
|
6614
6634
|
function Chat2({
|
|
6615
6635
|
chat,
|
|
6616
6636
|
host = "/api/puck/chat",
|
|
6617
|
-
prepareRequest
|
|
6637
|
+
prepareRequest,
|
|
6638
|
+
scrollTrackingId
|
|
6618
6639
|
}) {
|
|
6619
6640
|
const { examplePrompts } = chat ?? {};
|
|
6620
6641
|
const puckDispatch = usePuck((s2) => s2.dispatch);
|
|
@@ -6782,6 +6803,19 @@ function Chat2({
|
|
|
6782
6803
|
() => forcedStatus ?? status,
|
|
6783
6804
|
[status, forcedStatus]
|
|
6784
6805
|
);
|
|
6806
|
+
(0, import_react24.useEffect)(() => {
|
|
6807
|
+
if (!scrollTrackingId) return;
|
|
6808
|
+
dispatchScrollTrackingEvent({
|
|
6809
|
+
id: scrollTrackingId,
|
|
6810
|
+
enabled: resolvedStatus === "submitted" || resolvedStatus === "streaming"
|
|
6811
|
+
});
|
|
6812
|
+
return () => {
|
|
6813
|
+
dispatchScrollTrackingEvent({
|
|
6814
|
+
id: scrollTrackingId,
|
|
6815
|
+
enabled: false
|
|
6816
|
+
});
|
|
6817
|
+
};
|
|
6818
|
+
}, [resolvedStatus, scrollTrackingId]);
|
|
6785
6819
|
(0, import_react24.useEffect)(() => {
|
|
6786
6820
|
window.__PUCK_AI = {
|
|
6787
6821
|
processData,
|
|
@@ -6975,9 +7009,21 @@ function useFrameMutationObserver(callback) {
|
|
|
6975
7009
|
}
|
|
6976
7010
|
|
|
6977
7011
|
// src/components/ScrollTracking/ScrollTracking.tsx
|
|
6978
|
-
var ScrollTracking = ({
|
|
7012
|
+
var ScrollTracking = ({
|
|
7013
|
+
children,
|
|
7014
|
+
trackingId
|
|
7015
|
+
}) => {
|
|
6979
7016
|
const followedRefs = (0, import_react26.useRef)([]);
|
|
7017
|
+
const enabledRef = (0, import_react26.useRef)(false);
|
|
7018
|
+
(0, import_react26.useEffect)(() => {
|
|
7019
|
+
return subscribeToScrollTrackingEvents(({ id, enabled }) => {
|
|
7020
|
+
if (id !== trackingId) return;
|
|
7021
|
+
enabledRef.current = enabled;
|
|
7022
|
+
followedRefs.current = [];
|
|
7023
|
+
});
|
|
7024
|
+
}, [trackingId]);
|
|
6980
7025
|
const follow = useFrameMutationObserver((records, win) => {
|
|
7026
|
+
if (!enabledRef.current) return;
|
|
6981
7027
|
if (records.length > 0) {
|
|
6982
7028
|
const lastRecord = records[records.length - 1];
|
|
6983
7029
|
if (followedRefs.current.includes(lastRecord.target)) return;
|
|
@@ -6998,16 +7044,17 @@ var ScrollTracking = ({ children }) => {
|
|
|
6998
7044
|
var import_jsx_runtime31 = require("react/jsx-runtime");
|
|
6999
7045
|
function createAiPlugin(opts) {
|
|
7000
7046
|
const { scrollTracking = true, ...rest } = opts || {};
|
|
7047
|
+
const scrollTrackingId = `puck-ai-scroll-${(0, import_ulid2.ulid)()}`;
|
|
7001
7048
|
return {
|
|
7002
7049
|
label: "AI",
|
|
7003
7050
|
name: "ai",
|
|
7004
|
-
render: () => /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(Chat2, { ...rest }),
|
|
7051
|
+
render: () => /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(Chat2, { ...rest, scrollTrackingId }),
|
|
7005
7052
|
icon: /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(Bot, {}),
|
|
7006
7053
|
mobilePanelHeight: "min-content",
|
|
7007
7054
|
overrides: {
|
|
7008
7055
|
preview: ({ children }) => {
|
|
7009
7056
|
if (scrollTracking) {
|
|
7010
|
-
return /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(ScrollTracking, { children });
|
|
7057
|
+
return /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(ScrollTracking, { trackingId: scrollTrackingId, children });
|
|
7011
7058
|
}
|
|
7012
7059
|
return /* @__PURE__ */ (0, import_jsx_runtime31.jsx)(import_jsx_runtime31.Fragment, { children });
|
|
7013
7060
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -259,6 +259,9 @@ var TriangleAlert = createLucideIcon("TriangleAlert", [
|
|
|
259
259
|
["path", { d: "M12 17h.01", key: "p32p05" }]
|
|
260
260
|
]);
|
|
261
261
|
|
|
262
|
+
// src/index.tsx
|
|
263
|
+
import { ulid as ulid2 } from "ulid";
|
|
264
|
+
|
|
262
265
|
// src/components/Chat/index.tsx
|
|
263
266
|
init_react_import();
|
|
264
267
|
|
|
@@ -6606,6 +6609,23 @@ var dispatchOp = (operation, {
|
|
|
6606
6609
|
|
|
6607
6610
|
// src/components/Chat/index.tsx
|
|
6608
6611
|
import html2canvas from "html2canvas-pro";
|
|
6612
|
+
|
|
6613
|
+
// src/lib/scroll-tracking-events.ts
|
|
6614
|
+
init_react_import();
|
|
6615
|
+
var listeners = /* @__PURE__ */ new Set();
|
|
6616
|
+
function dispatchScrollTrackingEvent(detail) {
|
|
6617
|
+
listeners.forEach((listener) => {
|
|
6618
|
+
listener(detail);
|
|
6619
|
+
});
|
|
6620
|
+
}
|
|
6621
|
+
function subscribeToScrollTrackingEvents(listener) {
|
|
6622
|
+
listeners.add(listener);
|
|
6623
|
+
return () => {
|
|
6624
|
+
listeners.delete(listener);
|
|
6625
|
+
};
|
|
6626
|
+
}
|
|
6627
|
+
|
|
6628
|
+
// src/components/Chat/index.tsx
|
|
6609
6629
|
import { jsx as jsx30, jsxs as jsxs17 } from "react/jsx-runtime";
|
|
6610
6630
|
var q2 = qler();
|
|
6611
6631
|
var BENCHMARK = false;
|
|
@@ -6615,7 +6635,8 @@ var usePuck = createUsePuck();
|
|
|
6615
6635
|
function Chat2({
|
|
6616
6636
|
chat,
|
|
6617
6637
|
host = "/api/puck/chat",
|
|
6618
|
-
prepareRequest
|
|
6638
|
+
prepareRequest,
|
|
6639
|
+
scrollTrackingId
|
|
6619
6640
|
}) {
|
|
6620
6641
|
const { examplePrompts } = chat ?? {};
|
|
6621
6642
|
const puckDispatch = usePuck((s2) => s2.dispatch);
|
|
@@ -6783,6 +6804,19 @@ function Chat2({
|
|
|
6783
6804
|
() => forcedStatus ?? status,
|
|
6784
6805
|
[status, forcedStatus]
|
|
6785
6806
|
);
|
|
6807
|
+
useEffect10(() => {
|
|
6808
|
+
if (!scrollTrackingId) return;
|
|
6809
|
+
dispatchScrollTrackingEvent({
|
|
6810
|
+
id: scrollTrackingId,
|
|
6811
|
+
enabled: resolvedStatus === "submitted" || resolvedStatus === "streaming"
|
|
6812
|
+
});
|
|
6813
|
+
return () => {
|
|
6814
|
+
dispatchScrollTrackingEvent({
|
|
6815
|
+
id: scrollTrackingId,
|
|
6816
|
+
enabled: false
|
|
6817
|
+
});
|
|
6818
|
+
};
|
|
6819
|
+
}, [resolvedStatus, scrollTrackingId]);
|
|
6786
6820
|
useEffect10(() => {
|
|
6787
6821
|
window.__PUCK_AI = {
|
|
6788
6822
|
processData,
|
|
@@ -6976,9 +7010,21 @@ function useFrameMutationObserver(callback) {
|
|
|
6976
7010
|
}
|
|
6977
7011
|
|
|
6978
7012
|
// src/components/ScrollTracking/ScrollTracking.tsx
|
|
6979
|
-
var ScrollTracking = ({
|
|
7013
|
+
var ScrollTracking = ({
|
|
7014
|
+
children,
|
|
7015
|
+
trackingId
|
|
7016
|
+
}) => {
|
|
6980
7017
|
const followedRefs = useRef9([]);
|
|
7018
|
+
const enabledRef = useRef9(false);
|
|
7019
|
+
useEffect11(() => {
|
|
7020
|
+
return subscribeToScrollTrackingEvents(({ id, enabled }) => {
|
|
7021
|
+
if (id !== trackingId) return;
|
|
7022
|
+
enabledRef.current = enabled;
|
|
7023
|
+
followedRefs.current = [];
|
|
7024
|
+
});
|
|
7025
|
+
}, [trackingId]);
|
|
6981
7026
|
const follow = useFrameMutationObserver((records, win) => {
|
|
7027
|
+
if (!enabledRef.current) return;
|
|
6982
7028
|
if (records.length > 0) {
|
|
6983
7029
|
const lastRecord = records[records.length - 1];
|
|
6984
7030
|
if (followedRefs.current.includes(lastRecord.target)) return;
|
|
@@ -6999,16 +7045,17 @@ var ScrollTracking = ({ children }) => {
|
|
|
6999
7045
|
import { Fragment as Fragment4, jsx as jsx31 } from "react/jsx-runtime";
|
|
7000
7046
|
function createAiPlugin(opts) {
|
|
7001
7047
|
const { scrollTracking = true, ...rest } = opts || {};
|
|
7048
|
+
const scrollTrackingId = `puck-ai-scroll-${ulid2()}`;
|
|
7002
7049
|
return {
|
|
7003
7050
|
label: "AI",
|
|
7004
7051
|
name: "ai",
|
|
7005
|
-
render: () => /* @__PURE__ */ jsx31(Chat2, { ...rest }),
|
|
7052
|
+
render: () => /* @__PURE__ */ jsx31(Chat2, { ...rest, scrollTrackingId }),
|
|
7006
7053
|
icon: /* @__PURE__ */ jsx31(Bot, {}),
|
|
7007
7054
|
mobilePanelHeight: "min-content",
|
|
7008
7055
|
overrides: {
|
|
7009
7056
|
preview: ({ children }) => {
|
|
7010
7057
|
if (scrollTracking) {
|
|
7011
|
-
return /* @__PURE__ */ jsx31(ScrollTracking, { children });
|
|
7058
|
+
return /* @__PURE__ */ jsx31(ScrollTracking, { trackingId: scrollTrackingId, children });
|
|
7012
7059
|
}
|
|
7013
7060
|
return /* @__PURE__ */ jsx31(Fragment4, { children });
|
|
7014
7061
|
}
|
package/package.json
CHANGED